public OralConsultationConsultantItem UpdateConsultant(OralConsultationConsultantItem item) { try { TmpOralConsultationConsultant entity = new TmpOralConsultationConsultant { ID = item.ID, OralConsultationConsultantID = item.OralConsultationConsultantID, OralConsultationID = item.OralConsultationID, ConsultantID = item.ConsultantID, GUID = item.GUID }; db.TmpOralConsultationConsultants.Attach(entity); db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); Consultant consultant = db.Consultants.Find(item.ConsultantID); item.ConsultantName = consultant.FirstName + " " + consultant.LastName; return(item); } catch (Exception ex) { exception = ex; return(null); } }
public OralConsultationConsultantItem DeleteConsultant(OralConsultationConsultantItem item) { try { TmpOralConsultationConsultant entity = new TmpOralConsultationConsultant { ID = item.ID, OralConsultationConsultantID = item.OralConsultationConsultantID, OralConsultationID = item.OralConsultationID, ConsultantID = item.ConsultantID, GUID = item.GUID }; db.TmpOralConsultationConsultants.Attach(entity); db.TmpOralConsultationConsultants.Remove(entity); db.SaveChanges(); return(item); } catch (Exception ex) { exception = ex; return(null); } }
public OralConsultationConsultantItem InsertConsultant(OralConsultationConsultantItem item) { try { TmpOralConsultationConsultant entity = new TmpOralConsultationConsultant { OralConsultationConsultantID = 0, OralConsultationID = item.OralConsultationID, ConsultantID = item.ConsultantID, GUID = item.GUID }; db.TmpOralConsultationConsultants.Add(entity); db.SaveChanges(); item.ID = entity.ID; item.OralConsultationConsultantID = entity.OralConsultationConsultantID; Consultant consultant = db.Consultants.Find(item.ConsultantID); item.ConsultantName = consultant.FirstName + " " + consultant.LastName; return(item); } catch (Exception ex) { exception = ex; return(null); } }
public OralConsultationItem GetOralConsultationItemByID(int oralConsultationID) { var oralConsultation = db.OralConsultations.Find(oralConsultationID); var issue = db.Issues.Find(oralConsultation.IssueID); OralConsultationItem item = new OralConsultationItem { OralConsultationID = oralConsultation.OralConsultationID, IssueID = issue.IssueID, IssueName = issue.IssueName, IssueDate = issue.IssueDate, IssueDescription = issue.IssueDescription, OralConsultationDate = oralConsultation.OralConsultationDate, InvocationTypeID = oralConsultation.InvocationTypeID, TargetGroupID = oralConsultation.TargetGroupID, ProblemDescription = oralConsultation.ProblemDescription, ConsultationDescription = oralConsultation.ConsultationDescription, GUID = Guid.NewGuid(), InitializationType = InitializationTypes.Update, UserID = String.Empty, ChangeDate = null }; foreach (var consultant in db.OralConsultationConsultants.Where(p => p.OralConsultationID == oralConsultationID)) { TmpOralConsultationConsultant itm = new TmpOralConsultationConsultant(); itm.OralConsultationConsultantID = consultant.OralConsultationConsultantID; itm.OralConsultationID = consultant.OralConsultationID; itm.ConsultantID = consultant.ConsultantID; itm.GUID = item.GUID; db.TmpOralConsultationConsultants.Add(itm); } foreach (var organization in db.OralConsultationOrganizations.Where(p => p.OralConsultationID == oralConsultationID)) { TmpOralConsultationOrganization itm = new TmpOralConsultationOrganization(); itm.OralConsultationOrganizationID = organization.OralConsultationOrganizationID; itm.OralConsultationID = organization.OralConsultationID; itm.OrganizationID = organization.OrganizationID; itm.GUID = item.GUID; db.TmpOralConsultationOrganizations.Add(itm); } foreach (var right in db.OralConsultationRights.Where(p => p.OralConsultationID == oralConsultationID)) { TmpOralConsultationRight itm = new TmpOralConsultationRight(); itm.OralConsultationRightID = right.OralConsultationRightID; itm.OralConsultationID = right.OralConsultationID; itm.HumanRightID = right.HumanRightID; itm.GUID = item.GUID; db.TmpOralConsultationRights.Add(itm); } foreach (var permission in db.OralConsultationPermissions.Where(p => p.OralConsultationID == oralConsultationID)) { TmpOralConsultationPermission itm = new TmpOralConsultationPermission(); itm.OralConsultationPermissionID = permission.OralConsultationPermissionID; itm.OralConsultationID = permission.OralConsultationID; itm.UserID = permission.UserID; itm.IsChange = permission.IsChange; itm.IsRead = permission.IsRead; itm.GUID = item.GUID; db.TmpOralConsultationPermissions.Add(itm); } db.SaveChanges(); return(item); }