Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateReport(Guid id, [FromBody] ReportForUpdateDto report)
        {
            if (report == null)
            {
                _logger.LogError("Report object sent from client is null.");
                return(BadRequest("Report object is null"));
            }

            //This checks all of the validation attributes on the object to make sure the values are valid
            if (!ModelState.IsValid)
            {
                _logger.LogError("Invalid report object sent from client.");
                return(BadRequest("Invalid model object"));
            }

            var reportEntity = await _repoWrapper.Report.GetReportByIdAsync(id);

            if (reportEntity == null)
            {
                _logger.LogError($"report with id: {id} not found");
                return(NotFound());
            }

            _mapper.Map(report, reportEntity);
            _repoWrapper.Report.UpdateReport(reportEntity);
            await _repoWrapper.SaveAsync();

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateReport(int id, int reportId, ReportForUpdateDto reportForUpdateDto)
        {
            var user = await database.UserRepository.Get <User>(id);

            var report = user.Reports.FirstOrDefault(r => r.Id == reportId);

            if (report == null)
            {
                throw new EntityNotFoundException("Zgłoszenie");
            }

            report = mapper.Map <ReportForUpdateDto, Report>(reportForUpdateDto, report);

            report.UpdateReport();

            if (await database.Complete())
            {
                return(NoContent());
            }

            return(BadRequest("Nie udało się zaktualizować zgłoszenia"));
        }