コード例 #1
0
        // to add a customer to the database
        public async Task <HttpResponseMessage> PostAsync(Customer customer)
        {
            List <Customer> customers = await sqlDbHelper.GetCustomers();

            // to check if there are no customers with the same card number
            //in case of none a new customer will be created
            if (customers.Find(a => a.CardNumber == customer.CardNumber) == null)
            {
                await sqlDbHelper.AddCustomer(customer);

                return(Request.CreateResponse(HttpStatusCode.OK, "Created"));
            }
            // if there are customers already with the same card number, no customers will be created
            // and it will return cannot be created string.
            else
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Cannot be created!"));
            }
        }