Ejemplo n.º 1
0
 public SimCard Insert(SimCard entity)
 {
     try
     {
         _context.SimCards.Add(entity);
         _context.SaveChanges();
         return(entity);
     }
     catch (Exception ex)
     {
         _context.Entry(entity).State = EntityState.Detached;
         _context.SaveChanges();
         throw ex;
     }
 }
Ejemplo n.º 2
0
 public static void InsertUpdateSeedData(string connectionString)
 {
     using (var context = new EyeAssetDbContext(connectionString))
     {
         context.Database.EnsureCreated();
         var apps = context.Apps.ToList();
         if (apps == null)
         {
             context.Apps.AddRange(AppData);
         }
         else
         {
             for (int i = 0; i < AppData.Count; i++)
             {
                 var existing = apps.FirstOrDefault(x => x.Id == AppData[i].Id);
                 if (existing == null)
                 {
                     context.Apps.Add(AppData[i]);
                 }
                 else
                 {
                     if (existing.Name != AppData[i].Name)
                     {
                         existing.Name = AppData[i].Name;
                         context.Entry(existing).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                     }
                 }
             }
         }
         var operators = context.MobileOperators.ToList();
         if (operators == null)
         {
             context.MobileOperators.AddRange(Operators);
         }
         else
         {
             for (int i = 0; i < Operators.Count; i++)
             {
                 var existing = operators.FirstOrDefault(x => x.Id == Operators[i].Id);
                 if (existing == null)
                 {
                     context.MobileOperators.Add(Operators[i]);
                 }
                 else
                 {
                     if (existing.Name != Operators[i].Name)
                     {
                         existing.Name = Operators[i].Name;
                         context.Entry(existing).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                     }
                 }
             }
         }
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public Attachment Insert(Attachment entity)
 {
     using (var tran = _context.Database.BeginTransaction())
     {
         try
         {
             _context.Attachments.Add(entity);
             _logRepository.Insert(entity);
             _context.SaveChanges();
             tran.Commit();
             return(entity);
         }
         catch (Exception ex)
         {
             tran.Rollback();
             throw ex;
         }
     }
 }
 public MobileOperatorPackage Insert(MobileOperatorPackage entity)
 {
     _context.Add(entity);
     _context.SaveChanges();
     return(entity);
 }
Ejemplo n.º 5
0
 public User Insert(User entity)
 {
     _context.Users.Add(entity);
     _context.SaveChanges();
     return(entity);
 }