public ActionResult <InvestigationDto> CreateInvestigation([FromBody] InvestigationDto investigationDto) { try { if (investigationDto is null) { return(BadRequest("Investigation can't be null")); } var investigation = new InvestigationMapper().ToModel(investigationDto); var send = _unitOfWork.Investigations.Add(investigation); _unitOfWork.Save(); var dto = new InvestigationMapper().ToDto(send); return(CreatedAtAction(nameof(GetInvestigationById), new { id = dto.InvestigationId }, dto)); } catch (Exception e) { throw new HttpRequestException(e.Message, e, HttpStatusCode.InternalServerError); } }
public async Task <Investigation> Map(InvestigationDto investigationDto) { Investigation investigation = new() { InvestigationId = investigationDto.InvestigationId, Reason = investigationDto.Reason, NumberOfPets = investigationDto.NumberOfPets, Breed = investigationDto.Breed }; investigation.Set(investigationDto.IsFinish); PersonService ps = new(); InvestigationPersonService ips = new(); investigation.HolderInvestigatorId = await ps.GetPerson(investigationDto.HolderInvestigatorId); investigation.InvestigationOffenderId = await ips.GetInvestigationPerson(investigationDto.InvestigationOffenderId); investigation.InvestigationPlaintiffId = await ips.GetInvestigationPerson(investigationDto.InvestigationPlaintiffId); investigation.Persons = await ps.Get(); return(investigation); }
public ActionResult <InvestigationDto> UpdateInvestigation([FromRoute] int id, [FromBody] InvestigationDto investigationDto) { try { var investigation = new InvestigationMapper().ToModel(investigationDto); investigation.InvestigationId ??= id; var result = _unitOfWork.Investigations.Update(id, investigation); _unitOfWork.Save(); return(Ok(new InvestigationMapper().ToDto(result))); } catch (Exception e) { throw new HttpRequestException(e.Message, e, HttpStatusCode.InternalServerError); } }
public async Task <InvestigationDto> UpdateInvestigationAsync(int id, InvestigationDto investigation) { return(await new HttpRequestService <InvestigationDto>().UpdateAsync(id, investigation, BaseUrl, Api)); }