public IActionResult UpdateReport(int id, int reportId, [FromBody] ReportDTO reportDtoDto) { var buildingId = new BuildingId(id); var reportRepository = ReportRepository(buildingId); if (!reportRepository.Exists(reportId)) { return(NotFound()); } var report = new BubelSoft.Building.Domain.Models.Report(reportId, reportDtoDto.Date, reportDtoDto.NumberOfWorkers, _userSession.User.Id, buildingId); if (!_reportAccessRules.CanAccess(report, _userSession.User.Id)) { return(Forbid()); } foreach (var reportQuantity in reportDtoDto.Work) { report.AddOrUpdateWork(reportQuantity.EstimationId, reportQuantity.Quantity); } reportRepository.Save(report); return(Ok()); }
public IActionResult CreateReport(int id, [FromBody] ReportDTO reportDtoDto) { var buildingId = new BuildingId(id); var reportRepository = ReportRepository(buildingId); var report = new BubelSoft.Building.Domain.Models.Report(reportDtoDto.Date, reportDtoDto.NumberOfWorkers, _userSession.User.Id, buildingId); foreach (var reportQuantity in reportDtoDto.Work) { report.AddOrUpdateWork(reportQuantity.EstimationId, reportQuantity.Quantity); } reportRepository.Save(report); return(Ok(report.Id)); }