Example #1
0
        public async Task <IActionResult> Create(adm.PizzaViewModel pizzaVM)
        {
            long          size       = pizzaVM.UploadImage?.Length ?? 0;
            var           filename   = String.Empty;
            IActionResult returnPage = null;

            if (ModelState.IsValid)
            {
                if (size > 0)
                {
                    filename = await CreateFileOnServerAsync(pizzaVM.UploadImage);
                }

                var pizza = new Pizza()
                {
                    Description = pizzaVM.Description,
                    Image       = filename,
                    PriceHT     = pizzaVM.PriceHT,
                    Title       = pizzaVM.Title
                };

                //TODO:Save Pizza in db
                _pizzaRepository.Create(pizza);
                //_staticRepository.Pizzas.Add(pizza);
            }
            else
            {
                ModelState.AddModelError("Error Model", "Les données saisies ne sont pas valides, veuillez vérifier celles-ci");
                returnPage = View(pizzaVM);
            }

            if (pizzaVM.AddNewPizza)
            {
                returnPage = RedirectToAction("Create");
            }
            else
            {
                returnPage = RedirectToAction("Index", "Pizza", new { area = "Admin" });
            }


            return(returnPage);
        }
Example #2
0
        public PartialViewResult Detail(int id)
        {
            //var pizza = this.Pizzas.Find(p => p.IdPizza == id);
            //var pizzaVM = new PizzaViewModel()
            //{
            //    Pizza = pizza
            //};
            var pizzaVM = new adm.PizzaViewModel();

            var pizza = this._pizzaRepository.ReadById(id);

            pizzaVM.IdPizza     = pizza.IdPizza;
            pizzaVM.Description = pizza.Description;
            pizzaVM.Image       = pizza.Image;
            pizzaVM.PriceHT     = pizza.PriceHT;
            pizzaVM.Title       = pizza.Title;
            pizzaVM.IdPizza     = pizza.IdPizza;


            return(PartialView("DetailPartial", pizzaVM));
        }
Example #3
0
        public virtual void AddItem(adm.PizzaViewModel pizzaVM, int quantity = 1)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            CartLine line = lines.Where(l => l.PizzaVM.IDPizza == pizzaVM.IDPizza).FirstOrDefault(); // = new CartLine();

            //CartLine line2 = lines.FirstOrDefault(l => l.PizzaVM.IDPizza == pizzaVM.IDPizza);
            //CartLine line3 = lines.Find(l => l.PizzaVM.IDPizza == pizzaVM.IDPizza);
            //CartLine line4 = lines.Single(l => l.PizzaVM.IDPizza == pizzaVM.IDPizza);
            sw.Stop();
            Debug.WriteLine(sw.ElapsedMilliseconds);

            if (line == null)
            {
                lines.Add(new CartLine {
                    PizzaVM = pizzaVM, Quantity = quantity
                });
            }
            else
            {
                line.Quantity += quantity;
            }
        }
Example #4
0
 public void RemoveLine(adm.PizzaViewModel pizzaVM)
 {
     lines.RemoveAll(l => l.PizzaVM.IDPizza == pizzaVM.IDPizza);
 }