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()); }
public async Task <MobileOperatorPackage> InsertAsync(MobileOperatorPackage entity) { await _context.AddAsync(entity); await _context.SaveChangesAsync(); return(await Task.FromResult(entity)); }
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)); }
public async Task <App> InsertAsync(string name) { int maxId = await _context.Apps.MaxAsync(x => x.Id); var entity = new App { Id = maxId + 1, Name = name }; _context.Apps.Add(entity); await _context.SaveChangesAsync(); return(await Task.FromResult(entity)); }
public async Task <User> InsertAsync(User entity) { await _context.Users.AddAsync(entity); await _context.SaveChangesAsync(); return(await Task.FromResult(entity)); }
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; } } }
public async Task <AttachmentLog> InsertAsync(Attachment attachment, int addOrRemove = 1) { var entity = new AttachmentLog { SimCardId = attachment.SimCardId, AssetId = attachment.AssetId, AppId = attachment.AppId, LogType = addOrRemove, UserName = attachment.UserName, UserId = attachment.UserId }; await _context.AttachmentLogs.AddAsync(entity); await _context.SaveChangesAsync(); return(await Task.FromResult(entity)); }