Beispiel #1
0
        public static bool RegisterUser(ModelLibrary.Customer mCus, string passwordHashed)
        {
            var customer = ConvertCustomerToDatabase(mCus);

            if (customer == null)
            {
                return(false);
            }

            var db = new JustFeastDbDataContext();

            if (db.Customers.Any(x => x.email.Equals(customer.email)))
            {
                return(false);
            }

            db.Customers.InsertOnSubmit(customer);
            db.SubmitChanges();

            db.Users.InsertOnSubmit(new DatabaseAccessLibrary.User
            {
                customerId = db.Customers.FirstOrDefault(x => x.email == customer.email).id,
                password   = passwordHashed
            });
            db.SubmitChanges();
            return(true);
        }
Beispiel #2
0
        public void CreateRestaurantCategory(RestaurantCategory res)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();

            db.ResCats.InsertOnSubmit(RestaurantCtrl.ConvertRestaurantCategoryToDatabase(res));
            db.SubmitChanges();
        }
Beispiel #3
0
        public void DeleteRestaurantCategory(int id)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();

            db.ResCats.DeleteOnSubmit(db.ResCats.First(x => x.id == id));
            db.SubmitChanges();
        }
Beispiel #4
0
        public void DeleteOrder(int id)
        {
            var db = new JustFeastDbDataContext();

            db.Orders.DeleteOnSubmit(db.Orders.FirstOrDefault(x => x.id == id));
            db.SubmitChanges();
        }
        public void AddItemCat(ItemCat itemCat)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();

            db.ItemCats.InsertOnSubmit(itemCat);
            db.SubmitChanges();
        }
        public void AddPrice(Price price)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();

            db.Prices.InsertOnSubmit(price);
            db.SubmitChanges();
        }
Beispiel #7
0
        public void CreateOrder(Order order)
        {
            var db = new JustFeastDbDataContext();

            db.Orders.InsertOnSubmit(order);
            db.SubmitChanges();
        }
Beispiel #8
0
        public void DeleteRestaurant(ModelLibrary.Restaurant restaurant)
        {
            var db = new JustFeastDbDataContext();

            db.Restaurants.DeleteOnSubmit(RestaurantCtrl.ConvertRestaurantToDatabase(restaurant));
            db.SubmitChanges();
        }
Beispiel #9
0
        public void AddItemToOrder(int orderId, int itemId, int resId)
        {
            var ordC = new OrderCtrl();
            var db   = new JustFeastDbDataContext();
            var item = db.Items.SingleOrDefault(i => i.id == itemId);

            if (orderId == 0)
            {
                orderId = ordC.GetLastOrderIdentity() + 1;
                var order = new DatabaseAccessLibrary.Order
                {
                    id           = orderId,
                    restaurantId = resId
                };
                db.Orders.InsertOnSubmit(order);
            }
            var exists = db.OrderLineItems.SingleOrDefault(i => i.itemId == itemId && i.orderId == orderId);

            if (exists != null)
            {
                exists.quantity++;
            }
            else if (item != null)
            {
                var oli = new DatabaseAccessLibrary.OrderLineItem
                {
                    orderId  = orderId,
                    itemId   = item.id,
                    quantity = 1
                };
                db.OrderLineItems.InsertOnSubmit(oli);
            }
            db.SubmitChanges();
        }
Beispiel #10
0
        public void CreateOrder(ModelLibrary.Order order)
        {
            var db = new JustFeastDbDataContext();

            db.Orders.InsertOnSubmit(new OrderCtrl().ConvertOrder(order));
            db.SubmitChanges();
        }
        public void DeleteOrderLineItem(int itemId)
        {
            var db  = new JustFeastDbDataContext();
            var oli = db.OrderLineItems.Where(x => x.itemId == itemId);

            db.OrderLineItems.DeleteAllOnSubmit(oli);
            db.SubmitChanges();
        }
Beispiel #12
0
        public void UpdateRestaurantCategory(RestaurantCategory res)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();
            var nres = db.ResCats.First(x => x.id == res.Id);

            nres.name = res.Name;
            db.SubmitChanges();
        }
Beispiel #13
0
        public void UpdateOrder(ModelLibrary.Order order)
        {
            var db      = new JustFeastDbDataContext();
            var dbOrder = db.Orders.FirstOrDefault(x => x.id == Convert.ToInt32(order.OrderId));

            dbOrder.accepted = order.Accepted;
            db.SubmitChanges();
        }
Beispiel #14
0
        public void AddItem(Item item)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();

            db.Items.InsertOnSubmit(item);
            db.SubmitChanges();

            int id = item.id;
        }
        public void UpdatePrice(Price price)
        {
            var db   = new JustFeastDbDataContext();
            var pric = db.Prices.FirstOrDefault(x => x.itemId == price.itemId);

            pric.price1 = price.price1;

            db.SubmitChanges();
        }
Beispiel #16
0
        public void UpdateMenu(Menu beforeMenu, Menu afterMenu)
        {
            var db     = new JustFeastDbDataContext();
            var dbMenu = db.Menus.SingleOrDefault(t => t.id == beforeMenu.id && t.id == afterMenu.id);

            dbMenu.restaurantId = afterMenu.restaurantId;
            dbMenu.name         = afterMenu.name;
            dbMenu.active       = afterMenu.active;
            db.SubmitChanges();
        }
        public void ReserveSingleTable(int tableId, int orderId)
        {
            var db = new JustFeastDbDataContext();

            db.ReservedTables.InsertOnSubmit(new ReservedTable
            {
                orderId = orderId, tableId = tableId
            });
            db.SubmitChanges();
        }
