public static async System.Threading.Tasks.Task InitializeAsync(CouponDBContext context)
        {
            context.Database.EnsureCreated();

            if (!context.Coupons.Any())
            {
                List <Coupon> coupons = new List <Coupon>();
                for (int i = 0; i < 50000; i++)
                {
                    coupons.Add(new Coupon {
                        Title = $"Coupon {i}", MaxPerUser = 10, MaxAllUser = 20000, StartDate = DateTime.UtcNow, EndDate = DateTime.MaxValue
                    });
                }
                await context.Coupons.AddRangeAsync(coupons);
            }
            if (!context.Users.Any())
            {
                context.Users.Add(new User {
                    Name = "Arthur"
                });
                context.Users.Add(new User {
                    Name = "Jason"
                });
                context.Users.Add(new User {
                    Name = "Selina"
                });
            }
            await context.SaveChangesAsync();
        }
Ejemplo n.º 2
0
 public async Task UpdateAsync <T, M>(M m) where T : BaseEntity where M : BaseModel
 {
     try
     {
         var entity = _dBContext.Set <T>().First(d => d.Id == m.Id);
         _mapper.Map(m, entity);
         await _dBContext.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }