public async Task <IActionResult> UpdateCustomer(int id, [FromBody] UpdateCustomerDTO customerDTO) { if (!ModelState.IsValid || id < 1) { _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateCustomer)}"); return(BadRequest(ModelState)); } try { var customer = await _unitOfWork.Customer.Get(q => q.Id == id); if (customer == null) { _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateCustomer)}"); return(BadRequest("Data submitted is invalid")); } _mapper.Map(customerDTO, customer); _unitOfWork.Customer.Update(customer); await _unitOfWork.Save(); return(NoContent()); } catch (Exception ex) { _logger.LogError(ex, $"Something went wrong in the {nameof(UpdateCustomer)}"); return(StatusCode(500, "Internal Server Error. Please try again later.")); } }
public IActionResult UpdateCustomerDetails(long id, UpdateCustomerDTO updateCustomerDTO) { LoginToken <Administrator> admin_token = DesirializeToken(); if (id == 0) { return(NotFound()); } if (id != updateCustomerDTO.Id) { return(BadRequest()); } Customer customer = _mapper.Map <Customer>(updateCustomerDTO); try { _loggedInAdministratorFacade.UpdateCustomerDetails(admin_token, customer); } catch (RecordAlreadyExistsException) { return(Conflict()); } return(NoContent()); }
public CustomerDTO Update(UpdateCustomerDTO updateCustomer) { var customer = _repositoryCustomer.GetById(updateCustomer.Id); _repositoryCustomer.Save(_mapper.Map <UpdateCustomerDTO, Customer>(updateCustomer, customer)); return(_mapper.Map <Customer, CustomerDTO>(customer)); }
public void Update(UpdateCustomerDTO dto) { var Customer = _DB.Customers.SingleOrDefault(x => x.Id == dto.Id && !x.IsDeleted); if (Customer != null) { Customer.Name = dto.Name; Customer.Email = dto.Email; Customer.Phone = dto.Phone; Customer.UpdatedAt = DateTime.Now; _DB.Customers.Update(Customer); _DB.SaveChanges(); } }
/// <summary> /// Update a customer. /// </summary> /// <param name="id">ID of customer to search for.</param> /// <param name="model">Data to be updated.</param> /// <returns>Returns updated customer or an appropriate error message.</returns> public CustomerDTO Update(int id, UpdateCustomerDTO model) { var customer = FindCustomer(id); customer.FirstName = model.FirstName ?? customer.FirstName; customer.LastName = model.LastName ?? customer.LastName; customer.Email = model.Email ?? customer.Email; if (model.AddressId != 0) { this.addressService.GetBaseForTest(model.AddressId); customer.AddressId = model.AddressId; customer.ModifiedOn = DateTime.UtcNow; } this.dbContext.SaveChanges(); return(new CustomerDTO(customer)); }
public IActionResult UpdateCustomer(Guid id, [FromBody] UpdateCustomerDTO customerToUpdate) { var customerEntity = _customerRepository.GetSingle(id); if (customerEntity == null) { return(NotFound()); } Mapper.Map(customerToUpdate, customerEntity); _customerRepository.Update(customerEntity); if (!_customerRepository.Save()) { //return StatusCode(500); throw new Exception("An error while attempting to update Customer data. Please try again"); } return(Ok(Mapper.Map <UpdateCustomerDTO>(customerEntity))); }
public IActionResult Update([FromBody] UpdateCustomerDTO dto) { _CustomerService.Update(dto); return(Ok(GetResponse("Updated"))); }
public IActionResult Update([FromHeader] string authorizationUsername, int id, [FromBody] UpdateCustomerDTO model) { try { this.authHelper.TryGetEmployee(authorizationUsername); var customer = this.customerService.Update(id, model); return(Ok(customer)); } catch (Exception e) { return(NotFound(e.Message)); } }