public ActionResult EditorAjax(int id, int caseId) { CaseWorker caseworker = null; Case varCase = caseRepository.Find(caseId); bool hasAccess = workerroleactionpermissionnewRepository.HasPermission(caseId, CurrentLoggedInWorkerRoleIDs, CurrentLoggedInWorker.ID, varCase.ProgramID, varCase.RegionID, varCase.SubProgramID, varCase.JamatkhanaID, Constants.Areas.CaseManagement, Constants.Controllers.CaseWorker, 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 })); } if (id > 0) { //find an existing caseworker from database caseworker = caseworkerRepository.Find(id); if (caseworker == null) { //throw an exception if id is provided but data does not exist in database return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "Case Worker not found")); } caseworker.CaseMemberList = casememberRepository.FindAllByCaseIDForDropDownList(caseId); List <CaseWorkerMemberAssignment> assignment = caseworkermemberassignmentRepository.FindAllByCaseWorkerID(caseworker.ID); if (assignment != null) { foreach (SelectListItem caseMember in caseworker.CaseMemberList) { if (assignment.Where(item => item.CaseMemberID == caseMember.Value.ToInteger(true)).Count() > 0) { caseMember.Selected = true; } } } } else { //create a new instance if id is not provided caseworker = new CaseWorker(); caseworker.CaseID = caseId.ToInteger(true); } //List<SelectListItem> workerList = workerRepository.FindAllPossible(varCase.ProgramID, varCase.RegionID, varCase.SubProgramID); List <SelectListItem> workerList = workerRepository.NewFindAllPossible(varCase.ProgramID, varCase.RegionID, varCase.SubProgramID); if (workerList == null || (workerList != null && workerList.Count == 0)) { caseworker.ErrorMessage = "There is no worker found for Program:" + varCase.Program.Name + ", Region:" + varCase.Region.Name + ", Sub-Program:" + varCase.SubProgram.Name; } ViewBag.PossibleWorkerList = workerList; //return the html of editor to display on popup return(Content(this.RenderPartialViewToString(Constants.PartialViews.CreateOrEdit, caseworker))); }
public ActionResult Create(CaseWorker caseworker) { caseworker.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID; try { //validate data if (ModelState.IsValid) { //if (!string.IsNullOrEmpty(caseworker.CaseWorkerNote.Note) || caseworker.CaseWorkerNote.NoteDate != null || // caseworker.CaseWorkerNote.TimeSpentHours != null || caseworker.CaseWorkerNote.TimeSpentMinutes != null // || (caseworker.CaseWorkerNote.ContactMethodID != null && caseworker.CaseWorkerNote.ContactMethodID > 0)) //{ // var isnoteerror = false; // if (string.IsNullOrEmpty(caseworker.CaseWorkerNote.Note)) // { // ModelState.AddModelError("", "Please enter work note."); // isnoteerror = true; // } // if (caseworker.CaseWorkerNote.NoteDate == null) // { // ModelState.AddModelError("", "Please enter not date"); // isnoteerror = true; // } // if ((caseworker.CaseWorkerNote.TimeSpentHours == null || caseworker.CaseWorkerNote.TimeSpentHours == 0) && // (caseworker.CaseWorkerNote.TimeSpentMinutes == null || caseworker.CaseWorkerNote.TimeSpentMinutes == 0)) // { // ModelState.AddModelError("", "Please enter time spent"); // isnoteerror = true; // } // if (caseworker.CaseWorkerNote.ContactMethodID == null || caseworker.CaseWorkerNote.ContactMethodID == 0) // { // ModelState.AddModelError("", "Please select contact method"); // isnoteerror = true; // } // if (isnoteerror) // { // Case varCase = caseRepository.Find(caseId); // List<SelectListItem> workerList = workerRepository.NewFindAllPossible(varCase.ProgramID, varCase.RegionID, varCase.SubProgramID); // if (workerList == null || (workerList != null && workerList.Count == 0)) // { // caseworker.ErrorMessage = "There is no worker found for Program:" + varCase.Program.Name + ", Region:" + varCase.Region.Name + ", Sub-Program:" + varCase.SubProgram.Name; // } // ViewBag.PossibleWorkerList = workerList; // return View(caseworker); // } //} //call the repository function to save in database caseworker.IsActive = true; caseworkerRepository.InsertOrUpdate(caseworker); caseworkerRepository.Save(); string selectedCaseMember = Request.Form["SelectedCaseMember"].ToString(true); selectedCaseMember = selectedCaseMember.Replace("false", string.Empty); string[] arraySelectedCaseMember = selectedCaseMember.ToStringArray(',', true); List <CaseWorkerMemberAssignment> assignment = caseworkermemberassignmentRepository.FindAllByCaseWorkerID(caseworker.ID); if (arraySelectedCaseMember != null && arraySelectedCaseMember.Length > 0) { foreach (string caseMemberID in arraySelectedCaseMember) { if (assignment.Where(item => item.CaseMemberID == caseMemberID.ToInteger(true)).Count() == 0) { CaseWorkerMemberAssignment newCaseWorkerMemberAssignment = new CaseWorkerMemberAssignment() { CaseMemberID = caseMemberID.ToInteger(true), CaseWorkerID = caseworker.ID, LastUpdateDate = DateTime.Now, LastUpdatedByWorkerID = caseworker.LastUpdatedByWorkerID }; caseworkermemberassignmentRepository.InsertOrUpdate(newCaseWorkerMemberAssignment); caseworkermemberassignmentRepository.Save(); } } } foreach (CaseWorkerMemberAssignment existingMember in assignment) { if (arraySelectedCaseMember == null || !arraySelectedCaseMember.Contains(existingMember.CaseMemberID.ToString(true))) { caseworkermemberassignmentRepository.Delete(existingMember); caseworkermemberassignmentRepository.Save(); } } //if (caseworker.CaseWorkerNote.ContactMethodID > 0) //{ // caseworker.CaseWorkerNote.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID; // caseworker.CaseWorkerNote.CaseID = caseworker.CaseID; // //caseMember.CaseWorkerNote.CaseStatusID = varCase.CaseStatusID; // //caseMember.CaseWorkerNote.ProgramID = varCase.ProgramID; // caseworker.CaseWorkerNote.IsFamily = true; // caseworker.CaseWorkerNote.IsFamilyMember = false; // caseworker.CaseWorkerNote.WorkerNoteActivityTypeID = (int)WorkerNoteActivityType.CaseWorker; // //varCase.CaseWorkerNote.NoteDate = Convert.ToDateTime(varCase.ContactDate); // caseWorkerNoteRepository.InsertOrUpdate(caseworker.CaseWorkerNote); // caseWorkerNoteRepository.Save(); //} //redirect to list page after successful operation //return RedirectToAction(Constants.Views.Index, new { caseId = caseId }); return(RedirectToAction(Constants.Actions.Index, Constants.Controllers.CaseSummary, new { caseID = caseworker.CaseID })); } else { foreach (var modelStateValue in ViewData.ModelState.Values) { foreach (var error in modelStateValue.Errors) { caseworker.ErrorMessage = error.ErrorMessage; break; } if (caseworker.ErrorMessage.IsNotNullOrEmpty()) { break; } } } } catch (CustomException ex) { caseworker.ErrorMessage = ex.UserDefinedMessage; } catch (Exception ex) { ExceptionManager.Manage(ex); caseworker.ErrorMessage = Constants.Messages.UnhandelledError; } ViewBag.PossibleCreatedByWorkers = workerRepository.All; ViewBag.PossibleLastUpdatedByWorkers = workerRepository.All; ViewBag.PossibleWorkers = workerRepository.All; ViewBag.DisplayID = caseRepository.Find(caseworker.CaseID).DisplayID; ViewBag.CaseID = caseworker.CaseID; return(View(caseworker)); }