public async Task <IActionResult> Update(int id, CompanyForUpdateDTO companyForUpdateDTO)
        {
            /*
             * ---------------------------------------------------------------------------
             * ZONA DE VALIDACION
             * ---------------------------------------------------------------------------
             */
            // Chequear si el producto existe
            var companyDB = await _companyRepository.GetCompany(id);

            if (companyDB == null)
            {
                throw new Exception($"Company with id {id} does not exist");
            }


            /*
             * --------------------------------------------------------------------------
             * ZONA DE PROCESAMIENTO DE LA PETICION
             * --------------------------------------------------------------------------
             */
            _mapper.Map(companyForUpdateDTO, companyDB);

            if (await _companyRepository.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Error while updating company with id: {id}");
        }
        public async Task <IActionResult> UpdateCompany(Guid id, [FromBody] CompanyForUpdateDTO company)
        {
            var companyEntity = HttpContext.Items["Company"] as Company;

            _mapper.Map(company, companyEntity);

            await _repository.SaveAsync();

            return(NoContent());
        }
Exemple #3
0
        public async Task <IActionResult> UpdateCompany(Guid id, [FromBody] CompanyForUpdateDTO company)
        {
            var companyToUpdate = HttpContext.Items["company"] as Company;

            if (companyToUpdate == null)
            {
                _mapper.Map(company, companyToUpdate);
            }
            await _repository.SaveAsync();

            return(NoContent());
        }
Exemple #4
0
        public async Task <IActionResult> UpdateCompany(Guid id, [FromBody] CompanyForUpdateDTO company)
        {
            var companyEntity = HttpContext.Items["company"] as Company;

            if (companyEntity == null)
            {
                _logger.LogInfo($"Company with id: {id} doesn't exist in the database.");
                return(NotFound());
            }

            // mapping to a tacked entity updates its fields, as well as add any Employees embedded within CompanyForUpdateDTO

            _mapper.Map(company, companyEntity);

            await _repository.SaveAsync();

            return(NoContent());
        }