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("Home")] | |
| [ApiController] | |
| public class HomeController : ControllerBase | |
| { | |
| IUserRepository _userRepository; | |
| public HomeController(IUserRepository userRepository) | |
| { | |
| _userRepository = userRepository; | |
| } | |
| [HttpGet] |
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("Home")] | |
| [ApiController] | |
| public class HomeController : ControllerBase | |
| { | |
| UnitOfWork _Context; | |
| public HomeController() | |
| { | |
| _Context = new UnitOfWork(); | |
| } | |
| [HttpGet] |
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 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 | |
| { |
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 IUserRepository:IBaseRepository<User> | |
| { | |
| } | |
| public class UserRepository : BaseRepository<User>, IUserRepository | |
| { | |
| public UserRepository(Context dbContext) : base(dbContext) | |
| { | |
| } | |
| } |
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 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(); |
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 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() |
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 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, |
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
| 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; } |
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
| 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 |
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 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; |
NewerOlder