public DiscoveryPage()
 {
     InitializeComponent();
     viewModel = new FoodMenuViewModel();
     viewModel.LoadData();
     BindingContext = viewModel;
 }
Пример #2
0
 public CartPage(ObservableCollection <Food> selectedFood, bool isOrder = false)
 {
     InitializeComponent();
     currentList         = selectedFood;
     lsFoods.ItemsSource = currentList;
     LoadTotal();
     IsOrder   = isOrder;
     viewmodel = new FoodMenuViewModel();
 }
Пример #3
0
        public async Task <ActionResult> Create(FoodMenuViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var existed = await _db.FoodMenus.AnyAsync(x => x.MenuName == model.MenuName);

            if (existed)
            {
                ModelState.AddModelError("", "Tên thực đơn đã tồn tại hãy cung cấp tên khác");
                return(View(model));
            }
            var foodIdList = (List <string>)Session["FoodIdList"];

            if (foodIdList == null || !foodIdList.Any())
            {
                ModelState.AddModelError("", "Chưa thêm món ăn vào thực đơn");
                return(View(model));
            }
            model.FoodIdList = string.Join(";", foodIdList.ToArray());
            var menu = new FoodMenu
            {
                Id         = Guid.NewGuid(),
                MenuName   = model.MenuName,
                Price      = model.Price,
                FoodIdList = model.FoodIdList,
                Activated  = model.Activated,
                CreateTime = DateTime.Now
            };

            if (!Directory.Exists(Server.MapPath(Path)))
            {
                Directory.CreateDirectory(Server.MapPath(Path));
            }
            var avatar = Request.Files["Avatar"];

            if (avatar != null && avatar.ContentLength > 0)
            {
                if (avatar.ContentLength > 2048000)
                {
                    ModelState.AddModelError("", "Hình ảnh có dung lượng không quá 2Mb");
                    return(View(model));
                }
                var fileInfo    = new FileInfo(avatar.FileName);
                var fileExt     = fileInfo.Extension;
                var newFileName = $"{menu.Id}{fileExt}";
                avatar.SaveAs($"{Server.MapPath(Path)}/{newFileName}");
                menu.Avatar = newFileName;
            }
            _db.FoodMenus.Add(menu);
            await _db.SaveChangesAsync();

            Session["FoodIdList"] = null;
            return(RedirectToAction("index"));
        }
Пример #4
0
 public MenuPage()
 {
     InitializeComponent();
     viewModel = new FoodMenuViewModel();
     GenerateData();
     //LoadData();
     lsListCatagory.SelectionChanged += LsListCatagory_SelectionChanged;
     BindingContext = viewModel;
     // layoutTest.Children.Add(new StackLayout() { BackgroundColor = Color.Black, HeightRequest = 100 });
 }
Пример #5
0
 public PaymentPage(int total, int method)
 {
     InitializeComponent();
     Serviceviewmodel = new FoodMenuViewModel();
     viewmodel        = new PaymentModel()
     {
         Total = total,
         Type  = (method == 0 ? "Momo" : "Tiền mặt")
     };
     txbKM.Keyboard  = Keyboard.Create(KeyboardFlags.CapitalizeCharacter);
     txbTip.Keyboard = Keyboard.Numeric;
     BindingContext  = viewmodel;
 }
Пример #6
0
        public async Task <ActionResult> Edit(FoodMenuViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var menu = await _db.FoodMenus.FindAsync(model.Id);

            if (menu == null)
            {
                return(HttpNotFound());
            }
            var foodIdList = (List <string>)Session["FoodIdList"];

            if (foodIdList == null || !foodIdList.Any())
            {
                ModelState.AddModelError("", "Chưa thêm món ăn vào thực đơn");
                return(View(model));
            }
            menu.MenuName   = model.MenuName;
            menu.Price      = model.Price;
            menu.Activated  = model.Activated;
            menu.FoodIdList = string.Join(";", foodIdList.ToArray());
            var avatar = Request.Files["Avatar"];

            if (avatar != null && avatar.ContentLength > 0)
            {
                if (avatar.ContentLength > 2048000)
                {
                    ModelState.AddModelError("", "Hình ảnh có dung lượng không quá 2Mb");
                    return(View(model));
                }
                var fileInfo    = new FileInfo(avatar.FileName);
                var fileExt     = fileInfo.Extension;
                var newFileName = $"{menu.Id}{fileExt}";
                avatar.SaveAs(Server.MapPath($"{Server.MapPath(Path)}/{newFileName}"));
                menu.Avatar = newFileName;
            }
            _db.Entry(menu).State = EntityState.Modified;
            await _db.SaveChangesAsync();

            Session["FoodIdList"] = null;
            return(RedirectToAction("index"));
        }
Пример #7
0
        public async Task <ActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var menu = await _db.FoodMenus.FindAsync(id);

            if (menu == null)
            {
                return(HttpNotFound());
            }
            var model = new FoodMenuViewModel
            {
                Id         = menu.Id,
                MenuName   = menu.MenuName,
                Avatar     = menu.Avatar,
                Price      = menu.Price,
                FoodIdList = menu.FoodIdList
            };

            return(View(model));
        }
Пример #8
0
        public async Task <ActionResult> Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var menu = await _db.FoodMenus.FindAsync(id);

            if (menu == null)
            {
                return(HttpNotFound());
            }
            var model = new FoodMenuViewModel
            {
                Id        = menu.Id,
                MenuName  = menu.MenuName,
                Price     = menu.Price,
                Activated = menu.Activated,
                Avatar    = menu.Avatar
            };

            Session["FoodIdList"] = menu.FoodIdList.Split(';').ToList();
            return(View(model));
        }