public async Task <IActionResult> Update([FromBody] UpdateManufacturerDto categoryDto)
        {
            var response = await _service.UpdateManufacturerAsync(categoryDto);

            if (!response.Success)
            {
                return(BadRequest(response));
            }

            return(Ok(response));
        }
Beispiel #2
0
        public void Update(int id, UpdateManufacturerDto dto)
        {
            var operatorDb = _manufacturerRepository.FindById(id);

            if (operatorDb == null)
            {
                throw new Exception("Manufacturer was not found");
            }

            if (dto.Name != null)
            {
                operatorDb.Name = dto.Name;
            }

            if (dto.Email != null)
            {
                operatorDb.Email = dto.Email;
            }

            if (dto.Phone != null)
            {
                operatorDb.Phone = dto.Phone;
            }

            if (dto.Website != null)
            {
                operatorDb.Website = dto.Website;
            }

            if (dto.AddressId != operatorDb.Address.Id)
            {
                var address = _addressRepository.FindById(dto.AddressId);

                if (address != null)
                {
                    operatorDb.Address = address;
                }
            }

            _manufacturerRepository.Update(operatorDb);
        }
Beispiel #3
0
        public async Task <ServiceResponse <GetManufacturerDto> > UpdateManufacturerAsync(UpdateManufacturerDto dto)
        {
            var response = new ServiceResponse <GetManufacturerDto>();

            try
            {
                var dbManufacturer = await _context.Manufacturers.FirstOrDefaultAsync(x => x.Id == dto.Id);

                if (dbManufacturer == null)
                {
                    throw new ManufacturerNotFoundException();
                }

                dbManufacturer.Name           = dto.Name;
                dbManufacturer.Description    = dto.Description;
                dbManufacturer.Phone          = dto.Phone;
                dbManufacturer.Email          = dto.Email;
                dbManufacturer.Address        = dto.Address;
                dbManufacturer.Ward           = dto.Ward;
                dbManufacturer.Province       = dto.Province;
                dbManufacturer.Representative = dto.Representative;

                _context.Manufacturers.Update(dbManufacturer);
                await _context.SaveChangeWithValidationAsync();

                response.Data = _mapper.Map <GetManufacturerDto>(dbManufacturer);
                return(response);
            }
            catch (BaseServiceException ex)
            {
                response.Success = false;
                response.Message = ex.ErrorMessage;
                response.Code    = ex.Code;

                _logger.LogError(ex.Message, ex.StackTrace);
                return(response);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                response.Code    = ErrorCode.MANUFACTURER_UNEXPECTED_ERROR;

                _logger.LogError(ex.Message, ex.StackTrace);
                return(response);
            }
        }
Beispiel #4
0
 public void Put(int id, [FromBody] UpdateManufacturerDto dto)
 {
     _manufacturerService.Update(id, dto);
 }