public async Task <MobileOperatorPackage> UpdateAsync(MobileOperatorPackage entity)
        {
            _context.Entry(entity).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(await Task.FromResult(entity));
        }
        public async Task <int> DeleteAsync(int id)
        {
            var opt = await _context.MobileOperators.FirstOrDefaultAsync(x => x.Id == id);

            opt.IsDeleted             = 1;
            _context.Entry(opt).State = EntityState.Modified;
            return(await _context.SaveChangesAsync());
        }
Ejemplo n.º 3
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.º 4
0
        public async Task <SimCard> ActivateAsync(string mobileNumber, int operation)
        {
            var simcard = await _context.SimCards.FirstOrDefaultAsync(x => x.MobileNumber == mobileNumber);

            simcard.IsActive = operation;
            _context.Entry(simcard).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(await Task.FromResult(simcard));
        }
Ejemplo n.º 5
0
        public async Task <App> UpdateAsync(App entity)
        {
            _context.Entry(entity).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(await Task.FromResult(entity));
        }
Ejemplo n.º 6
0
        public async Task <int> DeleteAsync(int simCardId, int userId, string username)
        {
            using (var tran = await _context.Database.BeginTransactionAsync())
            {
                try
                {
                    var attachment = await _context.Attachments.FirstOrDefaultAsync(x => x.SimCardId == simCardId);

                    if (attachment != null)
                    {
                        var sim = _context.SimCards.FirstOrDefault(x => x.Id == simCardId);
                        sim.IsActive              = 0;
                        sim.UpdateTime            = DateTime.Now;
                        sim.UpdateByUser          = username;
                        sim.UpdateBy              = userId;
                        _context.Entry(sim).State = EntityState.Modified;
                        _context.Remove(attachment);
                        attachment.UserName = username;
                        attachment.UserId   = userId;
                        await _logRepository.InsertAsync(attachment, 2);

                        var response = await _context.SaveChangesAsync();

                        await tran.CommitAsync();

                        return(await Task.FromResult(1));
                    }
                    return(0);
                }
                catch (Exception ex)
                {
                    await tran.RollbackAsync();

                    throw ex;
                }
            }
        }