Example #1
0
        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();
        }
Example #2
0
        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));
        }
Example #3
0
 public DefaultLanguagesCreator(JewelleryDbContext context)
 {
     _context = context;
 }
Example #4
0
 public DefaultTenantBuilder(JewelleryDbContext context)
 {
     _context = context;
 }
 public DefaultSettingsCreator(JewelleryDbContext context)
 {
     _context = context;
 }
 public InitialHostDbBuilder(JewelleryDbContext context)
 {
     _context = context;
 }
Example #7
0
 public JewelleryDataBuilder(JewelleryDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
Example #8
0
 public HostRoleAndUserCreator(JewelleryDbContext context)
 {
     _context = context;
 }
Example #9
0
 public TenantRoleAndUserBuilder(JewelleryDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
Example #10
0
 public DefaultEditionCreator(JewelleryDbContext context)
 {
     _context = context;
 }