示例#1
0
        public ActionResult EditorAjax(int id, string casesmartgoalId)
        {
            bool hasAccess = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoalProgress, 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 }));
            }
            CaseSmartGoalProgress casesmartgoalprogress = null;

            if (id > 0)
            {
                //find an existing casesmartgoalprogress from database
                casesmartgoalprogress = casesmartgoalprogressRepository.Find(id);
                if (casesmartgoalprogress == null)
                {
                    //throw an exception if id is provided but data does not exist in database
                    return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "Case Smart Goal Progress not found"));
                }
            }
            else
            {
                //create a new instance if id is not provided
                casesmartgoalprogress = new CaseSmartGoalProgress();
                casesmartgoalprogress.CaseSmartGoalID = casesmartgoalId.ToInteger(true);
            }

            ViewBag.PossibleCreatedByWorkers     = workerRepository.All;
            ViewBag.PossibleLastUpdatedByWorkers = workerRepository.All;
            ViewBag.PossibleServiceLevelOutcomes = serviceleveloutcomeRepository.All;
            //return the html of editor to display on popup
            return(Content(this.RenderPartialViewToString(Constants.PartialViews.EditorPopUp, casesmartgoalprogress)));
        }
示例#2
0
        public ActionResult Edit(CaseSmartGoalProgress casesmartgoalprogress, int casesmartgoalId)
        {
            casesmartgoalprogress.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
            try
            {
                var casesmartgoalprogress1 = casesmartgoalprogressRepository.Find(casesmartgoalprogress.ID);
                if (casesmartgoalprogress.ProgressDate > DateTime.Today)
                {
                    throw new CustomException("Progress date can't be future date.");
                }
                //validate data
                if (ModelState.IsValid)
                {
                    //<JL:Comment:No need to check access again on post. On edit we are already checking permission.>
                    //var primaryWorkerID = GetPrimaryWorkerOfTheCase(casesmartgoalprogress1.CaseSmartGoal.CaseGoal.CaseMember.CaseID);
                    //if (casesmartgoalprogress.ID > 0 && casesmartgoalprogress.CreatedByWorkerID != CurrentLoggedInWorker.ID && primaryWorkerID != CurrentLoggedInWorker.ID && CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 && (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) == -1))
                    //{
                    //    WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                    //   // return Json(new { success = true, url = Url.Action(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }) });
                    //   return RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty });
                    //}
                    //</JL:Comment:07/08/2017>

                    //call the repository function to save in database
                    casesmartgoalprogressRepository.InsertOrUpdate(casesmartgoalprogress);
                    casesmartgoalprogressRepository.Save();
                    //redirect to list page after successful operation
                    return(RedirectToAction(Constants.Views.Index, new { casesmartgoalId = casesmartgoalId }));
                }
                else
                {
                    foreach (var modelStateValue in ViewData.ModelState.Values)
                    {
                        foreach (var error in modelStateValue.Errors)
                        {
                            casesmartgoalprogress.ErrorMessage = error.ErrorMessage;
                            break;
                        }
                        if (casesmartgoalprogress.ErrorMessage.IsNotNullOrEmpty())
                        {
                            break;
                        }
                    }
                }
            }
            catch (CustomException ex)
            {
                casesmartgoalprogress.ErrorMessage = ex.UserDefinedMessage;
            }
            catch (Exception ex)
            {
                ExceptionManager.Manage(ex);
                casesmartgoalprogress.ErrorMessage = Constants.Messages.UnhandelledError;
            }
            ViewBag.PossibleCreatedByWorkers     = workerRepository.All;
            ViewBag.PossibleLastUpdatedByWorkers = workerRepository.All;
            ViewBag.PossibleServiceLevelOutcomes = serviceleveloutcomeRepository.All;
            //return view with error message if the operation is failed
            return(View(casesmartgoalprogress));
        }
