Exemple #1
0
        public void Delete(T entity)
        {
            if (entity is null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            Entities.Remove(entity);
            _context.SaveChanges();
        }
Exemple #2
0
        public List <Order> DeliverOrder([FromRoute] int id)
        {
            var order = _context.Orders.Find(id);

            if (order != null)
            {
                if (order.Delivered == false)
                {
                    order.Delivered     = true;
                    order.DeliveredDate = DateTime.Now;
                    _context.SaveChanges();
                }
            }
            return(_context.Orders.ToList());
        }
Exemple #3
0
        public JsonResult SavePaymentRecord(IList <OrderNow> values)
        {
            if (values != null)
            {
                decimal amount   = GeneralModel.GetTotalAmount(values);
                var     response = ChargeCreditCard.Run(amount);
                if (response.refId != null)
                {
                    Order newOrder = new Order();
                    newOrder.userId     = Convert.ToInt32(Session["UserId"].ToString());
                    newOrder.dateTime   = DateTime.Now.ToString("HH:mm tt dd/MM/yyyy");
                    newOrder.status     = "Pending";
                    newOrder.totalPrice = amount.ToString();
                    newOrder.transId    = response.refId;

                    using (FoodOrderDbContext db = new FoodOrderDbContext())
                    {
                        db.Orders.Add(newOrder);
                        db.SaveChanges();
                    }

                    foreach (var item in values)
                    {
                        decimal itemid   = GeneralModel.GetItemID(item.Name);
                        decimal orderId  = GeneralModel.GetOrderId();
                        decimal quantity = item.count;
                        GeneralModel.SavetoItemDetials(itemid, orderId, quantity);
                        GeneralModel.UpdateQuantity(itemid, quantity);
                    }
                }
                return(Json(new { result = 1 }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new { result = 0 }, JsonRequestBehavior.AllowGet));
        }
        public void TestDb()
        {
            var context = new FoodOrderDbContext().CreateDbContext(null);

            context.WeekDays.Add(new WeekDay {
                Name = "Wd"
            });
            context.SaveChanges();
            var t = context.WeekDays.FirstOrDefault(x => x.Name == "Wd");

            Assert.Equal("Wd", t.Name);

            context.Remove(t);
            context.SaveChanges();
            var w = context.WeekDays.FirstOrDefault(x => x.Name == "Wd");

            Assert.Null(w);
        }
 public static void UpdateQuantity(decimal itemid, decimal quantity)
 {
     using (FoodOrderDbContext db = new FoodOrderDbContext())
     {
         decimal  Updatedquantity = GetUpdatedQuantity(quantity, itemid);
         FoodItem updateItem      = db.FoodItems.Find(itemid);
         updateItem.quantity = Convert.ToInt32(Updatedquantity);
         db.SaveChanges();
     }
 }
 public JsonResult AddNewCategory(string CategoryName)
 {
     using (FoodOrderDbContext db = new FoodOrderDbContext())
     {
         Category cat = new Category();
         cat.name = CategoryName;
         db.Categories.Add(cat);
         db.SaveChanges();
     }
     return(Json(new { result = true }, JsonRequestBehavior.AllowGet));
 }
 public ActionResult EditPrice(string Price, int itemId)
 {
     using (FoodOrderDbContext db = new FoodOrderDbContext())
     {
         FoodItem updateprice = db.FoodItems.Find(itemId);
         updateprice.price = Price;
         db.SaveChanges();
         return(new JsonResult {
             Data = true, JsonRequestBehavior = JsonRequestBehavior.AllowGet
         });
     }
 }
 public ActionResult DeleteItem(int id)
 {
     using (FoodOrderDbContext db = new FoodOrderDbContext())
     {
         var finddata = db.FoodItems.Find(id);
         finddata.isDeleted = true;
         db.SaveChanges();
     }
     return(new JsonResult {
         Data = true, JsonRequestBehavior = JsonRequestBehavior.AllowGet
     });
 }
        public static void SavetoItemDetials(decimal itemid, decimal orderId, decimal quantity)
        {
            using (FoodOrderDbContext db = new FoodOrderDbContext())
            {
                OrderDetail orderD = new OrderDetail();
                orderD.itemId   = itemid;
                orderD.orderId  = orderId;
                orderD.quantity = quantity.ToString();

                db.OrderDetails.Add(orderD);
                db.SaveChanges();
            }
        }
        public static void SaveRecord(SignUpModel data)
        {
            using (FoodOrderDbContext db = new FoodOrderDbContext())
            {
                User adduser = new User();
                adduser.email    = data.email;
                adduser.username = data.UserName;
                adduser.password = data.password;

                db.Users.Add(adduser);
                db.SaveChanges();
            }
        }
        public ActionResult OrderDeliver(int id)
        {
            var OrderDelivered = 0; var OrderPending = 0;

            using (FoodOrderDbContext db = new FoodOrderDbContext())
            {
                var finddata = db.Orders.Find(id);
                finddata.status = "Complete";
                db.SaveChanges();

                OrderDelivered = db.Orders.Where(s => s.status == "Complete").Count();
                OrderPending   = db.Orders.Where(s => s.status != "Complete").Count();
            }
            return(Json(new { OrderDeliver = OrderDelivered, OrderPending = OrderPending, Data = true, JsonRequestBehavior = JsonRequestBehavior.AllowGet }));
        }
        public JsonResult SaveNewFoodItem(ItemModel ItemData)
        {
            using (FoodOrderDbContext db = new FoodOrderDbContext())
            {
                if (ItemData.ImageUpload != null)
                {
                    UploadSelectedImage(ItemData);
                }

                FoodItem addnewItem = new FoodItem();
                addnewItem.catId       = ItemData.catId;
                addnewItem.name        = ItemData.name;
                addnewItem.description = ItemData.description;
                addnewItem.price       = ItemData.price;
                addnewItem.quantity    = ItemData.quantity;
                addnewItem.image       = ItemData.image;
                addnewItem.isEnabled   = true;
                db.FoodItems.Add(addnewItem);
                db.SaveChanges();
                return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult EnableDisable(int id)
        {
            bool status = false;

            using (FoodOrderDbContext db = new FoodOrderDbContext())
            {
                var finddata = db.FoodItems.Find(id);
                if (finddata.isEnabled == true)
                {
                    finddata.isEnabled = false;
                }
                else
                {
                    finddata.isEnabled = true;
                    status             = true;
                }

                db.SaveChanges();
            }
            return(new JsonResult {
                Data = status, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #14
0
        public static void Initialize(FoodOrderDbContext context)
        {
            IList <Category> defaultCategories = new List <Category>
            {
                new Category()
                {
                    Name  = "Levesek",
                    Items = new List <DrinkOrDish>()
                    {
                        new DrinkOrDish()
                        {
                            Name        = "Gulyásleves",
                            Description = "Soup made with beef",
                            Price       = 10001,
                            Spicy       = true,
                            Vegetarian  = false,
                            Fame        = 0
                        },
                        new DrinkOrDish()
                        {
                            Name        = "Brokkoli krémleves",
                            Description = "Soup made with broccoli",
                            Price       = 500,
                            Spicy       = false,
                            Vegetarian  = true,
                            Fame        = 0
                        },
                        new DrinkOrDish()
                        {
                            Name        = "Jókai bableves",
                            Description = "Soup made with bean",
                            Price       = 750,
                            Spicy       = false,
                            Vegetarian  = false,
                            Fame        = 0
                        }
                    }
                },
                new Category()
                {
                    Name  = "Főételek",
                    Items = new List <DrinkOrDish>()
                    {
                        new DrinkOrDish()
                        {
                            Name        = "Hortobágyi palacsinta",
                            Description = "Pancakes with meat",
                            Price       = 1250,
                            Spicy       = false,
                            Vegetarian  = false,
                            Fame        = 0
                        },
                        new DrinkOrDish()
                        {
                            Name        = "Szilvás gombóc",
                            Description = "Sweet pastry with plum",
                            Price       = 1000,
                            Spicy       = false,
                            Vegetarian  = true,
                            Fame        = 0
                        },
                        new DrinkOrDish()
                        {
                            Name        = "Spenótfőzelék",
                            Description = "Spinach with eggs",
                            Price       = 800,
                            Spicy       = false,
                            Vegetarian  = true,
                            Fame        = 0
                        }
                    }
                },
                new Category()
                {
                    Name  = "Pizzák",
                    Items = new List <DrinkOrDish>()
                    {
                        new DrinkOrDish()
                        {
                            Name        = "Mozzarella caprese",
                            Description = "Pizza with mozzarella",
                            Price       = 1250,
                            Spicy       = false,
                            Vegetarian  = true,
                            Fame        = 0
                        },
                        new DrinkOrDish()
                        {
                            Name        = "Húsimádó",
                            Description = "Pizza with 4 type of meat",
                            Price       = 1000,
                            Spicy       = false,
                            Vegetarian  = false,
                            Fame        = 0
                        },
                        new DrinkOrDish()
                        {
                            Name        = "Csípős SonGoKu",
                            Description = "Spicy pizza with corn and mushroom",
                            Price       = 800,
                            Spicy       = true,
                            Vegetarian  = false,
                            Fame        = 0
                        }
                    }
                },
                new Category()
                {
                    Name  = "Italok",
                    Items = new List <DrinkOrDish>()
                    {
                        new DrinkOrDish()
                        {
                            Name        = "Jalapeño Margarita",
                            Description = "A 'hot' beverage",
                            Price       = 1250,
                            Spicy       = true,
                            Vegetarian  = true,
                            Fame        = 0
                        },
                        new DrinkOrDish()
                        {
                            Name        = "Blonde Manhattan",
                            Description = "Taliesin's favourite",
                            Price       = 1000,
                            Spicy       = false,
                            Vegetarian  = true,
                            Fame        = 0
                        },
                        new DrinkOrDish()
                        {
                            Name        = "Fanta",
                            Description = "The old fashioned non-alcoholic drink",
                            Price       = 350,
                            Spicy       = false,
                            Vegetarian  = true,
                            Fame        = 0
                        }
                    }
                }
            };

            IList <Order> defaultOrders = new List <Order>
            {
                new Order()
                {
                    Address        = "Teszt utca",
                    Delivered      = false,
                    DrinksOrDishes = "2 2 1",
                    Name           = "Teszt Név",
                    Phone          = "Teszt telefon",
                    Sum            = 2000,
                    OrderedDate    = DateTime.Now
                },
                new Order()
                {
                    Address        = "Teszt2 utca",
                    Delivered      = false,
                    DrinksOrDishes = "2 2 1",
                    Name           = "Teszt2 Név",
                    Phone          = "Teszt2 telefon",
                    Sum            = 2000,
                    OrderedDate    = DateTime.Now
                }
            };

            foreach (var list in defaultCategories)
            {
                context.Categories.Add(list);
            }
            foreach (var list in defaultOrders)
            {
                context.Orders.Add(list);
            }

            context.SaveChanges();
        }
Exemple #15
0
 public void FameInc(int id)
 {
     _context.DrinksOrDishes.Find(id).Fame++;
     _context.SaveChanges();
 }