This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Common; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Day_15_Solver | |
{ | |
public static class Day15Solver | |
{ | |
public static long Part1Solution(long[] input) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IRepository<TEntity> where TEntity : class | |
{ | |
TEntity FindById(int id); | |
IEnumerable<TEntity> Find(ISpecification<TEntity> specification = null); | |
void Add(TEntity entity); | |
void AddRange(IEnumerable<TEntity> entities); | |
void Remove(TEntity entity); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SpecificationEvaluator<TEntity> where TEntity : BaseEntity | |
{ | |
public static IQueryable<TEntity> GetQuery(IQueryable<TEntity> inputQuery, ISpecification<TEntity> specification) | |
{ | |
var query = inputQuery; | |
// modify the IQueryable using the specification's criteria expression | |
if (specification.Criteria != null) | |
{ | |
query = query.Where(specification.Criteria); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UsersController : ControllerBase | |
{ | |
private readonly IUnitOfWork _unitOfWork; | |
public UsersController(IUnitOfWork unitOfWork) | |
{ | |
_unitOfWork = unitOfWork; | |
} | |
// GET: api/Users |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UsersWithRecipesAndIngredientsSpecification : BaseSpecification<User> | |
{ | |
public UsersWithRecipesAndIngredientsSpecification() : base() | |
{ | |
AddInclude(x => x.Recipes); | |
AddInclude($"{nameof(User.Recipes)}.{nameof(Recipe.Ingredients)}"); | |
} | |
public UsersWithRecipesAndIngredientsSpecification(int id) : base(x => x.Id == id) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IUnitOfWork : IDisposable | |
{ | |
IRepository<TEntity> Repository<TEntity>() where TEntity : BaseEntity; | |
int Complete(); | |
} | |
public class UnitOfWork : IUnitOfWork | |
{ | |
private readonly ApplicationDbContext _context; | |
private Hashtable _repositories; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Repository<TEntity> : IRepository<TEntity> where TEntity : BaseEntity | |
{ | |
protected readonly DbContext _context; | |
public Repository(DbContext context) | |
{ | |
_context = context; | |
} | |
public void Add(TEntity entity) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class BaseSpecification<T> : ISpecification<T> | |
{ | |
protected BaseSpecification(Expression<Func<T, bool>> criteria) | |
{ | |
Criteria = criteria; | |
} | |
protected BaseSpecification() | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISpecification<T> | |
{ | |
Expression<Func<T, bool>> Criteria { get; } | |
List<Expression<Func<T, object>>> Includes { get; } | |
List<string> IncludeStrings { get; } | |
Expression<Func<T, object>> OrderBy { get; } | |
Expression<Func<T, object>> OrderByDescending { get; } | |
Expression<Func<T, object>> GroupBy { get; } | |
int Take { get; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Route("api/[controller]")] | |
[ApiController] | |
public class UsersController : ControllerBase | |
{ | |
private readonly ApplicationDbContext _context; | |
public UsersController(ApplicationDbContext context) | |
{ | |
_context = context; | |
} |
NewerOlder