Beispiel #1
0
        public ActionResult DeleteCaseSmartGoalServiceLevelOutcomeAjax(int id)
        {
            bool hasAccess = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoalServiceProvider, 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 }));
            }

            //find the caseSmartGoalServiceProvider in database
            CaseSmartGoalServiceLevelOutcome casesmartgoalserviceleveloutcome = casesmartgoalserviceleveloutcomeRepository.Find(id);

            if (casesmartgoalserviceleveloutcome == null)
            {
                //set error message if it does not exist in database
                casesmartgoalserviceleveloutcome = new CaseSmartGoalServiceLevelOutcome();
                casesmartgoalserviceleveloutcome.ErrorMessage = "Service level outcome not found";
            }
            else
            {
                try
                {
                    //var primaryWorkerID = GetPrimaryWorkerOfTheCase(casesmartgoalserviceleveloutcome.CaseSmartGoal.CaseGoal.CaseMember.CaseID);
                    //if (casesmartgoalserviceleveloutcome.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 caseSmartGoalServiceProvider from database
                    casesmartgoalserviceleveloutcomeRepository.Delete(casesmartgoalserviceleveloutcome);
                    casesmartgoalserviceleveloutcomeRepository.Save();
                    //set success message
                    casesmartgoalserviceleveloutcome.SuccessMessage = "Service level outcome has been deleted successfully";
                }
                catch (CustomException ex)
                {
                    casesmartgoalserviceleveloutcome.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.")
                    {
                        casesmartgoalserviceleveloutcome.SuccessMessage = "Service level outcome has been deleted successfully";
                    }
                    else
                    {
                        ExceptionManager.Manage(ex);
                        casesmartgoalserviceleveloutcome.ErrorMessage = Constants.Messages.UnhandelledError;
                    }
                }
            }
            //return action status in json to display on a message bar
            if (casesmartgoalserviceleveloutcome.ErrorMessage.IsNotNullOrEmpty())
            {
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesmartgoalserviceleveloutcome) }));
            }
            else
            {
                return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesmartgoalserviceleveloutcome) }));
            }
        }
Beispiel #2
0
        public ActionResult SaveCaseSmartGoalServiceLevelOutcomeAjax(CaseSmartGoalServiceLevelOutcome casesmartgoalserviceleveloutcome)
        {
            //id=0 means add operation, update operation otherwise
            bool isNew     = casesmartgoalserviceleveloutcome.ID == 0;
            bool hasAccess = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoalServiceProvider, 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 }));
            }
            //validate data
            if (ModelState.IsValid)
            {
                try
                {
                    //if (!isNew)
                    //{
                    //    var primaryWorkerID = GetPrimaryWorkerOfTheCase(casesmartgoalserviceleveloutcome.CaseSmartGoal.CaseGoal.CaseMember.CaseID);
                    //    if (casesmartgoalserviceleveloutcome.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
                    casesmartgoalserviceleveloutcome.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
                    //call repository function to save the data in database
                    casesmartgoalserviceleveloutcomeRepository.InsertOrUpdate(casesmartgoalserviceleveloutcome);
                    casesmartgoalserviceleveloutcomeRepository.Save();
                    //set status message
                    if (isNew)
                    {
                        casesmartgoalserviceleveloutcome.SuccessMessage = "Service level outcome has been added successfully";
                    }
                    else
                    {
                        casesmartgoalserviceleveloutcome.SuccessMessage = "Service level outcome has been updated successfully";
                    }
                }
                catch (CustomException ex)
                {
                    casesmartgoalserviceleveloutcome.ErrorMessage = ex.UserDefinedMessage;
                }
                catch (Exception ex)
                {
                    ExceptionManager.Manage(ex);
                    casesmartgoalserviceleveloutcome.ErrorMessage = Constants.Messages.UnhandelledError;
                }
            }
            else
            {
                foreach (var modelStateValue in ViewData.ModelState.Values)
                {
                    foreach (var error in modelStateValue.Errors)
                    {
                        casesmartgoalserviceleveloutcome.ErrorMessage = error.ErrorMessage;
                        break;
                    }
                    if (casesmartgoalserviceleveloutcome.ErrorMessage.IsNotNullOrEmpty())
                    {
                        break;
                    }
                }
            }
            //return the status message in json
            if (casesmartgoalserviceleveloutcome.ErrorMessage.IsNotNullOrEmpty())
            {
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesmartgoalserviceleveloutcome) }));
            }
            else
            {
                return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesmartgoalserviceleveloutcome) }));
            }
        }