public ActionResult <CompanyCreateDto> CreateCompany(CompanyCreateDto companyCreateDto) { // Map Dto to Model var companyModel = _mapper.Map <Company>(companyCreateDto); _repository.CreateCompany(companyModel); _repository.SaveChanges(); var companyReadDto = _mapper.Map <CompanyReadDto>(companyModel); // CreatedAtRoute creates 201 created with specified values. return(CreatedAtRoute(nameof(GetCompanyById), new { Id = companyReadDto.Id }, companyReadDto)); }
public IActionResult PostCompany([FromBody] Company company) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var companyDto = _companyRepo.CreateCompany(company); if (companyDto == null) { return(BadRequest()); } return(CreatedAtAction("GetCompany", new { id = company.Id }, companyDto)); }