public async Task <IActionResult> UpdateCustomer([FromBody] CustomerOnUpdateDto updatedCustomer, string login) { if (!ModelState.IsValid) { var result = Json(ModelState); result.StatusCode = 420; return(result); } await _customerService.UpdateAsync(updatedCustomer, login); return(Ok()); }
public async Task UpdateAsync(CustomerOnUpdateDto customerDto, string login) { var customerToUpdate = await _customerRepository.GetAsync(login); if (customerToUpdate == null) { throw new ServiceException(ErrorCodes.OwnerNotFound, "Customer doesn't exist."); } customerToUpdate.FirstName = customerDto.FirstName; customerToUpdate.LastName = customerDto.LastName; customerToUpdate.Email = customerDto.Email; customerToUpdate.Phone = customerDto.Phone; await _customerRepository.UpdateAsync(customerToUpdate); }
/// <summary> /// Update customer account. /// </summary> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="email"></param> /// <param name="phone"></param> /// <returns></returns> public async Task UpdateCustomer(string firstName, string lastName, string email, string phone) { var login = base.GetAuthorizedUserLogin(); var updateCustomer = new CustomerOnUpdateDto() { FirstName = firstName, LastName = lastName, Email = email, Phone = phone }; var updateCustomerJson = JsonConvert.SerializeObject(updateCustomer); var response = await Client.AuthenticatedPostJsonAsync($"cusomters/{login}/update", new StringContent(updateCustomerJson), Token); //TODO exceptions }