Пример #1
0
 private void CreateContactDetail(ShopDbContext context)
 {
     if (context.ContactDetails.Count() == 0)
     {
         try
         {
             var contactDetail = new Model.Models.ContactDetail()
             {
                 Name    = "Nhà trọ của tôi",
                 Phone   = "095423233",
                 Email   = "*****@*****.**",
                 Website = "http://khongcodiachi.com",
                 Address = "Ngõ 117, Hạ Đoạn 2",
                 Other   = "",
                 Lat     = 20.849394,
                 Lng     = 106.727257,
                 Status  = true
             };
             context.ContactDetails.Add(contactDetail);
             context.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
             foreach (var eve in ex.EntityValidationErrors)
             {
                 Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation error.");
                 foreach (var ve in eve.ValidationErrors)
                 {
                     Trace.WriteLine($"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\"");
                 }
             }
         }
     }
 }
Пример #2
0
 private void CreateContactDetail(ShopDbContext context)
 {
     if (context.ContactDetails.Count() == 0)
     {
         try
         {
             var contactDetail = new Model.Models.ContactDetail()
             {
                 Name    = "Shop thời trang TEDU",
                 Address = "Ngõ 77 Xuân La",
                 Email   = "*****@*****.**",
                 Lat     = 21.0633645,
                 Lng     = 105.8053274,
                 Phone   = "095423233",
                 Website = "http://tedu.com.vn",
                 Other   = "",
                 Status  = true
             };
             context.ContactDetails.Add(contactDetail);
             context.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
             foreach (var eve in ex.EntityValidationErrors)
             {
                 Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation error.");
                 foreach (var ve in eve.ValidationErrors)
                 {
                     Trace.WriteLine($"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\"");
                 }
             }
         }
     }
 }