public static async Task <int> Create(Waiter waiter)
        {
            using (var db = new RestaurantDatabase())
            {
                db.Waiter.Add(waiter);
                await db.SaveChangesAsync();

                return(waiter.Id);
            }
        }
        public static async Task <int> Create(Table table)
        {
            using (var db = new RestaurantDatabase())
            {
                table.Waiter = await db.Waiter.FirstAsync(x => x.Id == table.Waiter.Id);

                db.Table.Add(table);
                await db.SaveChangesAsync();

                return(table.Id);
            }
        }
Example #3
0
        //public static async Task<int> Create(Table table)
        //{
        //    using (var db = new RestaurantDatabase())
        //    {
        //        db.Table.Add(table);
        //        await db.SaveChangesAsync();
        //        return table.Id;
        //    }
        //}

        public static async Task <int> Create(Account account)
        {
            using (var db = new RestaurantDatabase())
            {
                account.Table = await db.Table.FirstAsync(x => x.Id == account.Table.Id);

                db.Table.Add(account.Table);
                await db.SaveChangesAsync();

                return(account.Id);
            }
        }
Example #4
0
        public async Task Delete(Account account)
        {
            using (var db = new RestaurantDatabase())
            {
                Account existing = await db.Account.FirstOrDefaultAsync(x => x.Id == account.Id);

                if (existing == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
                db.Account.Remove(existing);
                await db.SaveChangesAsync();
            }
        }
        public static async Task Delete(Waiter waiter)
        {
            using (var db = new RestaurantDatabase())
            {
                Waiter existing = await db.Waiter.FirstOrDefaultAsync(x => x.Id == waiter.Id);

                if (existing == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
                db.Waiter.Remove(existing);
                await db.SaveChangesAsync();
            }
        }
Example #6
0
        public static async Task Update(Table table)
        {
            using (var db = new RestaurantDatabase())
            {
                Waiter existing = await db.Waiter.FirstOrDefaultAsync(x => x.Id == table.Id);

                if (existing == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
                existing.Waitername = table.Tablename;
                await db.SaveChangesAsync();
            }
        }
        public async Task <CategoryDTO> AddCategory(string CategoryName)
        {
            using (var db = new RestaurantDatabase()) {
                var cat = new Category()
                {
                    CategoryName = CategoryName,
                    CategoryID   = Guid.NewGuid(),
                    Items        = new List <MenuItem>(),
                };
                db.Categories.Add(cat);
                await db.SaveChangesAsync();

                return(new CategoryDTO(cat));
            }
        }
        public async Task <MenuItemDTO> AddItem(string categoryId, [FromBody] MenuItemDTO item)
        {
            using (var db = new RestaurantDatabase()) {
                var menuItem = new MenuItem()
                {
                    ItemDescription     = item.ItemDescription,
                    ItemName            = item.ItemName,
                    ItemPrice           = item.ItemPrice,
                    ItemID              = Guid.NewGuid(),
                    SpecialInstructions = item.SpecialInstructions,
                    InStock             = true,
                };
                db.MenuItems.Add(menuItem);
                await db.SaveChangesAsync();

                return(new MenuItemDTO(menuItem));
            }
        }