示例#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));
        }
示例#2
0
        public IHttpActionResult PostTable(int gridId, int tableNumber, int capacity, bool isSmokingAllowed, int xCoord, int yCoord, int xLength, int yLength)
        {
            // Retrieve the max id
            //var id = db.Tables.Max(x => x.Id) + 1;

            var table = new Table
            {
                //Id = id,
                Capacity         = capacity,
                GridId           = gridId,
                IsSmokingAllowed = isSmokingAllowed,
                TableNumber      = tableNumber,
                xCoord           = xCoord,
                yCoord           = yCoord,
                xLength          = xLength,
                yLength          = yLength
            };

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Tables.Add(table);
            db.SaveChanges();

            return(Ok());
        }
        public IHttpActionResult PostRestaurant(string name)
        {
            if (db.Restaurants.Where(x => x.Name == name).FirstOrDefault() != null)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    ReasonPhrase = "A restaurant with that name already exists"
                };

                throw new HttpResponseException(resp);
            }

            var id = db.Restaurants.Max(x => x.Id) + 1;

            Restaurant restaurant = new Restaurant {
                Id = id, Name = name
            };

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Restaurants.Add(restaurant);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = restaurant.Id }, restaurant));
        }
示例#4
0
        public IHttpActionResult PostGridItem(int gridId, int itemTypeId, int xCoord, int yCoord, string name)
        {
            // Retrieve the max id
            //var id = db.GridItems.Max(x => x.Id) + 1;

            GridItem gridItem = new GridItem
            {
                //Id = id,
                GridId     = gridId,
                ItemTypeId = itemTypeId,
                xCoord     = xCoord,
                yCoord     = yCoord,
                Name       = name
            };

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.GridItems.Add(gridItem);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = gridItem.Id }, gridItem));
        }
示例#5
0
        public IHttpActionResult PostGrid(int restaurantId, string date, int gridType, string name, bool isDefault, int xlen, int ylen)
        {
            //var gridToDelete = db.Grids.Where(x => x.RestaurantId == 10).FirstOrDefault();
            //if (gridToDelete != null)
            //{
            //    db.Grids.Remove(gridToDelete);
            //    db.SaveChanges();
            //}

            // Retrieve the max id
            var id = db.Grids.Max(x => x.Id) + 1;

            // To transfer the parameters to a grid
            //Grid grid = new Grid
            //{
            //    Id = id,
            //    RestaurantId = restaurantId,
            //    Date = DateTime.FromBinary(date),
            //    GridType = gridType,
            //    Name = name,
            //    IsDefault = isDefault,
            //    XLen = xlen,
            //    YLen = ylen
            //};

            Grid grid = new Grid
            {
                Id           = id,
                RestaurantId = restaurantId,
                Date         = Convert.ToDateTime(date),
                GridType     = gridType,
                Name         = name,
                IsDefault    = isDefault,
                XLen         = xlen,
                YLen         = ylen
            };

            try
            {
                db.Grids.Add(grid);

                db.SaveChanges();
            }
            catch (Exception e)
            {
                //if (!GridExists(id))
                //{
                //    return NotFound();
                //}
                //else
                //{
                //    throw;
                //}
            }

            return(Ok(grid.Id));
        }
        public IHttpActionResult PostRestaurantOwner(string name, int restaurantId, string userName, string password)
        {
            var id = db.RestaurantOwners.Max(x => x.Id) + 1;

            var restaurantOwner = new RestaurantOwner
            {
                Id           = id,
                Name         = name,
                Password     = password,
                RestaurantId = restaurantId,
                UserName     = userName
            };

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.RestaurantOwners.Add(restaurantOwner);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = restaurantOwner.Id }, restaurantOwner));
        }
示例#7
0
        public IHttpActionResult PostGridItem(int gridId, int itemTypeId, int xCoord, int yCoord, string name)
        {
            // Retrieve the max id
            //var id = db.GridItems.Max(x => x.Id) + 1;
            //var gridItemToAdd = db.GridItems.Where(x => x.Id == 10 && x.xCoord == xCoord && x.yCoord == yCoord && x.Name == name).FirstOrDefault();

            var gridItemToDelete = db.GridItems.Where(x => x.Id == gridId && x.xCoord == xCoord && x.yCoord == yCoord).FirstOrDefault();

            if (gridItemToDelete != null)
            {
                db.GridItems.Remove(gridItemToDelete);
                db.SaveChanges();
            }
            //if (gridItemToAdd == null)
            {
                GridItem gridItem = new GridItem
                {
                    //Id = id,
                    GridId     = gridId,
                    ItemTypeId = itemTypeId,
                    xCoord     = xCoord,
                    yCoord     = yCoord,
                    Name       = name
                };

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                db.GridItems.Add(gridItem);
                db.SaveChanges();
            }
            // return CreatedAtRoute("DefaultApi", new { id = gridItem.Id }, gridItem);
            return(Ok());
        }