Beispiel #1
0
        public async Task <IActionResult> PostNewCustomer(CustomerViewModel customerVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            // CONVERT CustomerModel TO Customer
            Customer cust = customerVM.ConvertToCustomer();
            await _context.AddCustomerAsync(cust);

            return(CreatedAtAction("PostNewCustomer", "Created"));
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateCustomer(CustomerViewModel customerVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            if (customerVM == null)
            {
                return(BadRequest("Object cannot be null"));
            }

            if (_context.GetCustomer(customerVM.CustomerId) == null)
            {
                return(NotFound("Customer Not Found"));
            }

            // CONVERT CustomerModel TO Customer
            Customer cust = customerVM.ConvertToCustomer();
            await _context.UpdateCustomerAsync(cust);

            return(Ok("Customer Updated"));
        }