public JsonResult updateAllocation(int regionId, List <AllocationAction> allocationAction) { foreach (AllocationAction aa in allocationAction) { if (aa.Action == "delete") { _projectCodeAllocationService.DeleteById((int)aa.AllocationId); } else { Cats.Models.ProjectCodeAllocation newProjectAllocation = convertToEntityModel(aa); if (aa.AllocationType == "PC") { newProjectAllocation.Amount_FromProject = newProjectAllocation.Amount_FromSI; newProjectAllocation.ProjectCodeID = newProjectAllocation.SINumberID; newProjectAllocation.Amount_FromSI = 0; newProjectAllocation.SINumberID = null; } if (aa.Action == "add") { _projectCodeAllocationService.AddProjectCodeAllocation(newProjectAllocation, aa.RequisitionId, false); } else { _projectCodeAllocationService.EditProjectCodeAllocationDetail(newProjectAllocation); } } } List <RequestAllocationViewModel> list = getIndexList(regionId); return(Json(list, JsonRequestBehavior.AllowGet)); }
public bool DeleteProjectCodeAllocationDetail(ProjectCodeAllocation _ProjectCodeAllocationDetail) { if (_ProjectCodeAllocationDetail == null) return false; _unitOfWork.ProjectCodeAllocationRepository.Delete(_ProjectCodeAllocationDetail); _unitOfWork.Save(); return true; }
public bool AddProjectCodeAllocation(ProjectCodeAllocation _ProjectCodeAllocationDetail,int requisitionId,bool IsLastAssignment) { if (IsLastAssignment) { var requisition = _unitOfWork.ReliefRequisitionRepository.FindBy(r => r.RequisitionID == requisitionId).Single(); requisition.Status = 4; } _unitOfWork.ProjectCodeAllocationRepository.Add(_ProjectCodeAllocationDetail); _unitOfWork.Save(); return true; }
public ActionResult SaveProjectAllocation(RequisitionViewModel requisitionViewModel, FormCollection form, string hub, string datepicker, int RequisitionId, int Remaining=0, int PCodeqty=0, int SICodeqty=0) { DateTime date; bool isProjectCodeSelected = false; bool isSICodeSelected = false; try { date = DateTime.Parse(datepicker); //checkes if date is ethiopian date. if it is then it will enter to the catch and convert to gragorian for persistance. } catch (Exception) { var strEth = new getGregorianDate(); date = strEth.ReturnGregorianDate(datepicker); } bool isLastAssignment = false; int? pCode =null; int? siCode=null; if (Remaining < PCodeqty + SICodeqty) { ModelState.AddModelError("Errors",@"Amount entered is greater than the remaining quantity "); TempData["ModelState"] = ModelState; return RedirectToAction("Assign", "ProjectAllocation", new { ReqId= RequisitionId, Remaining = Remaining}); } var requisitionId = requisitionViewModel.RequisitionId; try { pCode = int.Parse(form["PCCode"].ToString(CultureInfo.InvariantCulture)); isProjectCodeSelected = true; } catch { pCode = null; } try { siCode = int.Parse(form["SICode"].ToString(CultureInfo.InvariantCulture)); isSICodeSelected = true; } catch(Exception ex) { siCode = null; var log = new Logger(); log.LogAllErrorsMesseges(ex,_log); } if (isProjectCodeSelected == false && isSICodeSelected == false) { ModelState.AddModelError("Errors", @"SI code or Project Code is not selected."); TempData["ModelState"] = ModelState; return RedirectToAction("Assign", "ProjectAllocation", new { ReqId = RequisitionId, Remaining = Remaining }); } if ((isProjectCodeSelected && PCodeqty == 0) || (isSICodeSelected && SICodeqty == 0)) { ModelState.AddModelError("Errors", @"Value entered for Projecte Code/SI Code is zero or Invalid. "); TempData["ModelState"] = ModelState; return RedirectToAction("Assign", "ProjectAllocation", new { ReqId = RequisitionId, Remaining = Remaining }); } var hubAllocation = _hubAllocationService.GetAllocatedHubByRequisitionNo(requisitionId); var newProjectAllocation = new ProjectCodeAllocation { AllocatedBy = 1, AlloccationDate = date, Amount_FromProject = PCodeqty, ProjectCodeID = pCode, Amount_FromSI = SICodeqty, SINumberID = siCode, HubAllocationID = hubAllocation.HubAllocationID }; if (Remaining == PCodeqty + SICodeqty) isLastAssignment = true; try { _projectCodeAllocationService.AddProjectCodeAllocation(newProjectAllocation, requisitionId, isLastAssignment); } catch(Exception exception) { var log = new Logger(); log.LogAllErrorsMesseges(exception,_log); ModelState.AddModelError("Errors",@"Can't add new project code allocation"); } if (isLastAssignment) { return RedirectToAction("AllocateProjectCode", "ProjectAllocation"); } else { return RedirectToAction("AssignedprojectCodes", "ProjectAllocation",new {requisitionId= requisitionId}); } }
public bool EditProjectCodeAllocationDetail(ProjectCodeAllocation _ProjectCodeAllocationDetail) { _unitOfWork.ProjectCodeAllocationRepository.Edit(_ProjectCodeAllocationDetail); _unitOfWork.Save(); return true; }
public bool Save(ProjectCodeAllocation _projectAllocation) { _unitOfWork.ProjectCodeAllocationRepository.Add(_projectAllocation); var hubAllocation = _unitOfWork.HubAllocationRepository.FindById(_projectAllocation.HubAllocationID); var requisition = _unitOfWork.ReliefRequisitionRepository.FindById(hubAllocation.RequisitionID); requisition.Status = 4; _unitOfWork.Save(); return true; }