示例#1
0
        public ActionResult GetCaseSmartGoalAssignmentAjax(int SmartGoalID, int CaseSmartGoalID)
        {
            CaseSmartGoalAssignment caseSmartGoalAssignment = casesmartgoalprogressRepository.FindCaseSmartGoalAssignment(SmartGoalID, CaseSmartGoalID);

            if (caseSmartGoalAssignment != null)
            {
                string startDate = string.Empty;
                if (caseSmartGoalAssignment.StartDate.HasValue)
                {
                    startDate = caseSmartGoalAssignment.StartDate.Value.ToShortDateString();
                }

                string endDate = string.Empty;
                if (caseSmartGoalAssignment.EndDate.HasValue)
                {
                    endDate = caseSmartGoalAssignment.EndDate.Value.ToShortDateString();
                }
                return(Json(new { success = true, SmartGoalStartDate = startDate, SmartGoalEndDate = endDate }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }
示例#2
0
        /// <summary>
        /// Add or Update casesmartgoal to database
        /// </summary>
        /// <param name="casesmartgoal">data to save</param>
        public void InsertOrUpdate(CaseSmartGoal casesmartgoal, NameValueCollection data, bool endOnly = false)
        {
            bool isNew = false;

            casesmartgoal.LastUpdateDate = DateTime.Now;
            if (casesmartgoal.ID == default(int))
            {
                //set the date when this record was created
                casesmartgoal.CreateDate = casesmartgoal.LastUpdateDate;
                //set the id of the worker who has created this record
                casesmartgoal.CreatedByWorkerID = casesmartgoal.LastUpdatedByWorkerID;
                //add a new record to database
                context.CaseSmartGoal.Add(casesmartgoal);
                isNew = true;
            }
            else
            {
                //update an existing record to database
                context.Entry(casesmartgoal).State = System.Data.Entity.EntityState.Modified;
            }
            Save();
            if (endOnly)
            {
                return;
            }
            if (casesmartgoal.ID > 0)
            {
                List <CaseSmartGoalServiceProvider> existingServiceProviderList = new List <CaseSmartGoalServiceProvider>();
                if (!isNew)
                {
                    existingServiceProviderList = casesmartgoalserviceproviderRepository.AllIncluding(casesmartgoal.ID).ToList();
                    if (existingServiceProviderList == null)
                    {
                        existingServiceProviderList = new List <CaseSmartGoalServiceProvider>();
                    }
                }
                else
                {
                    //add progress level outcome
                    CaseSmartGoalProgress newCaseSmartGoalProgress = new CaseSmartGoalProgress()
                    {
                        CaseSmartGoalID       = casesmartgoal.ID,
                        Comment               = "Initial Outcome",
                        CreateDate            = DateTime.Now,
                        CreatedByWorkerID     = casesmartgoal.CreatedByWorkerID,
                        LastUpdateDate        = DateTime.Now,
                        LastUpdatedByWorkerID = casesmartgoal.LastUpdatedByWorkerID,
                        ProgressDate          = DateTime.Now,
                        ServiceLevelOutcomeID = casesmartgoal.ServiceLevelOutcomeID,
                    };
                    context.CaseSmartGoalProgress.Add(newCaseSmartGoalProgress);
                    context.SaveChanges();
                }
                bool   isAdded = false;
                string selectedUsedInternalServiceProvider = casesmartgoal.UsedInternalServiceProviderIDs;
                selectedUsedInternalServiceProvider = selectedUsedInternalServiceProvider.ToString(true).Replace("false", string.Empty);
                string[] arrayselectedUsedInternalServiceProvider = selectedUsedInternalServiceProvider.ToStringArray(',', true);
                if (arrayselectedUsedInternalServiceProvider != null && arrayselectedUsedInternalServiceProvider.Length > 0)
                {
                    foreach (string qolID in arrayselectedUsedInternalServiceProvider)
                    {
                        if (existingServiceProviderList.Where(item => item.ServiceProviderID == qolID.ToInteger(true)).Count() == 0)
                        {
                            CaseSmartGoalServiceProvider newCaseSmartGoalInternalService = new CaseSmartGoalServiceProvider()
                            {
                                ServiceProviderID     = qolID.ToInteger(true),
                                CaseSmartGoalID       = casesmartgoal.ID,
                                LastUpdateDate        = DateTime.Now,
                                LastUpdatedByWorkerID = casesmartgoal.LastUpdatedByWorkerID,
                                IsUsed = true
                            };
                            casesmartgoalserviceproviderRepository.InsertOrUpdate(newCaseSmartGoalInternalService);
                            casesmartgoalserviceproviderRepository.Save();
                            isAdded = true;
                        }
                    }
                    if (isAdded)
                    {
                        existingServiceProviderList = casesmartgoalserviceproviderRepository.AllIncluding(casesmartgoal.ID).ToList();
                        if (existingServiceProviderList == null)
                        {
                            existingServiceProviderList = new List <CaseSmartGoalServiceProvider>();
                        }
                    }
                }

                bool isDeleted = false;
                foreach (CaseSmartGoalServiceProvider existingUsedInternalServiceProvider in existingServiceProviderList.Where(item => item.IsUsed == true && item.ServiceProvider != null && item.ServiceProvider.IsExternal == false))
                {
                    if (arrayselectedUsedInternalServiceProvider == null || !arrayselectedUsedInternalServiceProvider.Contains(existingUsedInternalServiceProvider.ServiceProviderID.ToString(true)))
                    {
                        string sqlQuery = @"delete from [CaseAction] where CaseSmartGoalServiceProviderID=" + existingUsedInternalServiceProvider.ID + ";";
                        context.Database.ExecuteSqlCommand(sqlQuery);
                        casesmartgoalserviceproviderRepository.Delete(existingUsedInternalServiceProvider);
                        casesmartgoalserviceproviderRepository.Save();
                        isDeleted = true;
                    }
                }

                if (isDeleted)
                {
                    existingServiceProviderList = casesmartgoalserviceproviderRepository.AllIncluding(casesmartgoal.ID).ToList();
                    if (existingServiceProviderList == null)
                    {
                        existingServiceProviderList = new List <CaseSmartGoalServiceProvider>();
                    }
                }
                isAdded = false;
                string selectedProposedInternalServiceProvider = casesmartgoal.ProposedInternalServiceProviderIDs;
                selectedProposedInternalServiceProvider = selectedProposedInternalServiceProvider.ToString(true).Replace("false", string.Empty);
                string[] arrayselectedProposedInternalServiceProvider = selectedProposedInternalServiceProvider.ToStringArray(',', true);
                if (arrayselectedProposedInternalServiceProvider != null && arrayselectedProposedInternalServiceProvider.Length > 0)
                {
                    foreach (string qolID in arrayselectedProposedInternalServiceProvider)
                    {
                        if (existingServiceProviderList.Where(item => item.ServiceProviderID == qolID.ToInteger(true)).Count() == 0)
                        {
                            CaseSmartGoalServiceProvider newCaseSmartGoalInternalService = new CaseSmartGoalServiceProvider()
                            {
                                ServiceProviderID     = qolID.ToInteger(true),
                                CaseSmartGoalID       = casesmartgoal.ID,
                                LastUpdateDate        = DateTime.Now,
                                LastUpdatedByWorkerID = casesmartgoal.LastUpdatedByWorkerID,
                                IsUsed = false
                            };
                            casesmartgoalserviceproviderRepository.InsertOrUpdate(newCaseSmartGoalInternalService);
                            casesmartgoalserviceproviderRepository.Save();
                            isAdded = true;
                        }
                    }
                    if (isAdded)
                    {
                        existingServiceProviderList = casesmartgoalserviceproviderRepository.AllIncluding(casesmartgoal.ID).ToList();
                        if (existingServiceProviderList == null)
                        {
                            existingServiceProviderList = new List <CaseSmartGoalServiceProvider>();
                        }
                    }
                }
                isDeleted = false;
                foreach (CaseSmartGoalServiceProvider existingProposedInternalServiceProvider in existingServiceProviderList.Where(item => item.IsUsed == false && item.ServiceProvider != null && item.ServiceProvider.IsExternal == false))
                {
                    if (arrayselectedProposedInternalServiceProvider == null || !arrayselectedProposedInternalServiceProvider.Contains(existingProposedInternalServiceProvider.ServiceProviderID.ToString(true)))
                    {
                        casesmartgoalserviceproviderRepository.Delete(existingProposedInternalServiceProvider);
                        casesmartgoalserviceproviderRepository.Save();
                        isDeleted = true;
                    }
                }
                if (isDeleted)
                {
                    existingServiceProviderList = casesmartgoalserviceproviderRepository.AllIncluding(casesmartgoal.ID).ToList();
                    if (existingServiceProviderList == null)
                    {
                        existingServiceProviderList = new List <CaseSmartGoalServiceProvider>();
                    }
                }
                isAdded = false;
                string selectedUsedExternalServiceProvider = casesmartgoal.UsedExternalServiceProviderIDs;
                selectedUsedExternalServiceProvider = selectedUsedExternalServiceProvider.ToString(true).Replace("false", string.Empty);
                string[] arrayselectedUsedExternalServiceProvider = selectedUsedExternalServiceProvider.ToStringArray(',', true);
                if (arrayselectedUsedExternalServiceProvider != null && arrayselectedUsedExternalServiceProvider.Length > 0)
                {
                    foreach (string qolID in arrayselectedUsedExternalServiceProvider)
                    {
                        if (existingServiceProviderList.Where(item => item.ServiceProviderID == qolID.ToInteger(true)).Count() == 0)
                        {
                            CaseSmartGoalServiceProvider newCaseSmartGoalExternalService = new CaseSmartGoalServiceProvider()
                            {
                                ServiceProviderID     = qolID.ToInteger(true),
                                CaseSmartGoalID       = casesmartgoal.ID,
                                LastUpdateDate        = DateTime.Now,
                                LastUpdatedByWorkerID = casesmartgoal.LastUpdatedByWorkerID,
                                IsUsed = true
                            };
                            casesmartgoalserviceproviderRepository.InsertOrUpdate(newCaseSmartGoalExternalService);
                            casesmartgoalserviceproviderRepository.Save();
                            isAdded = true;
                        }
                    }
                    if (isAdded)
                    {
                        existingServiceProviderList = casesmartgoalserviceproviderRepository.AllIncluding(casesmartgoal.ID).ToList();
                        if (existingServiceProviderList == null)
                        {
                            existingServiceProviderList = new List <CaseSmartGoalServiceProvider>();
                        }
                    }
                }
                isDeleted = false;
                foreach (CaseSmartGoalServiceProvider existingUsedExternalServiceProvider in existingServiceProviderList.Where(item => item.IsUsed == true && item.ServiceProvider != null && item.ServiceProvider.IsExternal == true))
                {
                    if (arrayselectedUsedExternalServiceProvider == null || !arrayselectedUsedExternalServiceProvider.Contains(existingUsedExternalServiceProvider.ServiceProviderID.ToString(true)))
                    {
                        casesmartgoalserviceproviderRepository.Delete(existingUsedExternalServiceProvider);
                        casesmartgoalserviceproviderRepository.Save();
                        isDeleted = true;
                    }
                }
                if (isDeleted)
                {
                    existingServiceProviderList = casesmartgoalserviceproviderRepository.AllIncluding(casesmartgoal.ID).ToList();
                    if (existingServiceProviderList == null)
                    {
                        existingServiceProviderList = new List <CaseSmartGoalServiceProvider>();
                    }
                }
                isAdded = false;
                string selectedProposedExternalServiceProvider = casesmartgoal.ProposedExternalServiceProviderIDs;
                selectedProposedExternalServiceProvider = selectedProposedExternalServiceProvider.ToString(true).Replace("false", string.Empty);
                string[] arrayselectedProposedExternalServiceProvider = selectedProposedExternalServiceProvider.ToStringArray(',', true);
                if (arrayselectedProposedExternalServiceProvider != null && arrayselectedProposedExternalServiceProvider.Length > 0)
                {
                    foreach (string qolID in arrayselectedProposedExternalServiceProvider)
                    {
                        if (existingServiceProviderList.Where(item => item.ServiceProviderID == qolID.ToInteger(true)).Count() == 0)
                        {
                            CaseSmartGoalServiceProvider newCaseSmartGoalExternalService = new CaseSmartGoalServiceProvider()
                            {
                                ServiceProviderID     = qolID.ToInteger(true),
                                CaseSmartGoalID       = casesmartgoal.ID,
                                LastUpdateDate        = DateTime.Now,
                                LastUpdatedByWorkerID = casesmartgoal.LastUpdatedByWorkerID,
                                IsUsed = false
                            };
                            casesmartgoalserviceproviderRepository.InsertOrUpdate(newCaseSmartGoalExternalService);
                            casesmartgoalserviceproviderRepository.Save();
                            isAdded = true;
                        }
                    }
                    if (isAdded)
                    {
                        existingServiceProviderList = casesmartgoalserviceproviderRepository.AllIncluding(casesmartgoal.ID).ToList();
                        if (existingServiceProviderList == null)
                        {
                            existingServiceProviderList = new List <CaseSmartGoalServiceProvider>();
                        }
                    }
                }
                isDeleted = false;
                foreach (CaseSmartGoalServiceProvider existingProposedExternalServiceProvider in existingServiceProviderList.Where(item => item.IsUsed == false && item.ServiceProvider != null && item.ServiceProvider.IsExternal == true))
                {
                    if (arrayselectedProposedExternalServiceProvider == null || !arrayselectedProposedExternalServiceProvider.Contains(existingProposedExternalServiceProvider.ServiceProviderID.ToString(true)))
                    {
                        casesmartgoalserviceproviderRepository.Delete(existingProposedExternalServiceProvider);
                        casesmartgoalserviceproviderRepository.Save();
                        isDeleted = true;
                    }
                }
                if (isDeleted)
                {
                    existingServiceProviderList = casesmartgoalserviceproviderRepository.AllIncluding(casesmartgoal.ID).ToList();
                    if (existingServiceProviderList == null)
                    {
                        existingServiceProviderList = new List <CaseSmartGoalServiceProvider>();
                    }
                }


                List <CaseSmartGoalAssignment> existingCaseSmartGoalAssignmentList = new List <CaseSmartGoalAssignment>();
                if (!isNew)
                {
                    existingCaseSmartGoalAssignmentList = context.CaseSmartGoalAssignment.Where(item => item.CaseSmartGoalID == casesmartgoal.ID).ToList();
                    if (existingCaseSmartGoalAssignmentList == null)
                    {
                        existingCaseSmartGoalAssignmentList = new List <CaseSmartGoalAssignment>();
                    }
                }

                string selectedCaseSmartGoalAssignment = casesmartgoal.SmartGoalIDs;
                selectedCaseSmartGoalAssignment = selectedCaseSmartGoalAssignment.ToString(true).Replace("false", string.Empty);
                string[] arrayselectedCaseSmartGoalAssignment = selectedCaseSmartGoalAssignment.ToStringArray(',', true);
                if (arrayselectedCaseSmartGoalAssignment != null && arrayselectedCaseSmartGoalAssignment.Length > 0)
                {
                    foreach (string qolID in arrayselectedCaseSmartGoalAssignment)
                    {
                        //if (existingCaseSmartGoalAssignmentList.Where(item => item.SmartGoalID == qolID.ToInteger(true)).Count() == 0)


                        var smartGoalOther = data["SmartGoalOther" + qolID] == null ? "" : data["SmartGoalOther" + qolID].ToString();

                        var qo1IDItem = existingCaseSmartGoalAssignmentList.FirstOrDefault(item => item.SmartGoalID == qolID.ToInteger(true));
                        if (qo1IDItem == null)
                        {
                            CaseSmartGoalAssignment newCaseSmartGoalAssignment = new CaseSmartGoalAssignment()
                            {
                                SmartGoalID           = qolID.ToInteger(true),
                                CaseSmartGoalID       = casesmartgoal.ID,
                                LastUpdateDate        = DateTime.Now,
                                LastUpdatedByWorkerID = casesmartgoal.LastUpdatedByWorkerID,
                                CreateDate            = DateTime.Now,
                                CreatedByWorkerID     = casesmartgoal.LastUpdatedByWorkerID,
                                IsArchived            = false
                            };
                            if (data["SmartGoalStartDate" + qolID] != null && data["SmartGoalStartDate" + qolID].IsNotNullOrEmpty() && data["SmartGoalStartDate" + qolID].ToDateTime().IsValidDate())
                            {
                                newCaseSmartGoalAssignment.StartDate = data["SmartGoalStartDate" + qolID].ToDateTime();
                            }
                            if (data["SmartGoalEndDate" + qolID] != null && data["SmartGoalEndDate" + qolID].IsNotNullOrEmpty() && data["SmartGoalEndDate" + qolID].ToDateTime().IsValidDate())
                            {
                                newCaseSmartGoalAssignment.EndDate = data["SmartGoalEndDate" + qolID].ToDateTime();
                            }
                            if (data["Comment" + qolID] != null && data["Comment" + qolID].IsNotNullOrEmpty())
                            {
                                newCaseSmartGoalAssignment.Comment = data["Comment" + qolID].ToString();
                            }


                            newCaseSmartGoalAssignment.SmartGoalOther = smartGoalOther;

                            context.CaseSmartGoalAssignment.Add(newCaseSmartGoalAssignment);
                        }
                        else if (qo1IDItem.SmartGoalOther != smartGoalOther)
                        {
                            qo1IDItem.SmartGoalOther = smartGoalOther;
                        }
                    }
                }

                foreach (CaseSmartGoalAssignment existingCaseSmartGoalAssignment in existingCaseSmartGoalAssignmentList)
                {
                    if (arrayselectedCaseSmartGoalAssignment == null || !arrayselectedCaseSmartGoalAssignment.Contains(existingCaseSmartGoalAssignment.SmartGoalID.ToString(true)))
                    {
                        context.Entry(existingCaseSmartGoalAssignment).State = System.Data.Entity.EntityState.Deleted;
                        Save();
                    }
                    else
                    {
                        if (data["SmartGoalStartDate" + existingCaseSmartGoalAssignment.SmartGoalID] != null && data["SmartGoalStartDate" + existingCaseSmartGoalAssignment.SmartGoalID].IsNotNullOrEmpty() && data["SmartGoalStartDate" + existingCaseSmartGoalAssignment.SmartGoalID].ToDateTime().IsValidDate())
                        {
                            existingCaseSmartGoalAssignment.StartDate = data["SmartGoalStartDate" + existingCaseSmartGoalAssignment.SmartGoalID].ToDateTime();
                        }
                        if (data["SmartGoalEndDate" + existingCaseSmartGoalAssignment.SmartGoalID] != null && data["SmartGoalEndDate" + existingCaseSmartGoalAssignment.SmartGoalID].IsNotNullOrEmpty() && data["SmartGoalEndDate" + existingCaseSmartGoalAssignment.SmartGoalID].ToDateTime().IsValidDate())
                        {
                            existingCaseSmartGoalAssignment.EndDate = data["SmartGoalEndDate" + existingCaseSmartGoalAssignment.SmartGoalID].ToDateTime();
                        }
                        if (data["Comment" + existingCaseSmartGoalAssignment.SmartGoalID] != null && data["Comment" + existingCaseSmartGoalAssignment.SmartGoalID].IsNotNullOrEmpty())
                        {
                            existingCaseSmartGoalAssignment.Comment = data["Comment" + existingCaseSmartGoalAssignment.SmartGoalID].ToString();
                        }
                        if (data["SmartGoalOther" + existingCaseSmartGoalAssignment.SmartGoalID] != null && data["SmartGoalOther" + existingCaseSmartGoalAssignment.SmartGoalID].IsNotNullOrEmpty())
                        {
                            existingCaseSmartGoalAssignment.Comment = data["SmartGoalOther" + existingCaseSmartGoalAssignment.SmartGoalID].ToString();
                        }
                    }
                }
            }
        }