Skip to content

Instantly share code, notes, and snippets.

[Route("Home")]
[ApiController]
public class HomeController : ControllerBase
{
IUserRepository _userRepository;
public HomeController(IUserRepository userRepository)
{
_userRepository = userRepository;
}
[HttpGet]
[Route("Home")]
[ApiController]
public class HomeController : ControllerBase
{
UnitOfWork _Context;
public HomeController()
{
_Context = new UnitOfWork();
}
[HttpGet]
public class UnitOfWork
{
Context DBContext = new Context();
IProductRepository productRepository { get; set; }
IUserRepository userRepository { get; set; }
ICategoryRepository categoryRepository { get; set; }
IBasketRepository basketRepository { get; set; }
IPaymentRepository paymentRepository { get; set; }
public IProductRepository Products
{
public interface IUserRepository:IBaseRepository<User>
{
}
public class UserRepository : BaseRepository<User>, IUserRepository
{
public UserRepository(Context dbContext) : base(dbContext)
{
}
}
public class BaseRepository<TEntity> :IBaseRepository<TEntity> where TEntity : EntityBase
{
protected readonly Context _dbContext;
public BaseRepository(Context dbContext)
{
_dbContext = dbContext ?? throw newArgumentNullException(nameof(dbContext));
}
public async Task<IReadOnlyList<TEntity>> GetAllAsync()
{
return await _dbContext.Set<TEntity>().ToListAsync();
public class BaseRepository<TEntity> :IBaseRepository<TEntity> where TEntity : EntityBase
{
protected readonly Context _dbContext;
public BaseRepository(Context dbContext)
{
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
public async Task<IReadOnlyList<TEntity>> GetAllAsync()
public interface IBaseRepository<TEtity> where TEtity : EntityBase
{
Task<IReadOnlyList<TEtity>> GetAllAsync();
Task<IReadOnlyList<TEtity>> GetAsync(Expression<Func<TEtity, bool>> predicate);
Task<IReadOnlyList<TEtity>> GetAsync(Expression<Func<TEtity, bool>> predicate = null,
Func<IQueryable<TEtity>, IOrderedQueryable<TEtity>> orderBy = null,
string includeString = null,
bool disableTracking = true);
Task<IReadOnlyList<TEtity>> GetAsync(Expression<Func<TEtity, bool>> predicate = null,
Func<IQueryable<TEtity>, IOrderedQueryable<TEtity>> orderBy = null,
namespace CodeFirst.DBContext
{
public class Context : DbContext
{
public Context(DbContextOptions<Context> options) : base(options)
{
}
public DbSet<User> Users { get; set; }
public DbSet<Product> Products { get; set; }
namespace CodeFirst.Entities
{
public class EntityBase
{
public int Id { get; set; }
public DateTime CreatedDate { set; get; }
public bool IsDeleted { set; get; }
public DateTime LastModifiedDate { get; set; }
}
public class Basket:EntityBase
public static bool VerifySha256Hash(string inputText,string hashString)
{
var hash = Convert.FromBase64String(hashString);
using (SHA256 sha256Hash = SHA256.Create())
{
byte[] tempHash;
tempHash = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(inputText));
bool bEqual = false;