public async Task <IActionResult> Create([FromBody] CompanyForManipulationDto company) { if (company == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState.GetValidationErrors())); } var companyToAdd = _mapper.Map <Company>(company); await _companyRepository.AddAsync(companyToAdd); return(CreatedAtRoute("GetCompany", companyToAdd, new { id = companyToAdd.Id })); }
public async Task <IActionResult> Update(int id, [FromBody] CompanyForManipulationDto company) { var companyToUpdate = await _companyRepository.GetSingleAsync(id); if (companyToUpdate == null) { return(NotFound()); } if (company == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState.GetValidationErrors())); } _mapper.Map(company, companyToUpdate); await _companyRepository.UpdateAsync(companyToUpdate); return(NoContent()); }