Esempio n. 1
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            // Validations
            if (string.IsNullOrEmpty(txtItemName.Text) ||
                string.IsNullOrEmpty(txtItemPrice.Text) ||
                cbxItemCategory.SelectedIndex < 0)
            {
                MessageBox.Show("Məlumatları tam doldurun");
                return;
            }


            Models.MenuItem mItem = new Models.MenuItem();
            mItem.Name  = txtItemName.Text;
            mItem.Price = Convert.ToDouble(txtItemPrice.Text);

            string       catName      = cbxItemCategory.SelectedItem.ToString();
            MenuCategory menuCategory = _context.Categories.FirstOrDefault(c => c.Name == catName);


            mItem.CategoryId = menuCategory.Id;

            _context.MenuItems.Add(mItem);
            _context.SaveChanges();

            FillMenuItems();
        }
        public ActionResult Create([Bind(Include = "MenuId,Name,MenuType,CompanyId")] Menu menu)
        {
            if (ModelState.IsValid)
            {
                db.Menus.Add(menu);
                db.SaveChanges();
                return(RedirectToAction("Details", "Companies", new { Id = menu.CompanyId }));
            }

            ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", menu.CompanyId);
            return(View(menu));
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "MenuProductId,ProductId,cookingTime,MenuId,ProductPrice")] MenuProduct menuProduct)
        {
            if (ModelState.IsValid)
            {
                db.MenuProducts.Add(menuProduct);
                db.SaveChanges();
                return(RedirectToAction("Details", "Menus", new { Id = menuProduct.MenuId }));
            }

            ViewBag.MenuId    = new SelectList(db.Menus, "MenuId", "Name", menuProduct.MenuId);
            ViewBag.ProductId = new SelectList(db.Products, "ProductId", "ProductName", menuProduct.ProductId);
            return(View(menuProduct));
        }
Esempio n. 4
0
 public EntityAction SaveChanges()
 {
     if (db.SaveChanges() > 0)
     {
         return(EntityAction.Success);
     }
     return(EntityAction.Exception);
 }
Esempio n. 5
0
 public static void DeleteFood(int id)
 {
     using (var ctx = new MenuDbContext())
     {
         var toRemove = ctx.Food.FirstOrDefault(f => f.Id == id);
         ctx.Food.Remove(toRemove);
         ctx.SaveChanges();
     }
 }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "ProductId,ProductName")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                try
                {
                    db.SaveChanges();
                }catch (Exception e)
                {
                    ModelState.AddModelError("Same product name", e);
                    return(View(product));
                }
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Esempio n. 7
0
        public static Order AddOrder(string json, int id)
        {
            var   order      = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(json);
            var   duplicates = new List <string>();
            Order realOrder;

            using (var ctx = new MenuDbContext())
            {
                var user = ctx.User.Where(u => u.Id == id).First();

                realOrder = new Order
                {
                    OrderedAt  = DateTime.Now,
                    User       = user,
                    UserId     = id,
                    TotalPrice = Decimal.Parse(order["totalprice"][0])
                };

                realOrder.OrderFood = new List <OrderFood>();

                ctx.Order.Add(realOrder);

                ctx.SaveChanges();

                foreach (string foodId in order["food"])
                {
                    if (duplicates.Contains(foodId))
                    {
                        continue;
                    }

                    realOrder.OrderFood.Add(new OrderFood {
                        Order = realOrder, Food = ctx.Food.Find(Int32.Parse(foodId)), FoodCount = order["food"].Duplicates(foodId)
                    });
                    duplicates.Add(foodId);
                }

                ctx.SaveChanges();
            }

            return(realOrder);
        }
Esempio n. 8
0
 public static Category AddCategory(Category c)
 {
     using (var ctx = new MenuDbContext())
     {
         //Test if parentId exists
         ctx.Category.Where(cat => cat.Id == c.ParentId).First();
         ctx.Category.Add(c);
         ctx.SaveChanges();
     }
     return(c);
 }
Esempio n. 9
0
 public static void DeleteCategory(int id)
 {
     using (var ctx = new MenuDbContext())
     {
         var toRemove = ctx.Category.FirstOrDefault(c => c.Id == id);
         ctx.Category.Remove(toRemove);
         var toRemoveChild = ctx.Category.Where(c => c.ParentId == id);
         ctx.Category.RemoveRange(toRemoveChild);
         ctx.SaveChanges();
     }
 }
Esempio n. 10
0
        public static Order AddOrder(string json)
        {
            var order = JsonConvert.DeserializeObject <Order>(json);

            using (var ctx = new MenuDbContext())
            {
                ctx.Order.Add(order);
                ctx.SaveChanges();
            }
            return(order);
        }
