Skip to content

Commit

Permalink
Filled out the services and controllers further.
Browse files Browse the repository at this point in the history
Most endpoints are usable now.
  • Loading branch information
MelGrubb committed Feb 24, 2019
1 parent c5e6ca5 commit b629c08
Show file tree
Hide file tree
Showing 58 changed files with 1,439 additions and 229 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Code

This folder contains the source code for the sample solution.
This folder contains the source code for the sample solution.

## Branching Strategy

The "master" branch has the solution itself, and the stubs for the test assemblies.
The "Mx" branches each demonstrate the different test data generation strategies.

When changes are made to the store solution, they should be made in master and then merged to the other branches so that each strategy branch is running against the same basic solution.
3 changes: 1 addition & 2 deletions Solution.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- Add the following line, uncommented, to each csproj file, just inside the Project node. -->
<!-- <Import Project="..\Solution.props" /> -->
<!-- Add a line to each csproj file, just under the first -->

<Project>
<PropertyGroup>
Expand Down
14 changes: 14 additions & 0 deletions Store.Common/Contracts/PagingOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Store.Common.Contracts
{
public class PagingOptions
{
private int _take;
public int Skip { get; set; }

public int Take
{
get => _take == 0 ? 10 : _take;
set => _take = value;
}
}
}
3 changes: 1 addition & 2 deletions Store.Common/Store.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\Solution.props" />
<Import Project="..\Solution.props" />

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
Expand All @@ -12,7 +12,6 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Contracts\" />
<Folder Include="Extensions\" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion Store.Domain/.Framework/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public abstract class Model : IModel
public bool IsNew => Id.Equals(0);

/// <summary>The primary key / identity column.</summary>
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
}
}
41 changes: 27 additions & 14 deletions Store.Domain/.Framework/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Store.Common.Contracts;
using Store.Domain.Models;

namespace Store.Domain.Framework
Expand All @@ -27,6 +28,8 @@ public interface IRepository<T> : IRepository where T : IModel

Task<T> GetAsync(int userId, int id);

Task<List<T>> GetAsync(int userId, PagingOptions pagingOptions);

Task SaveChangesAsync(int userId);

Task<T> SingleOrDefaultAsync(int userId, Expression<Func<T, bool>> predicate = null);
Expand Down Expand Up @@ -94,20 +97,6 @@ public virtual Task<bool> AnyAsync(Expression<Func<T, bool>> predicate = null)
return result;
}

public virtual Task<int> CountAsync(Expression<Func<T, bool>> predicate = null)
{
IQueryable<T> query = StoreContext.Set<T>();

if (typeof(T) is ISoftDeleteable)
{
query = query.Where(x => !((ISoftDeleteable)x).DeletedUtc.HasValue);
}

var result = query.CountAsync(predicate);

return result;
}

public virtual async Task DeleteAsync(int userId, T model)
{
if (_isSoftDeleteable)
Expand Down Expand Up @@ -138,6 +127,16 @@ public virtual Task<T> GetAsync(int userId, int id)
return results;
}

public async Task<List<T>> GetAsync(int userId, PagingOptions pagingOptions)
{
var results = await GetQuery(userId)
.Skip(pagingOptions.Skip)
.Take(pagingOptions.Take)
.ToListAsync();

return results;
}

public virtual Task SaveChangesAsync(int userId)
{
var result = StoreContext.SaveChangesAsync(userId);
Expand All @@ -152,6 +151,20 @@ public virtual async Task<T> SingleOrDefaultAsync(int userId, Expression<Func<T,
return result;
}

public virtual Task<int> CountAsync(Expression<Func<T, bool>> predicate = null)
{
IQueryable<T> query = StoreContext.Set<T>();

if (typeof(T) is ISoftDeleteable)
{
query = query.Where(x => !((ISoftDeleteable)x).DeletedUtc.HasValue);
}

var result = query.CountAsync(predicate);

return result;
}

protected virtual IQueryable<T> GetBaseQuery(int userId, Expression<Func<T, bool>> predicate = null)
{
IQueryable<T> query = StoreContext.Set<T>();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b629c08

Please sign in to comment.