Example #1
0
        public IHttpActionResult GetGrid(int restaurantId, string date, string fromTime, string toTime)
        {
            // TODO: change the signature of this mathod to be meaningful
            //userName = "******";
            //password = "******";

            //var restaurantOwner = db.RestaurantOwners.Where(x => x.UserName == userName && x.Password == password).FirstOrDefault();

            //if (restaurantOwner == null)
            //{
            //    return NotFound();
            //}

            //var restaurantId = restaurantOwner.RestaurantId;

            var today = Convert.ToDateTime(date);

            var grid = db.Grids.Where(x => DbFunctions.TruncateTime(x.Date).Value == today && x.RestaurantId == restaurantId).FirstOrDefault();

            //var grid = db.Grids.Where(x => x.RestaurantId == restaurantId).FirstOrDefault();

            if (grid == null)
            {
                return(NotFound());
            }

            var tables = db.Tables.Where(x => x.GridId == grid.Id).ToList();

            var gridItems = db.GridItems.Where(x => x.GridId == grid.Id).ToList();
            //************************************************
            DateTime startDinner = Convert.ToDateTime(date + " " + fromTime.Replace('-', ':'));
            DateTime endDinner   = Convert.ToDateTime(date + " " + toTime.Replace('-', ':'));
            //check if the table is reserve between times or start/end dinner is part of other dinner
            var orders = db.Orders.Where(x => x.GridId == grid.Id && ((x.FromTime <= startDinner && x.ToTime > startDinner) ||
                                                                      (x.FromTime < endDinner && x.ToTime >= endDinner) ||
                                                                      (x.FromTime >= startDinner && x.ToTime <= endDinner))).ToList();


            GridDto gridDto = new GridDto();

            gridDto.simpleItems = gridItems;

            gridDto.XLen = grid.XLen;
            gridDto.YLen = grid.YLen;
            gridDto.Id   = grid.Id;

            gridDto.Items = new List <ItemDto>();

            tables.ForEach(table =>
            {
                var tableDto = new GridTableDto
                {
                    X              = table.xCoord,
                    Y              = table.yCoord,
                    MaxCapacity    = table.Capacity,
                    SmokingAllowed = table.IsSmokingAllowed,
                    TableNumber    = table.TableNumber,
                    XLen           = table.xLength,
                    YLen           = table.yLength
                };

                tableDto.Taken = orders.Where(x => x.TableNumber == tableDto.TableNumber).FirstOrDefault() != null;

                gridDto.Items.Add(tableDto);
            });

            return(Ok(gridDto));
        }
Example #2
0
        public IHttpActionResult GetGrid(int restaurantId, string date, string fromTime, string toTime)
        {
            // TODO: change the signature of this mathod to be meaningful
            //userName = "******";
            //password = "******";

            //var restaurantOwner = db.RestaurantOwners.Where(x => x.UserName == userName && x.Password == password).FirstOrDefault();

            //if (restaurantOwner == null)
            //{
            //    return NotFound();
            //}

            //var restaurantId = restaurantOwner.RestaurantId;

            var today = Convert.ToDateTime(date);

            var grid = db.Grids.Where(x => DbFunctions.TruncateTime(x.Date).Value == today && x.RestaurantId == restaurantId).FirstOrDefault();
            //var grid = db.Grids.Where(x => x.RestaurantId == restaurantId).FirstOrDefault();

            if (grid == null)
            {
                return NotFound();
            }

            var tables = db.Tables.Where(x => x.GridId == grid.Id).ToList();

            var gridItems = db.GridItems.Where(x => x.GridId == grid.Id).ToList();
            //************************************************
            DateTime startDinner = Convert.ToDateTime(date + " " + fromTime.Replace('-', ':'));
            DateTime endDinner = Convert.ToDateTime(date + " " + toTime.Replace('-', ':'));
            //check if the table is reserve between times or start/end dinner is part of other dinner
            var orders = db.Orders.Where(x => x.GridId == grid.Id && ((x.FromTime <= startDinner && x.ToTime > startDinner) ||
                                                                    (x.FromTime < endDinner && x.ToTime >= endDinner) ||
                                                                    (x.FromTime >= startDinner && x.ToTime <= endDinner))).ToList();

            GridDto gridDto = new GridDto();

            gridDto.simpleItems = gridItems;

            gridDto.XLen = grid.XLen;
            gridDto.YLen = grid.YLen;
            gridDto.Id = grid.Id;

            gridDto.Items = new List<ItemDto>();

            tables.ForEach(table =>
            {
                var tableDto = new GridTableDto
                {
                    X = table.xCoord,
                    Y = table.yCoord,
                    MaxCapacity = table.Capacity,
                    SmokingAllowed = table.IsSmokingAllowed,
                    TableNumber = table.TableNumber,
                    XLen = table.xLength,
                    YLen = table.yLength
                };

                tableDto.Taken = orders.Where(x => x.TableNumber == tableDto.TableNumber).FirstOrDefault() != null;

                gridDto.Items.Add(tableDto);
            });

            return Ok(gridDto);
        }