/// <summary> /// Add or Update caseworker to database /// </summary> /// <param name="caseworker">data to save</param> public void InsertOrUpdate(CaseWorker caseworker) { //when a member is set as primary, release others from primary is there is any if (caseworker.IsPrimary && caseworker.CaseID > 0) { string sqlQuery = "UPDATE CaseWorker SET IsPrimary=0 WHERE CaseID=" + caseworker.CaseID; context.Database.ExecuteSqlCommand(sqlQuery); } //set a member as primary if there is no primary member has been set if (!caseworker.IsPrimary) { int count = context.CaseWorker.Where(item => item.CaseID == caseworker.CaseID && item.IsPrimary == true).Count(); if (count == 0) { caseworker.IsPrimary = true; } } caseworker.LastUpdateDate = DateTime.Now; if (caseworker.ID == default(int)) { //set the date when this record was created caseworker.CreateDate = caseworker.LastUpdateDate; //set the id of the worker who has created this record caseworker.CreatedByWorkerID = caseworker.LastUpdatedByWorkerID; //add a new record to database context.CaseWorker.Add(caseworker); } else { //update an existing record to database var NewCaseworker = context.CaseWorker.Where(a => a.ID == caseworker.ID).FirstOrDefault(); NewCaseworker.CaseID = caseworker.CaseID; NewCaseworker.WorkerID = caseworker.WorkerID; NewCaseworker.IsActive = caseworker.IsActive; NewCaseworker.AllowNotification = caseworker.AllowNotification; NewCaseworker.IsPrimary = caseworker.IsPrimary; NewCaseworker.IsArchived = caseworker.IsArchived; NewCaseworker.LastUpdateDate = DateTime.Now; //context.Entry(caseworker).State = System.Data.Entity.EntityState.Modified; } Save(); if (caseworker.IsPrimary) { string caseLink = "/CaseManagement/CaseMemberProfile/Index?caseId=" + caseworker.CaseID; WorkerNotification workerNotification = new WorkerNotification() { IsRead = false, LastUpdateDate = DateTime.Now, LastUpdatedByWorkerID = caseworker.LastUpdatedByWorkerID, Notification = "You are assigned to a new case. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the case detail.", ReferenceLink = caseLink, WorkerID = caseworker.WorkerID }; workernotificationRepository.InsertOrUpdate(workerNotification); workernotificationRepository.Save(); } }
/// <summary> /// Add or Update CaseSmartGoalServiceProvider to database /// </summary> /// <param name="CaseSmartGoalServiceProvider">data to save</param> public void InsertOrUpdate(CaseSmartGoalServiceProvider casesmartgoalserviceprovider) { bool isNew = false; if (casesmartgoalserviceprovider.WorkerID == 0) { casesmartgoalserviceprovider.WorkerID = null; } casesmartgoalserviceprovider.LastUpdateDate = DateTime.Now; if (casesmartgoalserviceprovider.ID == default(int)) { isNew = true; //set the date when this record was created casesmartgoalserviceprovider.CreateDate = casesmartgoalserviceprovider.LastUpdateDate; //set the id of the worker who has created this record casesmartgoalserviceprovider.CreatedByWorkerID = casesmartgoalserviceprovider.LastUpdatedByWorkerID; //add a new record to database context.CaseSmartGoalServiceProvider.Add(casesmartgoalserviceprovider); } else { //update an existing record to database context.Entry(casesmartgoalserviceprovider).State = System.Data.Entity.EntityState.Modified; } Save(); if (casesmartgoalserviceprovider.ID > 0 && casesmartgoalserviceprovider.WorkerID.HasValue && casesmartgoalserviceprovider.WorkerID.Value > 0) { string caseLink = "/CaseManagement/CaseSmartGoalServiceProvider/Index?casesmartgoalId=" + casesmartgoalserviceprovider.CaseSmartGoalID + "&CaseID=" + casesmartgoalserviceprovider.CaseID + "&CaseMemberID=" + casesmartgoalserviceprovider.CaseMemberID; WorkerNotification workerNotification = new WorkerNotification() { IsRead = false, LastUpdateDate = DateTime.Now, LastUpdatedByWorkerID = casesmartgoalserviceprovider.LastUpdatedByWorkerID, ReferenceLink = caseLink, WorkerID = casesmartgoalserviceprovider.WorkerID.Value }; if (isNew) { workerNotification.Notification = "A new service provider has been added to a case. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the service provider detail."; } else { workerNotification.Notification = "A service provider has been updated. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the service provider detail."; } workernotificationRepository.InsertOrUpdate(workerNotification); workernotificationRepository.Save(); } }
/// <summary> /// Add or Update caseprogressnote to database /// </summary> /// <param name="caseprogressnote">data to save</param> public void InsertOrUpdate(CaseProgressNote caseprogressnote) { bool isNew = false; caseprogressnote.LastUpdateDate = DateTime.Now; if (caseprogressnote.ID == default(int)) { isNew = true; //set the date when this record was created caseprogressnote.CreateDate = caseprogressnote.LastUpdateDate; //set the id of the worker who has created this record caseprogressnote.CreatedByWorkerID = caseprogressnote.LastUpdatedByWorkerID; //add a new record to database context.CaseProgressNote.Add(caseprogressnote); } else { //update an existing record to database context.Entry(caseprogressnote).State = System.Data.Entity.EntityState.Modified; } Save(); if (caseprogressnote.ID > 0) { CaseWorker primaryWorker = caseworkerRepository.FindPrimary(caseprogressnote.CaseID); if (primaryWorker != null) { string caseLink = "/CaseManagement/CaseProgressNote/Edit?noteID=" + caseprogressnote.ID + "&CaseID=" + caseprogressnote.CaseID + "&CaseMemberID=" + caseprogressnote.CaseMemberID; WorkerNotification workerNotification = new WorkerNotification() { IsRead = false, LastUpdateDate = DateTime.Now, LastUpdatedByWorkerID = caseprogressnote.LastUpdatedByWorkerID, ReferenceLink = caseLink, WorkerID = primaryWorker.WorkerID }; if (isNew) { workerNotification.Notification = "A new progress note has been added to a case. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the note detail."; } else { workerNotification.Notification = "A progress note has been updated. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the note detail."; } workernotificationRepository.InsertOrUpdate(workerNotification); workernotificationRepository.Save(); } } }
/// <summary> /// Add or Update caseaction to database /// </summary> /// <param name="caseaction">data to save</param> public void InsertOrUpdate(CaseAction caseaction) { bool isNew = false; if (caseaction.CaseSmartGoalServiceProviderID > 0) { caseaction.CaseProgressNoteID = null; caseaction.CaseSmartGoalID = null; } if (caseaction.CaseProgressNoteID == 0) { caseaction.CaseProgressNoteID = null; } if (caseaction.CaseSmartGoalID == 0) { caseaction.CaseSmartGoalID = null; } caseaction.LastUpdateDate = DateTime.Now; if (caseaction.ID == default(int)) { isNew = true; //set the date when this record was created caseaction.CreateDate = caseaction.LastUpdateDate; //set the id of the worker who has created this record caseaction.CreatedByWorkerID = caseaction.LastUpdatedByWorkerID; //add a new record to database context.CaseAction.Add(caseaction); } else { //update an existing record to database context.Entry(caseaction).State = System.Data.Entity.EntityState.Modified; } Save(); if (caseaction.CaseProgressNoteID.HasValue && caseaction.CaseProgressNoteID.Value > 0) { CaseWorker primaryWorker = caseworkerRepository.FindPrimary(caseaction.CaseID); if (primaryWorker != null) { string caseLink = "/CaseManagement/CaseProgressNote/Edit?noteID=" + caseaction.CaseProgressNoteID.Value + "&CaseID=" + caseaction.CaseID + "&CaseMemberID=" + caseaction.CaseMemberID; WorkerNotification workerNotification = new WorkerNotification() { IsRead = false, LastUpdateDate = DateTime.Now, LastUpdatedByWorkerID = caseaction.LastUpdatedByWorkerID, ReferenceLink = caseLink, WorkerID = primaryWorker.WorkerID }; if (isNew) { workerNotification.Notification = "A new action has been added to a progress note. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the note detail."; } else { workerNotification.Notification = "A progress note action has been updated. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the note detail."; } workernotificationRepository.InsertOrUpdate(workerNotification); workernotificationRepository.Save(); } } else if (caseaction.CaseSmartGoalServiceProviderID.HasValue && caseaction.CaseSmartGoalServiceProviderID.Value > 0) { CaseSmartGoalServiceProvider casesmartgoalserviceprovider = casesmartgoalserviceproviderRepository.Find(caseaction.CaseSmartGoalServiceProviderID.Value); if (casesmartgoalserviceprovider != null && casesmartgoalserviceprovider.WorkerID.HasValue && casesmartgoalserviceprovider.WorkerID.Value > 0) { string caseLink = "/CaseManagement/CaseSmartGoalServiceProvider/Index?casesmartgoalId=" + casesmartgoalserviceprovider.CaseSmartGoalID + "&CaseID=" + caseaction.CaseID + "&CaseMemberID=" + caseaction.CaseMemberID; WorkerNotification workerNotification = new WorkerNotification() { IsRead = false, LastUpdateDate = DateTime.Now, LastUpdatedByWorkerID = casesmartgoalserviceprovider.LastUpdatedByWorkerID, ReferenceLink = caseLink, WorkerID = casesmartgoalserviceprovider.WorkerID.Value }; if (isNew) { workerNotification.Notification = "A new action has been added to a service provider. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the service provider detail."; } else { workerNotification.Notification = "A service provider action has been updated. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the service provider detail."; } workernotificationRepository.InsertOrUpdate(workerNotification); workernotificationRepository.Save(); } } if (caseaction.CaseWorkerID.HasValue && caseaction.CaseWorkerID.Value > 0) { int workerID = 0; if (caseaction.CaseSmartGoalServiceProviderID.HasValue && caseaction.CaseSmartGoalServiceProviderID.Value > 0) { CaseSmartGoalServiceProvider casesmartgoalserviceprovider = casesmartgoalserviceproviderRepository.Find(caseaction.CaseSmartGoalServiceProviderID.Value); if (casesmartgoalserviceprovider != null && casesmartgoalserviceprovider.WorkerID.HasValue) { workerID = casesmartgoalserviceprovider.WorkerID.Value; } } if (workerID == 0) { CaseWorker caseWorker = caseworkerRepository.Find(caseaction.CaseWorkerID.Value); if (caseWorker != null) { workerID = caseWorker.WorkerID; } } if (workerID > 0) { string caseLink = "/CaseManagement/CaseAction/Index?CaseID=" + caseaction.CaseID + "&CaseMemberID=" + caseaction.CaseMemberID; WorkerToDo workerToDo = new WorkerToDo() { LastUpdateDate = DateTime.Now, LastUpdatedByWorkerID = caseaction.LastUpdatedByWorkerID, ReferenceLink = caseLink, WorkerID = workerID, IsCompleted = false, }; if (isNew) { workerToDo.Subject = "A new action has been assigned to you. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the detail."; } else if (caseaction.IsCompleted) { workerToDo.Subject = "An action assigned to you has been completed. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the detail."; } else { workerToDo.Subject = "An action assigned to you has been updated. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the detail."; } workertodoRepository.InsertOrUpdate(workerToDo); workertodoRepository.Save(); } } }
/// <summary> /// Add or Update caseassessment to database /// </summary> /// <param name="caseassessment">data to save</param> public void InsertOrUpdate(CaseAssessment caseassessment, NameValueCollection data) { bool isNew = false; caseassessment.LastUpdateDate = DateTime.Now; if (caseassessment.ID == default(int)) { //set the date when this record was created caseassessment.CreateDate = caseassessment.LastUpdateDate; //set the id of the worker who has created this record caseassessment.CreatedByWorkerID = caseassessment.LastUpdatedByWorkerID; //add a new record to database context.CaseAssessment.Add(caseassessment); isNew = true; } else { //update an existing record to database context.Entry(caseassessment).State = System.Data.Entity.EntityState.Modified; } Save(); if (caseassessment.ID > 0) { CaseMember existingCaseMember = context.CaseMember.SingleOrDefault(item => item.ID == caseassessment.CaseMemberID); if (existingCaseMember != null) { try { existingCaseMember.MemberStatusID = caseassessment.MemberStatusID; existingCaseMember.LastUpdateDate = DateTime.Now; existingCaseMember.LastUpdatedByWorkerID = caseassessment.LastUpdatedByWorkerID; context.Entry(existingCaseMember).State = System.Data.Entity.EntityState.Modified; Save(); } catch { context.Entry(existingCaseMember).State = System.Data.Entity.EntityState.Detached; } } List <CaseAssessmentLivingCondition> existingQOLList = new List <CaseAssessmentLivingCondition>(); if (!isNew) { existingQOLList = caseassessmentlivingconditionRepository.FindAllByCaseAssessmentID(caseassessment.ID).ToList(); if (existingQOLList == null) { existingQOLList = new List <CaseAssessmentLivingCondition>(); } } string selectedQOL = caseassessment.QualityOfLifeIDs; selectedQOL = selectedQOL.Replace("false", string.Empty); string[] arraySelectedQOL = selectedQOL.ToStringArray(',', true); if (arraySelectedQOL != null && arraySelectedQOL.Length > 0) { foreach (string qolID in arraySelectedQOL) { if (existingQOLList.Where(item => item.QualityOfLifeID == qolID.ToInteger(true)).Count() == 0) { CaseAssessmentLivingCondition newCaseAssessmentLivingCondition = new CaseAssessmentLivingCondition() { QualityOfLifeID = qolID.ToInteger(true), CaseAssessmentID = caseassessment.ID, LastUpdateDate = DateTime.Now, LastUpdatedByWorkerID = caseassessment.LastUpdatedByWorkerID, }; newCaseAssessmentLivingCondition.Note = data["txtQualityOfLifeIDs" + qolID].ToString(true); caseassessmentlivingconditionRepository.InsertOrUpdate(newCaseAssessmentLivingCondition); caseassessmentlivingconditionRepository.Save(); } else { CaseAssessmentLivingCondition caseAssessmentLivingCondition = caseassessmentlivingconditionRepository.Find(caseassessment.ID, qolID.ToInteger(true)); if (caseAssessmentLivingCondition != null) { caseAssessmentLivingCondition.Note = data["txtQualityOfLifeIDs" + qolID].ToString(true); caseAssessmentLivingCondition.LastUpdateDate = DateTime.Now; caseassessmentlivingconditionRepository.InsertOrUpdate(caseAssessmentLivingCondition); caseassessmentlivingconditionRepository.Save(); } } } } foreach (CaseAssessmentLivingCondition existingQOL in existingQOLList) { if (arraySelectedQOL == null || !arraySelectedQOL.Contains(existingQOL.QualityOfLifeID.ToString(true))) { caseassessmentlivingconditionRepository.Delete(existingQOL); caseassessmentlivingconditionRepository.Save(); } } CaseWorker primaryWorker = caseworkerRepository.FindPrimary(caseassessment.CaseID); if (primaryWorker != null) { string caseLink = "/CaseManagement/CaseAssessment?CaseID=" + caseassessment.CaseID + "&CaseMemberID=" + caseassessment.CaseMemberID; WorkerNotification workerNotification = new WorkerNotification() { IsRead = false, LastUpdateDate = DateTime.Now, LastUpdatedByWorkerID = caseassessment.LastUpdatedByWorkerID, ReferenceLink = caseLink, WorkerID = primaryWorker.WorkerID }; if (isNew) { workerNotification.Notification = "A new assessment has been added to a case. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the assessment detail."; } else { workerNotification.Notification = "An assessment has been updated. Please <a href='" + caseLink + "' target='_blank'>click here</a> to see the assessment detail."; } workernotificationRepository.InsertOrUpdate(workerNotification); workernotificationRepository.Save(); } } }