private bool InsertPermission(OralConsultationItem item, OralConsultation entity) { foreach (var itm in db.TmpOralConsultationPermissions.Where(p => p.GUID == item.GUID)) { OralConsultationPermission dbItem = new OralConsultationPermission { OralConsultation = entity, UserID = itm.UserID, IsChange = itm.IsChange, IsRead = itm.IsRead, OralConsultationID = itm.OralConsultationID, OralConsultationPermissionID = itm.OralConsultationPermissionID }; db.OralConsultationPermissions.Add(dbItem); } List <int> deletionTempItems = new List <int>(); foreach (var itm3 in db.TmpOralConsultationPermissions.Where(p => p.GUID == item.GUID)) { deletionTempItems.Add(itm3.ID); } foreach (int ID in deletionTempItems) { db.TmpOralConsultationPermissions.Remove(db.TmpOralConsultationPermissions.Find(ID)); } return(true); }
private bool UpdatePermission(OralConsultationItem item, OralConsultation entity) { List <int> existingItems = new List <int>(); foreach (var itm in db.TmpOralConsultationPermissions.Where(p => p.GUID == item.GUID)) { existingItems.Add(itm.OralConsultationPermissionID); OralConsultationPermission dbItem = new OralConsultationPermission { OralConsultation = entity, UserID = itm.UserID, IsChange = itm.IsChange, IsRead = itm.IsRead, OralConsultationID = itm.OralConsultationID, OralConsultationPermissionID = itm.OralConsultationPermissionID }; if (itm.OralConsultationPermissionID == 0) { db.OralConsultationPermissions.Add(dbItem); } else { db.OralConsultationPermissions.Attach(dbItem); db.Entry(dbItem).State = EntityState.Modified; } } List <int> deletedItems = new List <int>(); foreach (var itm2 in db.OralConsultationPermissions.Where(p => p.OralConsultationID == item.OralConsultationID)) { deletedItems.Add(itm2.OralConsultationPermissionID); } List <int> common = deletedItems.Except(existingItems).ToList(); foreach (int deletionID in common) { db.OralConsultationPermissions.Remove(db.OralConsultationPermissions.Find(deletionID)); } List <int> deletionTempItems = new List <int>(); foreach (var itm3 in db.TmpOralConsultationPermissions.Where(p => p.GUID == item.GUID)) { deletionTempItems.Add(itm3.ID); } foreach (int ID in deletionTempItems) { db.TmpOralConsultationPermissions.Remove(db.TmpOralConsultationPermissions.Find(ID)); } return(true); }