Esempio n. 11
0
        private void btnApproveOrder_Click(object sender, EventArgs e)
        {
            Order order = new Order()
            {
                OrderItems = orderItems,
                CreatedAt  = DateTime.Now
            };

            _context.Orders.Add(order);
            _context.SaveChanges();
        }
        // GET: Orders/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null || id == 0)
            {
                var dbOrder = db.Orders.Where(o => o.OrderStatus == OrderStatusEnum.PENDING).FirstOrDefault();
                if (dbOrder == null)
                {
                    dbOrder = db.Orders.Create();
                    dbOrder.ApplicationUserId = User.Identity.GetUserId();
                    dbOrder.orderDate         = DateTime.Now;
                    dbOrder.OrderProducts     = new List <MenuProduct>();
                    dbOrder.OrderStatus       = OrderStatusEnum.PENDING;
                    db.Orders.Add(dbOrder);
                    db.SaveChanges();
                }
                id = dbOrder.OrderId;
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Order order = db.Orders.Where(o => o.OrderId == id).Include(o => o.OrderProducts)
                          .Include("OrderProducts.Product")
                          .Include("OrderProducts.Menu.Company").FirstOrDefault();

            if (order == null)
            {
                return(HttpNotFound());
            }
            return(View(order));
        }
        private void BtnAddCategory_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtCategoryName.Text))
            {
                MessageBox.Show("Kateqoriya adını daxil edin!");
                return;
            }

            if (txtCategoryName.Text.Length < 2)
            {
                MessageBox.Show("Kateqoriya adı minimum 2 simvol olmalidir");
                return;
            }

            MenuCategory category = new MenuCategory();

            category.Name = txtCategoryName.Text;

            _context.Categories.Add(category);
            _context.SaveChanges();

            MessageBox.Show($"{category.Name} əlavə olundu");
            FillCategories();
        }
        public ActionResult Create([Bind(Include = "CompanyId,Name,Description,CompanyType,ImageUpload,Cost")] Company company)
        {
            if (company.ImageUpload == null || company.ImageUpload.ContentLength == 0)
            {
                ModelState.AddModelError("ImageUpload", "This field is required");
            }
            else if (!validImageTypes.Contains(company.ImageUpload.ContentType))
            {
                ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
            }
            if (ModelState.IsValid)
            {
                if (company.ImageUpload != null && company.ImageUpload.ContentLength > 0)
                {
                    var uploadDir = "~/Content/uploads";
                    var logoName  = Path.ChangeExtension(Guid.NewGuid().ToString(), Path.GetExtension(company.ImageUpload.FileName));
                    var imagePath = Path.Combine(Server.MapPath(uploadDir), logoName);
                    var imageUrl  = Path.Combine(uploadDir, logoName);
                    company.ImageUpload.SaveAs(imagePath);
                    company.Logo = imageUrl;
                }
                db.Companies.Add(company);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("Same company name", e);
                    return(View(company));
                }
                return(RedirectToAction("Index"));
            }

            return(View(company));
        }
Esempio n. 15
0
 public static Food AddFood(Food food)
 {
     using (var ctx = new MenuDbContext())
     {
         ctx.Category.Where(c => c.Id == food.CategoryId).First();
         food.FoodAllergen = new HashSet <FoodAllergen>();
         foreach (int AllergenId in food.Allergenes)
         {
             var allergen = ctx.Allergens.Single(a => a.Id == AllergenId);
             food.FoodAllergen.Add(new FoodAllergen(food, allergen));
         }
         ctx.Food.Add(food);
         ctx.SaveChanges();
     }
     return(food);
 }
Esempio n. 16
0
        public static Food AddFood(string jsonObject)
        {
            var food = JsonConvert.DeserializeObject <Food>(jsonObject);

            using (var ctx = new MenuDbContext())
            {
                food.FoodAllergen = new HashSet <FoodAllergen>();
                foreach (int AllergenId in food.Allergenes)
                {
                    var allergen = ctx.Allergens.Single(a => a.Id == AllergenId);
                    food.FoodAllergen.Add(new FoodAllergen(food, allergen));
                }
                ctx.Food.Add(food);
                ctx.SaveChanges();
            }

            return(food);
        }
