Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }