public ActionResult EditorAjax(int id, string caseId)
        {
            CaseSupportCircle casesupportcircle = null;

            if (id > 0)
            {
                //find an existing casesupportcircle from database
                casesupportcircle = casesupportcircleRepository.Find(id);
                if (casesupportcircle == null)
                {
                    //throw an exception if id is provided but data does not exist in database
                    return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "Case Support Circle not found"));
                }
            }
            else
            {
                //create a new instance if id is not provided
                casesupportcircle        = new CaseSupportCircle();
                casesupportcircle.CaseID = caseId.ToInteger(true);
            }

            ViewBag.PossibleCreatedByWorkers     = workerRepository.All;
            ViewBag.PossibleLastUpdatedByWorkers = workerRepository.All;
            //return the html of editor to display on popup
            return(Content(this.RenderPartialViewToString(Constants.PartialViews.CreateOrEdit, casesupportcircle)));
        }
        public ActionResult DeleteAjax(int id)
        {
            //find the casesupportcircle in database
            CaseSupportCircle casesupportcircle = casesupportcircleRepository.Find(id);

            if (casesupportcircle == null)
            {
                //set error message if it does not exist in database
                casesupportcircle = new CaseSupportCircle();
                casesupportcircle.ErrorMessage = "CaseSupportCircle not found";
            }
            else
            {
                try
                {
                    if (casesupportcircle.CreatedByWorkerID != 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 casesupportcircle from database
                    casesupportcircleRepository.Delete(casesupportcircle);
                    casesupportcircleRepository.Save();
                    //set success message
                    casesupportcircle.SuccessMessage = "Case Support Circle has been deleted successfully";
                }
                catch (CustomException ex)
                {
                    casesupportcircle.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.")
                    {
                        casesupportcircle.SuccessMessage = "Case Support Circle has been deleted successfully";
                    }
                    else
                    {
                        ExceptionManager.Manage(ex);
                        casesupportcircle.ErrorMessage = Constants.Messages.UnhandelledError;
                    }
                }
            }
            //return action status in json to display on a message bar
            if (casesupportcircle.ErrorMessage.IsNotNullOrEmpty())
            {
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesupportcircle) }));
            }
            else
            {
                return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesupportcircle) }));
            }
        }
        public ActionResult SaveAjax(CaseSupportCircle casesupportcircle)
        {
            //id=0 means add operation, update operation otherwise
            bool isNew = casesupportcircle.ID == 0;

            //validate data
            if (ModelState.IsValid)
            {
                try
                {
                    if (casesupportcircle.CreatedByWorkerID != 0)
                    {
                        if (!isNew && casesupportcircle.CreatedByWorkerID != 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 });
                        }
                    }
                    casesupportcircle.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
                    casesupportcircleRepository.InsertOrUpdate(casesupportcircle);
                    casesupportcircleRepository.Save();
                    if (isNew)
                    {
                        casesupportcircle.SuccessMessage = "Case Support Circle has been added successfully";
                    }
                    else
                    {
                        casesupportcircle.SuccessMessage = "Case Support Circle has been updated successfully";
                    }
                }
                catch (CustomException ex)
                {
                    casesupportcircle.ErrorMessage = ex.UserDefinedMessage;
                }
                catch (Exception ex)
                {
                    ExceptionManager.Manage(ex);
                    casesupportcircle.ErrorMessage = Constants.Messages.UnhandelledError;
                }
            }
            else
            {
                foreach (var modelStateValue in ViewData.ModelState.Values)
                {
                    foreach (var error in modelStateValue.Errors)
                    {
                        casesupportcircle.ErrorMessage = error.ErrorMessage;
                        break;
                    }
                    if (casesupportcircle.ErrorMessage.IsNotNullOrEmpty())
                    {
                        break;
                    }
                }
            }
            if (casesupportcircle.ErrorMessage.IsNotNullOrEmpty())
            {
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesupportcircle) }));
            }
            else
            {
                return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.Alert, casesupportcircle) }));
            }
        }