示例#3
0
 public ActionResult Create(CaseSmartGoalProgress casesmartgoalprogress, int casesmartgoalId)
 {
     casesmartgoalprogress.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
     try
     {
         if (casesmartgoalprogress.ProgressDate > DateTime.Today)
         {
             throw new CustomException("Progress date can't be future date.");
         }
         //validate data
         if (ModelState.IsValid)
         {
             //call the repository function to save in database
             casesmartgoalprogressRepository.InsertOrUpdate(casesmartgoalprogress);
             casesmartgoalprogressRepository.Save();
             //redirect to list page after successful operation
             return(RedirectToAction(Constants.Views.Index, new { casesmartgoalId = casesmartgoalId }));
         }
         else
         {
             foreach (var modelStateValue in ViewData.ModelState.Values)
             {
                 foreach (var error in modelStateValue.Errors)
                 {
                     casesmartgoalprogress.ErrorMessage = error.ErrorMessage;
                     break;
                 }
                 if (casesmartgoalprogress.ErrorMessage.IsNotNullOrEmpty())
                 {
                     break;
                 }
             }
         }
     }
     catch (CustomException ex)
     {
         casesmartgoalprogress.ErrorMessage = ex.UserDefinedMessage;
     }
     catch (Exception ex)
     {
         ExceptionManager.Manage(ex);
         casesmartgoalprogress.ErrorMessage = Constants.Messages.UnhandelledError;
     }
     ViewBag.PossibleCreatedByWorkers     = workerRepository.All;
     ViewBag.PossibleLastUpdatedByWorkers = workerRepository.All;
     ViewBag.PossibleServiceLevelOutcomes = serviceleveloutcomeRepository.All;
     //return view with error message if operation is failed
     return(View(casesmartgoalprogress));
 }
示例#4
0
        public ActionResult Edit(int id)
        {
            bool hasAccess = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoalProgress, 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 casesmartgoalprogress from database
            CaseSmartGoalProgress casesmartgoalprogress = casesmartgoalprogressRepository.Find(id);

            ViewBag.PossibleCreatedByWorkers     = workerRepository.All;
            ViewBag.PossibleLastUpdatedByWorkers = workerRepository.All;
            ViewBag.PossibleServiceLevelOutcomes = serviceleveloutcomeRepository.All;
            //return editor view
            return(View(casesmartgoalprogress));
        }
示例#5
0
        public ActionResult Create(int casesmartgoalId)
        {
            bool hasAccess = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoalProgress, Constants.Actions.Create, 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 }));
            }

            //create a new instance of casesmartgoalprogress
            CaseSmartGoalProgress casesmartgoalprogress = new CaseSmartGoalProgress();

            casesmartgoalprogress.CaseSmartGoalID = casesmartgoalId;
            ViewBag.PossibleCreatedByWorkers      = workerRepository.All;
            ViewBag.PossibleLastUpdatedByWorkers  = workerRepository.All;
            ViewBag.PossibleServiceLevelOutcomes  = serviceleveloutcomeRepository.All;
            //return view result
            return(View(casesmartgoalprogress));
        }
示例#6
0
        public ViewResult Index(int casesmartgoalId, int caseId, int?caseMemberId)
        {
            CaseSmartGoal caseSmartGoal = casesmartgoalRepository.Find(casesmartgoalId);

            if (caseSmartGoal != null)
            {
                List <CaseSmartGoalAssignment> goalAssignmentList = casesmartgoalRepository.FindAllCaseSmartGoalAssignmentByCaseSmargGoalID(caseSmartGoal.ID);
                if (goalAssignmentList != null)
                {
                    foreach (CaseSmartGoalAssignment goalAssignment in goalAssignmentList)
                    {
                        caseSmartGoal.SmartGoalName = caseSmartGoal.SmartGoalName.Concate(",", goalAssignment.SmartGoal.Name);
                    }
                }
            }
            caseSmartGoal.CaseID = caseId;
            CaseSmartGoalProgress caseSmartGoalProgress = new CaseSmartGoalProgress();

            caseSmartGoalProgress.CaseSmartGoal      = caseSmartGoal;
            caseSmartGoalProgress.CaseSmartGoalID    = casesmartgoalId;
            caseSmartGoalProgress.PendingActionCount = caseactionRepository.FindPendingActionCount(casesmartgoalId);

            if (caseMemberId.HasValue && caseMemberId.Value > 0)
            {
                caseSmartGoalProgress.CaseMemberID = caseMemberId.Value;
                CaseMember caseMember = casememberRepository.Find(caseSmartGoalProgress.CaseMemberID);
                if (caseMember != null)
                {
                    ViewBag.DisplayID = caseMember.DisplayID;
                }
            }
            else
            {
                var varCase = caseRepository.Find(caseId);
                if (varCase != null)
                {
                    ViewBag.DisplayID = varCase.DisplayID;
                }
            }
            return(View(caseSmartGoalProgress));
        }