Beispiel #18
0
        public int AddOrder(Order order)
        {
            var db = new JustFeastDbDataContext();

            db.Orders.InsertOnSubmit(order);
            db.OrderLineItems.InsertAllOnSubmit(order.OrderLineItems);
            db.SubmitChanges();

            return(order.id);
        }
        public void AddTable(ResTable resTable)
        {
            var db = new JustFeastDbDataContext();

            if (db.ResTables.FirstOrDefault(t => (t.restaurantId == resTable.restaurantId)) != null)
            {
                db.ResTables.InsertOnSubmit(resTable);
                db.SubmitChanges();
            }
        }
Beispiel #20
0
        public void AddMenu(Menu menu)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();

            if (db.Menus.Any(t => !(t.restaurantId == menu.restaurantId && t.active == menu.active && t.active == true)))
            {
                db.Menus.InsertOnSubmit(menu);
            }
            db.SubmitChanges();
        }
        public void UpdateItemCat(ItemCat beforeItemCat, ItemCat afterItemCat)
        {
            var db        = new JustFeastDbDataContext();
            var dbItemCat = db.ItemCats.SingleOrDefault(t => t.id == beforeItemCat.id && beforeItemCat.id == afterItemCat.id);

            dbItemCat.id   = afterItemCat.id;
            dbItemCat.name = afterItemCat.name;


            db.SubmitChanges();
        }
Beispiel #22
0
        public void DeleteMenu(int menuId)
        {
            var db = new JustFeastDbDataContext();

            DatabaseAccessLibrary.Menu dbMenu = db.Menus.First(t => t.id == menuId);
            if (dbMenu != null)
            {
                db.Menus.DeleteOnSubmit(db.Menus.First(t => t.id == menuId));
                db.SubmitChanges();
            }
        }
        public void DeletePricesByItemId(int itemId)
        {
            var db      = new JustFeastDbDataContext();
            var dbPrice = db.Prices.Where(t => t.itemId == itemId);

            if (dbPrice != null)
            {
                db.Prices.DeleteAllOnSubmit(dbPrice);
                db.SubmitChanges();
            }
        }
Beispiel #24
0
        public void DeleteItem(int itemId)
        {
            var db = new JustFeastDbDataContext();

            DatabaseAccessLibrary.Item dbItem = db.Items.First(t => t.id == itemId);
            if (dbItem != null)
            {
                db.Items.DeleteOnSubmit(dbItem);
                db.SubmitChanges();
            }
        }
        public void DeleteItemCat(int itemCatId)
        {
            var db    = new JustFeastDbDataContext();
            var check = db.ItemCats.SingleOrDefault(t => t.id == itemCatId);

            if (check != null)
            {
                db.ItemCats.DeleteOnSubmit(db.ItemCats.First(t => t.id == itemCatId));
                db.SubmitChanges();
            }
        }
 public void ReserveTables(IEnumerable <ResTable> reserveTables, int orderId)
 {
     foreach (var table in reserveTables)
     {
         var reservedTable = new ReservedTable();
         reservedTable.orderId = orderId;
         reservedTable.tableId = table.id;
         db.ReservedTables.InsertOnSubmit(reservedTable);
     }
     db.SubmitChanges();
 }
Beispiel #27
0
        public void UpdateItem(Item updatedItem)
        {
            var db     = new JustFeastDbDataContext();
            var dbItem = db.Items.First(t => t.id == updatedItem.id);

            dbItem.menuId      = updatedItem.menuId;
            dbItem.name        = updatedItem.name;
            dbItem.description = updatedItem.description;
            dbItem.itemCatId   = updatedItem.itemCatId;

            db.SubmitChanges();
        }
Beispiel #28
0
        public void CreateRestaurant(ModelLibrary.Restaurant restaurant)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();
            var res = RestaurantCtrl.ConvertRestaurantToDatabase(restaurant);

            if (restaurant.Category != null)
            {
                res.ResCat = db.ResCats.FirstOrDefault(x => x.id == restaurant.Category.Id);
            }
            db.Restaurants.InsertOnSubmit(res);
            db.SubmitChanges();
        }
        public void DeleteItemById(int orderId, int itemId)
        {
            var db       = new JustFeastDbDataContext();
            var lineitem = db.OrderLineItems.FirstOrDefault(x => x.orderId == orderId && x.itemId == itemId);

            if (lineitem.quantity > 1)
            {
                lineitem.quantity--;
            }
            else
            {
                db.OrderLineItems.DeleteOnSubmit(lineitem);
            }
            db.SubmitChanges();
        }
Beispiel #30
0
        public void UpdateOrder(Order order)
        {
            var db  = new JustFeastDbDataContext();
            var ord = db.Orders.SingleOrDefault(o => o.id == order.id);

            if (ord != null)
            {
                ord.OrderLineItems = order.OrderLineItems;
                ord.restaurantId   = order.restaurantId;
                ord.accepted       = order.accepted;
                ord.dateTime       = order.dateTime;
                ord.reservation    = order.reservation;
                ord.noSeats        = order.noSeats;
                db.SubmitChanges();
            }
        }