public BaseRepository(IConfiguration configuration, CatalogDbContext context) { this.configuration = configuration; this.context = context; dbSet = context.Set <T>(); }
public async Task <TenantContext <Tenant> > ResolveAsync(HttpContext context) { var hostname = context.Request.Host.Value.ToLower(); var host = context.Request.Host; Tenant tenant = await catalog.Set <Tenant>().Where(e => e.HostName.Equals(hostname)).FirstOrDefaultAsync(); return(await Task.FromResult(new TenantContext <Tenant>(tenant))); }
public async Task DeleteAsync(T entity) { if (_context.Entry(entity).State == EntityState.Detached) { _context.Set <T>().Attach(entity); } _context.Set <T>().Remove(entity); await _context.SaveChangesAsync(); }
public static async Task Seed(CatalogDbContext dbContext) { var products = new List <Product>(); for (var index = 1; index <= 26; index++) { products.Add(new Product { Id = Guid.NewGuid(), Name = $"Product {index}", Model = $"Model {index}", Price = 10, Quantity = 100, DateAdded = DateTime.UtcNow, Status = Status.Published }); } var product = new Product { Id = new Guid("85db18f3-9c27-47d8-bd45-86dd67068960"), Name = "Product 111", Model = "Model ABA", Price = 50, Quantity = 100, DateAdded = DateTime.UtcNow, Status = Status.Published }; products.Add(product); var supplier = new Supplier { Id = new Guid("83fd9e15-eadd-44da-8c1a-e7626a767775"), ContactName = "Nguyen Van A", CompanyName = "Company A", ContactTitle = "Provider", AddressInfo = new AddressInfo(Guid.NewGuid(), "123 Addrress", "HCM", "Region A", "7000", "VN"), ContactInfo = new ContactInfo(Guid.NewGuid(), "123456789", "1234567890", "*****@*****.**"), Products = products }; await dbContext.Set <Supplier>().AddAsync(supplier); await dbContext.SaveChangesAsync(); }
public async Task <IEnumerable <TEntity> > GetAllAsync() { return(await _context.Set <TEntity>().ToListAsync()); }
public virtual void Add(T entity) { try { EntityEntry dbEntityEntry = _context.Entry(entity); _context.Set <T>().Add(entity); } catch (Exception ex) { throw new Exception(ex.Message); } }