public JobCardViewModel GetJobCard(int Id) { JobCard jobCard = _unitOfWork.JobCardRepository.GetById(Id); if (jobCard == null) { return(null); } List <JobPartsViewModel> jobPartsViews = new List <JobPartsViewModel>(); foreach (JobParts jobPart in jobCard.JobParts) { JobPartsViewModel jobPartView = new JobPartsViewModel(jobPart) { SparePart = new SparePartsViewModel(jobPart.SparePart) }; jobPartsViews.Add(jobPartView); } EmployeeViewModel employee = new EmployeeViewModel(jobCard.Employee); JobCardViewModel jobCardView = new JobCardViewModel(jobCard) { JobParts = jobPartsViews, Employee = employee }; return(jobCardView); }
public IActionResult UpdateJobPart(JobPartsViewModel jobPartPost) { if (!ModelState.IsValid) { return(View(jobPartPost)); } _jobPart.UpdateJobPart(jobPartPost); return(RedirectToRoute(new { controller = "JobCard", action = "GetJobCard", Id = jobPartPost.JobCardId })); }
public void UpdateJobPart(JobPartsViewModel jobPartPost) { JobParts jobPart = _unitOfWork.JobPartRepository.GetById(jobPartPost.JobCardId, jobPartPost.SparePartId); int addedPart = jobPartPost.QuantityInstalled - jobPart.QuantityInstalled; jobPart.SparePart.QuantityInStock = (jobPart.SparePart.QuantityInStock - addedPart); jobPart.QuantityInstalled = jobPartPost.QuantityInstalled; _unitOfWork.JobPartRepository.Update(jobPart); _unitOfWork.Save(); _logger.LogInfo($"Part Id {jobPart.SparePartId} for job {jobPart.JobCardId} updated"); }
public void InsertJobPart(JobPartsViewModel jobPartView) { JobParts jobPart = new JobParts { JobCardId = jobPartView.JobCardId, SparePartId = jobPartView.SparePartId, QuantityInstalled = jobPartView.QuantityInstalled, SparePart = _unitOfWork.SparePartsRepository.GetById(jobPartView.SparePartId) }; jobPart.SparePart.QuantityInStock = (jobPart.SparePart.QuantityInStock - jobPart.QuantityInstalled); _unitOfWork.JobPartRepository.Insert(jobPart); _unitOfWork.Save(); _logger.LogInfo($"Part Id {jobPart.SparePartId} for job {jobPart.JobCardId} inserted"); }
public JobPartsViewModel GetJobPart(int jobId, int partId) { JobParts jobPart = _unitOfWork.JobPartRepository.GetById(jobId, partId); if (jobPart == null) { return(null); } JobPartsViewModel jobPartsView = new JobPartsViewModel(jobPart) { JobCard = new JobCardViewModel(jobPart.JobCard), SparePart = new SparePartsViewModel(jobPart.SparePart) }; return(jobPartsView); }
public JobPartsViewModel InsertJobPartView(int jobId) { IEnumerable <SparePart> parts = _unitOfWork.SparePartsRepository.Get(); List <SparePartsViewModel> partsView = new List <SparePartsViewModel>(); foreach (SparePart part in parts) { SparePartsViewModel partView = new SparePartsViewModel(part); partsView.Add(partView); } JobParts jobParts = new JobParts(); JobPartsViewModel jobPartsView = new JobPartsViewModel() { JobCardId = jobId, SparePartsList = partsView }; return(jobPartsView); }
public IActionResult UpdateJobPart([FromQuery] int jobId, int partId) { JobPartsViewModel jobPart = _jobPart.GetJobPart(jobId, partId); return(View(jobPart)); }
public IActionResult InsertJobPart([FromQuery] int jobId) { JobPartsViewModel newJobPart = _jobPart.InsertJobPartView(jobId); return(View(newJobPart)); }
public IActionResult GetJobPart(int jobId, int partId) { JobPartsViewModel jobPartsView = _jobPart.GetJobPart(jobId, partId); return(View(jobPartsView)); }