Exemple #1
0
        public IHttpActionResult PutOrder(int id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != order.Id)
            {
                return BadRequest();
            }

            db.Entry(order).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemple #2
0
        public IHttpActionResult PostOrder(Order data)
        {
            //(int gridID, int tableNum, String customerName, String phoneNum, int numOfPpl, DateTime reservationTime)
            //[Route("api/Orders/{gridID}/{tableNum}/{customerName}/{phoneNum}/{numOfPpl}/{reservationTime}")]
            // get customer by phone and name

            string customerName = data.CustomerInfo.ToString().Split('-')[0];
            string phoneNum = data.CustomerInfo.ToString().Split('-')[1];
            var customer = db.Customers.Where(x => x.Name == customerName && x.PhoneNumber == phoneNum).FirstOrDefault();

            if (customer == null)
            {
                customer = new Customer
                {
                    Name = customerName,
                    PhoneNumber = phoneNum
                };

                db.Customers.Add(customer);
                db.SaveChanges();
            }

            Order order = new Order
            {
                GridId = data.GridId,
                TableNumber = data.TableNumber,
                CustomerId = customer.Id,
                NumOfPeople = data.NumOfPeople,
                FromTime = Convert.ToDateTime(data.FromTime),
                ToTime = Convert.ToDateTime(data.ToTime)
            };

            db.Orders.Add(order);
            //db.Orders.Add(data);
            db.SaveChanges();

            return Ok();
        }