public async Task <IActionResult> OnPost() { if (!ModelState.IsValid) { return(Page()); } await _customerStoreRepository.Create(Customer); return(RedirectToPage("Index")); }
public void AddNewCustomer(NewCustomer newCustomer) { if (newCustomer == null) { throw new ArgumentNullException(nameof(newCustomer)); } if (String.IsNullOrWhiteSpace(newCustomer.CustomerNumber)) { throw new ArgumentException(nameof(newCustomer.CustomerNumber)); } if (customerStore.CustomerExists(newCustomer.CustomerNumber)) { throw new InvalidOperationException("The customer number already exists."); } customerStore.Create(newCustomer); }
public async Task <ActionResult> CreateNewCustomer(Customer customer) { try { if (customer == null) { return(BadRequest()); } var customerCreated = await _repository.Create(customer); return(CreatedAtAction(nameof(GetCustomer), new { id = customerCreated.CustomerId }, customerCreated)); } catch (System.Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "There were error in createing new customer, Please contact your admin!")); } }