public WorkPackageReportDetailsViewModel(WorkPackageReportDetails _workPackageReportDetails) { this.LabourGradeId = _workPackageReportDetails.LabourGradeId; this.LabourGradeName = _workPackageReportDetails.LabourGradeName; this.ReBudgetDay = _workPackageReportDetails.ResponsibleEngineerBudgetInDays; this.TotalDays = _workPackageReportDetails.TotalDays; this.ReETC = _workPackageReportDetails.ReEstimateToCompletion; this.ReEAC = _workPackageReportDetails.ReEstimateAtCompletion; this.Variance = _workPackageReportDetails.VariancePercent; this.Complete = _workPackageReportDetails.CompletionPercent; }
public async Task <ActionResult <WorkPackageReport> > PostWorkPackageReport(WorkPackageReportViewModel workPackageReportViewModel) { try { int wpId = (await _workPackageRepository.GetAll()) .FirstOrDefault(w => w.WorkPackageCode.Equals(workPackageReportViewModel.WorkPackageCode)) .WorkPackageId; await _workPackageReportRepository.Add(new WorkPackageReport(workPackageReportViewModel, wpId)); var thisReport = (await _workPackageReportRepository.GetAll()).OrderByDescending(x => x.LastUpdatedTime).FirstOrDefault(); foreach (WorkPackageReportDetailsViewModel details in workPackageReportViewModel.Details) { WorkPackageReportDetails wpReportDetails = new WorkPackageReportDetails(); wpReportDetails.LabourGradeId = details.LabourGradeId; wpReportDetails.WorkPackageReportId = thisReport.WorkPackageReportId; wpReportDetails.LabourGradeName = details.LabourGradeName; wpReportDetails.ResponsibleEngineerBudgetInDays = details.ReBudgetDay; wpReportDetails.TotalDays = details.TotalDays; wpReportDetails.ReEstimateAtCompletion = details.ReEAC; wpReportDetails.ReEstimateToCompletion = details.ReETC; wpReportDetails.VariancePercent = details.Variance; wpReportDetails.CompletionPercent = details.Complete; wpReportDetails.LastUpdatedBy = Environment.UserName; wpReportDetails.LastUpdatedTime = DateTime.Now; await _workPackageReportDetailsRepository.Add(wpReportDetails); //await _workPackageReportDetailsRepository.Add(new WorkPackageReportDetails(details, wpId)); } return(Ok(200)); } catch (NullReferenceException e) { return(Ok(new Exception("Null pointer: WorkPackageview's wp code might not exist in database. " + "Cannot get ID for wp code."))); } catch (Exception e) { return(Ok(new Exception("Failed to add, something went wrong: " + e.ToString()))); } }