示例#7
0
        public ActionResult DeleteAjax(int id)
        {
            //find the casesmartgoalprogress in database
            CaseSmartGoalProgress casesmartgoalprogress = casesmartgoalprogressRepository.Find(id);

            if (casesmartgoalprogress == null)
            {
                //set error message if it does not exist in database
                casesmartgoalprogress = new CaseSmartGoalProgress();
                casesmartgoalprogress.ErrorMessage = "CaseSmartGoalProgress not found";
            }
            else
            {
                try
                {
                    bool hasAccess = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoalProgress, Constants.Actions.Delete, 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 }));
                    }

                    //var primaryWorkerID = GetPrimaryWorkerOfTheCase(casesmartgoalprogress.CaseSmartGoal.CaseGoal.CaseMember.CaseID);
                    //if (casesmartgoalprogress.CreatedByWorkerID != CurrentLoggedInWorker.ID && primaryWorkerID != CurrentLoggedInWorker.ID && CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 && (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) == -1))
                    //{
                    //    WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                    //    return Json(new { success = true, url = Url.Action(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }) });
                    //    //return RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty });
                    //}
                    //delete casesmartgoalprogress from database
                    casesmartgoalprogressRepository.Delete(casesmartgoalprogress);
                    casesmartgoalprogressRepository.Save();
                    //set success message
                    casesmartgoalprogress.SuccessMessage = "Case Smart Goal Progress has been deleted successfully";
                }
                catch (CustomException ex)
                {
                    casesmartgoalprogress.ErrorMessage = ex.UserDefinedMessage;
                }
                catch (Exception ex)
                {
                    if (ex.Message == "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.")
                    {
                        casesmartgoalprogress.SuccessMessage = "Case Smart Goal Progress has been deleted successfully";
                    }
                    else
                    {
                        ExceptionManager.Manage(ex);
                        casesmartgoalprogress.ErrorMessage = Constants.Messages.UnhandelledError;
                    }
                }
            }
            //return action status in json to display on a message bar
            if (casesmartgoalprogress.ErrorMessage.IsNotNullOrEmpty())
            {
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesmartgoalprogress) }));
            }
            else
            {
                return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesmartgoalprogress) }));
            }
        }
示例#8
0
        public ActionResult SaveAjax(CaseSmartGoalProgress casesmartgoalprogress)
        {
            //id=0 means add operation, update operation otherwise
            bool isNew = casesmartgoalprogress.ID == 0;

            //validate data
            if (ModelState.IsValid)
            {
                try
                {
                    if (casesmartgoalprogress.ProgressDate > DateTime.Today)
                    {
                        throw new CustomException("Progress date can't be future date.");
                    }
                    //if (!isNew)
                    //{
                    //    var casesmartgoalprogress1 = casesmartgoalprogressRepository.Find(casesmartgoalprogress.ID);
                    //    var primaryWorkerID = GetPrimaryWorkerOfTheCase(casesmartgoalprogress1.CaseSmartGoal.CaseGoal.CaseMember.CaseID);
                    //    if (casesmartgoalprogress.CreatedByWorkerID != CurrentLoggedInWorker.ID && primaryWorkerID != CurrentLoggedInWorker.ID && CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 && (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) == -1))
                    //    {
                    //        WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                    //        return Json(new { success = true, url = Url.Action(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }) });
                    //        //return RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty });
                    //    }
                    //}
                    //set the id of the worker who has added/updated this record
                    casesmartgoalprogress.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
                    //call repository function to save the data in database
                    casesmartgoalprogressRepository.InsertOrUpdate(casesmartgoalprogress);
                    casesmartgoalprogressRepository.Save();
                    //set status message
                    if (isNew)
                    {
                        casesmartgoalprogress.SuccessMessage = "Case Smart Goal Progress has been added successfully";
                    }
                    else
                    {
                        casesmartgoalprogress.SuccessMessage = "Case Smart Goal Progress has been updated successfully";
                    }
                }
                catch (CustomException ex)
                {
                    casesmartgoalprogress.ErrorMessage = ex.UserDefinedMessage;
                }
                catch (Exception ex)
                {
                    ExceptionManager.Manage(ex);
                    casesmartgoalprogress.ErrorMessage = Constants.Messages.UnhandelledError;
                }
            }
            else
            {
                foreach (var modelStateValue in ViewData.ModelState.Values)
                {
                    foreach (var error in modelStateValue.Errors)
                    {
                        casesmartgoalprogress.ErrorMessage = error.ErrorMessage;
                        break;
                    }
                    if (casesmartgoalprogress.ErrorMessage.IsNotNullOrEmpty())
                    {
                        break;
                    }
                }
            }
            //return the status message in json
            if (casesmartgoalprogress.ErrorMessage.IsNotNullOrEmpty())
            {
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesmartgoalprogress) }));
            }
            else
            {
                return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesmartgoalprogress) }));
            }
        }
示例#9
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();
                        }
                    }
                }
            }
        }