public void DeleteAccounting(int accountingId, bool isCascade) { using (var db = new LogistoDb()) { if (isCascade) { db.AccountingMarks.Delete(w => w.AccountingId == accountingId); db.Payments.Delete(w => w.AccountingId == accountingId); db.Services.Delete(w => w.AccountingId == accountingId); db.OrderAccountingRouteSegments.Delete(w => w.AccountingId == accountingId); var files = db.TemplatedDocuments.Where(w => w.AccountingId == accountingId).ToList(); foreach (var file in files) { db.Delete(file); } var docs = db.Documents.Where(w => w.AccountingId == accountingId).ToList(); foreach (var doc in docs) { db.DocumentData.Delete(w => w.DocumentId == doc.ID); db.Delete(doc); } } db.Accountings.Delete(w => w.ID == accountingId); } }
public void RemoveUserFromRole(int userId, int roleId) { using (var db = new LogistoDb()) { var rel = db.IdentityUserInRoles.FirstOrDefault(w => w.UserId == userId && w.RoleId == roleId); if (rel != null) { db.Delete(rel); } } }