public static void SeedHostDb(JewelleryDbContext context) { context.SuppressAutoSetTenantId = true; // Host seed new InitialHostDbBuilder(context).Create(); // Default tenant seed (in host database). new DefaultTenantBuilder(context).Create(); new TenantRoleAndUserBuilder(context, 1).Create(); new JewelleryDataBuilder(context, 1).Create(); }
public override async Task <OrderDto> UpdateAsync(EditOrderDto input) { var builder = new DbContextOptionsBuilder <JewelleryDbContext>(); var conn = _configuration.GetConnectionString("Default"); builder.UseSqlServer(conn); using var context = new JewelleryDbContext(builder.Options); using var transaction = context.Database.BeginTransaction(); var orderEntity = ObjectMapper.Map <Order>(input); var existingOrder = await context.Orders.Include(s => s.OrderDetails).FirstOrDefaultAsync(x => x.Id == input.Id); context.Entry(existingOrder).CurrentValues.SetValues(orderEntity); foreach (var detail in orderEntity.OrderDetails) { detail.OrderId = orderEntity.Id; var existingDetail = existingOrder.OrderDetails.FirstOrDefault(s => s.ProductId == detail.ProductId); if (existingDetail == null) { existingOrder.OrderDetails.Add(detail); } else { context.Entry(existingDetail).CurrentValues.SetValues(detail); } } foreach (var detail in existingOrder.OrderDetails) { if (!orderEntity.OrderDetails.Any(p => p.ProductId == detail.ProductId)) { context.Remove(detail); } } await context.SaveChangesAsync(); // Commit transaction if all commands succeed, transaction will auto-rollback // when disposed if either commands fails transaction.Commit(); var result = await context.Orders.Include(s => s.OrderDetails).FirstOrDefaultAsync(x => x.Id == input.Id); return(ObjectMapper.Map <OrderDto>(result)); }
public DefaultLanguagesCreator(JewelleryDbContext context) { _context = context; }
public DefaultTenantBuilder(JewelleryDbContext context) { _context = context; }
public DefaultSettingsCreator(JewelleryDbContext context) { _context = context; }
public InitialHostDbBuilder(JewelleryDbContext context) { _context = context; }
public JewelleryDataBuilder(JewelleryDbContext context, int tenantId) { _context = context; _tenantId = tenantId; }
public HostRoleAndUserCreator(JewelleryDbContext context) { _context = context; }
public TenantRoleAndUserBuilder(JewelleryDbContext context, int tenantId) { _context = context; _tenantId = tenantId; }
public DefaultEditionCreator(JewelleryDbContext context) { _context = context; }