public async Task <bool> DeleteGroupAsync(int id) { var sData = await _Context.Settlement.Where(c => c.GroupId == id).ToListAsync(); if (sData.Count > 0) { for (var i = 0; i < sData.Count; i++) { _Context.Remove(sData[i]); } await _Context.SaveChangesAsync(); } var billData = await _Context.Bill.Where(c => c.GroupId == id).ToListAsync(); if (billData.Count > 0) { for (var i = 0; i < billData.Count; i++) { _Context.Remove(billData[i]); } await _Context.SaveChangesAsync(); } var transData = await _Context.Transactions.Where(c => c.GroupId == id).ToListAsync(); if (transData.Count > 0) { for (var i = 0; i < transData.Count; i++) { _Context.Remove(transData[i]); } await _Context.SaveChangesAsync(); } var group = await _Context.Group.SingleOrDefaultAsync(c => c.GroupId == id); _Context.Remove(group); //await _Context.SaveChangesAsync(); try { return(await _Context.SaveChangesAsync() > 0 ? true : false); } catch (System.Exception exp) { _Logger.LogError($"Error in {nameof(DeleteGroupAsync)}: " + exp.Message); } return(false); }
public async Task <bool> DeleteUserAsync(int id) { var user = await _Context.User .Include(c => c.BillMembers) .Include(c => c.Bills) .Include(c => c.Friends) .Include(c => c.groupMembers) .Include(c => c.Groups) .Include(c => c.Payers) .Include(c => c.Payersdata) .Include(c => c.SharedMembers) .Include(c => c.TPayers) .Include(c => c.TReceivers) .Include(c => c.Users) .SingleOrDefaultAsync(c => c.UserId == id); _Context.Remove(user); try { return(await _Context.SaveChangesAsync() > 0 ? true : false); } catch (System.Exception exp) { _Logger.LogError($"Error in {nameof(DeleteUserAsync)}: " + exp.Message); } return(false); }
public async Task <bool> DeleteGroupAsync(int id) { var group = await _Context.Group.SingleOrDefaultAsync(c => c.GroupId == id); _Context.Remove(group); try { return(await _Context.SaveChangesAsync() > 0 ? true : false); } catch (System.Exception exp) { _Logger.LogError($"Error in {nameof(DeleteGroupAsync)}: " + exp.Message); } return(false); }
public async Task <int> DeleteAsync(int countryId) { var countryToDelete = await _dbContext.Country .Where(x => x.CountryId == countryId) .FirstOrDefaultAsync(); _dbContext.Remove(countryToDelete); return(await _dbContext.SaveChangesAsync()); }
public virtual void Setup() { DbContext.DetachAllEntities(); foreach (var administrator in DbContext.Administrators.ToList()) { DbContext.Remove(administrator); } DbContext.SaveChanges(); }
static void TestWriteDataWarpper() { DemoDbContext remoteDbContext = new DemoDbContext(AdoHelper.CreateHelper("DemoDB")); //删除数据,必须通过DbContext 来处理,详细参见 解决方案说明.txt 文件的数据同步说明 using (IWriteDataWarpper warpper = WriteDataWarpperFactory.Create(remoteDbContext)) { UserEntity entity = new UserEntity(); entity.UID = 100; remoteDbContext.Remove <UserEntity>(entity); } }
static void InitData(string dbName, string prjId) { DemoDbContext context = new DemoDbContext(AdoHelper.CreateHelper(dbName)); //分类ID int delId = 0; for (int i = 0; i < 100; i++) { TestEntity test = new TestEntity(); test.Name = "Name" + i; test.AtTime = DateTime.Now; test.Classification = prjId; context.Add(test); UserEntity user = new UserEntity(); user.Name = "User" + i; user.Sex = false; user.Height = 1.6f + i / 10; user.Birthday = new DateTime(1990, 1, 1).AddDays(i); context.Add(user); if (i == 50) { delId = test.ID; } } //删除数据,确保被删除的ID写入到ID删除记录表中 using (IWriteDataWarpper warpper = WriteDataWarpperFactory.Create(context)) { context.Remove(new TestEntity() { ID = delId }); context.Remove(new UserEntity() { UID = delId }); } }
public async Task <bool> DeleteFriendAsync(int fid, int uid) { var data = _Context.FriendList.SingleOrDefault(c => c.UserId == uid && c.FriendId == fid); if (data == null) { var fData = _Context.FriendList.SingleOrDefault(c => c.UserId == fid && c.FriendId == uid); _Context.Remove(fData); } else { _Context.Remove(data); } try { return(await _Context.SaveChangesAsync() > 0 ? true : false); } catch (System.Exception exp) { _Logger.LogError($"Error in {nameof(DeleteFriendAsync)}: " + exp.Message); } return(false); }