Exemplo n.º 1
0
        public ActionResult Edit(int id, int caseId, int?caseMemberID)
        {
            bool hasAccess = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseAssessment, Constants.Actions.Edit, true);

            if (!hasAccess)
            {
                WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                return(RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }));
            }
            //find the existing caseassessment from database
            CaseAssessment caseassessment = caseassessmentRepository.Find(id);

            caseassessment.CaseID = caseId;
            //if (caseassessment.AssessmentTypeID == 3)
            //{
            //    return RedirectToAction(Constants.Actions.Termination, Constants.Controllers.CaseAssessment, new { Id = caseassessment.ID, CaseID = caseassessment.CaseID, CaseMemberID = caseassessment.CaseMemberID });
            //}
            WebHelper.CurrentSession.Content.Data = caseassessmentlivingconditionRepository.FindAllByCaseAssessmentID(id).ToList();
            if (caseassessment.CaseMemberID > 0)
            {
                CaseMember caseMember = casememberRepository.Find(caseassessment.CaseMemberID);
                if (caseMember != null)
                {
                    ViewBag.DisplayID = caseMember.DisplayID;
                }
            }
            else
            {
                Case varCase = caseRepository.Find(caseassessment.CaseID);
                if (varCase != null)
                {
                    ViewBag.DisplayID = varCase.DisplayID;
                }
            }
            //return editor view
            return(View(caseassessment));
        }
Exemplo n.º 2
0
        /// <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();
                }
            }
        }