Esempio n. 17
0
        public static User AddUser(string json)
        {
            var  dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
            User user = new User(Token.Decrypt(dict["email"]), Token.Decrypt(dict["password"]));

            try
            {
                using (var ctx = new MenuDbContext())
                {
                    ctx.User.Add(user);
                    ctx.SaveChanges();
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(user);
        }
Esempio n. 18
0
        public static Category AddCategory(string postText)
        {
            var      categoryText = JsonConvert.DeserializeObject <Dictionary <string, string> >(postText);
            Category newCategory;

            //var category = JsonConvert.DeserializeObject<Category>(postText);
            using (var ctx = new MenuDbContext())
            {
                if (categoryText["ParentName"].Equals("Vybrat...", StringComparison.CurrentCultureIgnoreCase))
                {
                    newCategory = new Category(categoryText["Name"], null);
                }
                else
                {
                    var parent = (from c in ctx.Category.ToList() where c.Name == categoryText["ParentName"] select c).First();
                    newCategory = new Category(categoryText["Name"], parent.Id);
                }
                ctx.Category.Add(newCategory);
                ctx.SaveChanges();
            }
            return(newCategory);
        }
Esempio n. 19
0
 //Přidá objednávku
 public void AddOrder(string[] orderArr, int uid, string totalPrice)
 {
     try
     {
         var food = new List <Food>();
         //Najde uživatel, který zadal objednávnku
         User user = this.database.Users.Find(uid);
         foreach (string foodId in orderArr)
         {
             //Pro každé id jídla z pole objednávku se najde entita a přidá do listu
             food.Add(database.Menu.Find(Int32.Parse(foodId)));
         }
         //Vytvoří se nová objednávka, který se spojí s uživatelem a objednaným jídlem
         var order = new Order(user, food.ToArray());
         //Také cena se samozřejmě uloží
         order.TotalPrice = Decimal.Parse(totalPrice);
         //A přídá do DB
         database.Orders.Add(order);
         //Duplikáty jídel
         var duplicates = new List <string>();
         //Ty se najdou a uloží jen pro elegantnější zobraní počtu jídla v objednávce např. 5x Tofu
         foreach (string foodId in orderArr)
         {
             if (duplicates.Contains(foodId))
             {
                 continue;
             }
             database.OrderFood.Add(new OrderFood {
                 Order = order, Food = database.Menu.Find(Int32.Parse(foodId)), foodCount = orderArr.Duplicates(foodId)
             });
             duplicates.Add(foodId);
         }
         database.SaveChanges();
         //A objednávka se zobrazí v hlavním okně
         this.win.PushToNodeView(order.Id, database.OrderFood.Where(s => s.OrderId == order.Id).AsEnumerable(), order.TotalPrice.ToString(), order.OrderedAt.ToString("HH:mm:ss"));
     }
     catch (Exception ex) { Console.WriteLine(ex.ToString()); }
 }
Esempio n. 20
0
        public ActionResult Index()
        {
            var _db = new MenuDbContext();

            _db.Foods.Add(new Food
            {
                Name       = "Tariaki",
                Vegetarian = false,
                Calories   = 100,
                FoodType   = FoodTypes.Chicken,
                Grammage   = 350,
                Price      = 3.50M,
            });

            _db.Drinks.Add(new Drink
            {
                Name      = "Coca-Cola",
                Calories  = 250,
                Alcoholic = false,
                Grammage  = 250,
                Price     = 1.50M,
                DrinkType = DrinkTypes.Other,
            });

            //_db.Purchases.Add(new Purchase()
            //{
            //    DateOfPurchase = DateTime.Now,
            //    PurchasedDrink = new List<PurchasedDrink>
            //    {
            //        new PurchasedDrink
            //        {
            //            DrinkID = 1,
            //        }
            //    },
            //    PurchasedFood = new List<PurchasedFood>
            //    {
            //            new PurchasedFood
            //            {
            //                FoodID = 1
            //            },
            //            new PurchasedFood
            //            {
            //                FoodID = 2
            //            }
            //    },
            //});

            //var currPur = _db.Purchases.FirstOrDefault(x => x.PurchaseID == 2);
            //var a = currPur.PurchasedFood.Select(x => x.FoodID);
            //var b = currPur.PurchasedDrink.Select(x => x.DrinkID);

            //decimal sum = 0;

            //sum += _db.Foods.Where(x => a.Contains(x.FoodID)).Select(x => x.Price).Sum();
            //sum += _db.Drinks.Where(x => b.Contains(x.DrinkID)).Select(x => x.Price).Sum();

            //currPur.SumOfThePurchase = sum;

            _db.SaveChanges();
            return(View());
        }
        public IActionResult Get()
        {
            var options = new DbContextOptionsBuilder <MenuDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            MenuDbContext menuDbContext = new MenuDbContext(options);

            if (!menuDbContext.Menus.Any())
            {
                menuDbContext.Menus.Add(new Menu()
                {
                    DisplayName = "First Menu",
                    ChildMenus  = new List <Menu>()
                    {
                        new Menu()
                        {
                            DisplayName = "First Content", Route = "FirstContent"
                        },
                        new Menu()
                        {
                            DisplayName = "Second Content", Route = "SecondContent"
                        },
                        new Menu()
                        {
                            DisplayName = "Second Menu",
                            ChildMenus  = new List <Menu>()
                            {
                                new Menu()
                                {
                                    DisplayName = "Third Menu",
                                    ChildMenus  = new List <Menu>()
                                    {
                                        new Menu()
                                        {
                                            DisplayName = "7th Content", Route = "SeventhContent"
                                        },
                                    }
                                },
                                new Menu()
                                {
                                    DisplayName = "Third Content", Route = "ThirdContent"
                                },
                            },
                        },
                    }
                });

                menuDbContext.Menus.Add(new Menu()
                {
                    DisplayName = "Forth Content", Route = "ForthContent"
                });

                menuDbContext.Menus.Add(new Menu()
                {
                    DisplayName = "Forth Menu",
                    ChildMenus  = new List <Menu>()
                    {
                        new Menu()
                        {
                            DisplayName = "Fifth Content", Route = "FifthContent"
                        },
                        new Menu()
                        {
                            DisplayName = "Sixth Content", Route = "SixthContent"
                        },
                    }
                });

                menuDbContext.SaveChanges();
            }

            var menus    = menuDbContext.Menus.Where(x => !x.MainMenuId.HasValue).ToList();
            var allMenus = menuDbContext.Menus.ToList();

            return(Ok(menus));
        }
Esempio n. 22
0
 public void Save()
 {
     _db.SaveChanges();
 }
Esempio n. 23
0
        static void Main(string[] args)
        {
            string  add = "";
            Options opt;

            try
            {
                opt        = CliParser.Parse <Options>(args);
                ConnString = string.Format("server={0};port=3306;database={1};uid={2};password={3};charset=utf8;persistsecurityinfo=True", opt.Host, opt.Database, opt.User, opt.Password);
                add        = opt.Address;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                Environment.Exit(-1);
            }

            try
            {
                using (var ctx = new MenuDbContext())
                {
                    ctx.Database.EnsureCreated();
                    var result = ctx.Allergens.FirstOrDefault();

                    if (result == null)
                    {
                        foreach (string allergen in ctx.allergenValues)
                        {
                            ctx.Allergens.Add(new Allergen(allergen));
                        }
                        ctx.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                Environment.Exit(-1);
            }

            //Webserver handles htmls, css and basically everything we see on the web
            try
            {
                var server = new Http.WebServer(add);
            }catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                Environment.Exit(-1);
            }

            string command = "";

            do
            {
                Console.Write("webserver> ");
                command = Console.ReadLine();
                ResolveCommand(command);
            } while (!command.Equals("stop", StringComparison.CurrentCultureIgnoreCase));
        }
Esempio n. 24
0
        public void InitDbDefault(MenuDbContext db)
        {
            var usersForAdd = new List <User>()
            {
                new User()
                {
                    Email        = "*****@*****.**",
                    Login        = "******",
                    Name         = "test_Email_1",
                    PasswordHash = "pas_hash_1",
                },
                new User()
                {
                    Email        = "*****@*****.**",
                    Login        = "******",
                    Name         = "test_Email_2",
                    PasswordHash = "pas_hash_2",
                },
            };

            db.Users.AddRange(usersForAdd);
            db.SaveChanges();

            var articlesForAdd = new List <Article>()
            {
                new Article()
                {
                    Title    = "article_title_1",
                    Body     = "article_body_1",
                    Followed = false,
                    UserId   = usersForAdd[0].Id,
                },
                new Article()
                {
                    Title    = "article_title_2",
                    Body     = "article_body_2",
                    Followed = false,
                    UserId   = usersForAdd[1].Id,
                },
            };

            db.Articles.AddRange(articlesForAdd);
            db.SaveChanges();
            var imagesForAdd = new List <CustomImage>()
            {
                new CustomImage()
                {
                    Path      = "test_path_1",
                    ArticleId = articlesForAdd[0].Id,
                },
                new CustomImage()
                {
                    Path      = "test_path_2",
                    ArticleId = articlesForAdd[0].Id,
                },
            };

            db.Images.AddRange(imagesForAdd);
            db.SaveChanges();


            //db.SaveChanges();
        }