Esempio n. 1
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            await _customerStoreRepository.Create(Customer);

            return(RedirectToPage("Index"));
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
        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!"));
            }
        }