public IActionResult Update(long id, [FromBody] UpdateCustomerDto item) { try { Result <CustomerName> customerNameOrError = CustomerName.Create(item.Name); if (customerNameOrError.IsFailure) { return(BadRequest(customerNameOrError.Error)); } Customer customer = _customerRepository.GetById(id); if (customer == null) { return(BadRequest("Invalid customer id: " + id)); } customer.Name = customerNameOrError.Value; return(Ok()); } catch (Exception e) { return(StatusCode(500, new { error = e.Message })); } }
public IActionResult Update(long id, [FromBody] UpdateCustomerDto item) { Result <CustomerName> customerNameOrError = CustomerName.Create(item.Name); if (customerNameOrError.IsFailure) { return(Error(customerNameOrError.Error)); } Customer customer = _customerRepository.GetById(id); if (customer == null) { return(Error("Invalid customer id: " + id)); } customer.Name = customerNameOrError.Value; return(Ok()); }
public IActionResult UpdateCustomer(long id, UpdateCustomerDto customerModel) { var customerNameOrError = CustomerName.Create(customerModel.Name); if (customerNameOrError.IsFailure) { return(Error(customerNameOrError.Error)); } var customer = _customerRepository.GetById(id); if (customer == null) { return(Error($"[{id}] is an invalid customer id")); } customer.Name = customerNameOrError.Value; return(Ok(customer)); }
public IActionResult Update(long id, [FromBody] UpdateCustomerDto item) { var customerNameOrError = CustomerName.Create(item.Name); if (!customerNameOrError.IsSuccess) { return(Error(customerNameOrError.Error)); } Customer customer = _customerRepository.GetById(id); if (customer == null) { return(Error($"Invalid customer id: {id}")); } customer.Name = customerNameOrError.Value; return(Ok()); }
public IActionResult Update(long id, [FromBody] UpdateCustomerDto item) { //try //{ Result <CustomerName> customerNameOrError = CustomerName.Create(item.Name); Result result = Result.Combine(customerNameOrError); if (result.IsFailure) { //return BadRequest(result.Error); return(Error(result.Error)); } //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} Customer customer = _customerRepository.GetById(id); if (customer == null) { //return BadRequest("Invalid customer id: " + id); return(Error("Invalid customer id: " + id)); } customer.Name = customerNameOrError.Value; //_customerRepository.SaveChanges(); return(Ok()); //} //catch (Exception e) //{ // return StatusCode(500, new { error = e.Message }); //} }