public JsonResult AddToCart([FromBody] TblPizza pizza)
        {
            var foodOrder = _ctx.TblPizza.FirstOrDefault(x => x.PizzaId == pizza.PizzaId);

            foodOrder.Price      = pizza.Price;
            foodOrder.CategoryId = pizza.CategoryId;

            List <TblPizza> FoodList;

            if (HttpContext.Session.GetString("Varukorg") == null)
            {
                FoodList = new List <TblPizza>();
            }

            else
            {
                var value = (HttpContext.Session.GetString("Varukorg"));
                FoodList = JsonConvert.DeserializeObject <List <TblPizza> >(value);
            }

            FoodList.Add(foodOrder);

            var tempo = JsonConvert.SerializeObject(FoodList);

            HttpContext.Session.SetString("Varukorg", tempo);

            return(Json(new { result = "Success" }));
        }
Пример #2
0
        public JsonResult RemovePizza([FromBody] TblPizza pizza)
        {
            if (ModelState.IsValid)
            {
                var delete = _ctx.TblPizza.FirstOrDefault(x => x.PizzaId == pizza.PizzaId);

                _ctx.TblPizza.Remove(delete);
                _ctx.SaveChanges();
                return(Json(new { result = "Success" }));
            }

            return(Json(new { result = "Fail" }));
        }
Пример #3
0
        public JsonResult UpdatePizza([FromBody] TblPizza pizza)
        {
            if (ModelState.IsValid)
            {
                var update = _ctx.TblPizza.FirstOrDefault(x => x.PizzaId == pizza.PizzaId);
                update.Price      = pizza.Price;
                update.Name       = pizza.Name;
                update.CategoryId = pizza.CategoryId;

                _ctx.TblPizza.Update(update);
                _ctx.SaveChanges();

                return(Json(new { result = "Success" }));
            }

            return(Json(new { result = "Fail" }));
        }
Пример #4
0
        public JsonResult CreatePizza([FromBody] TblPizza pizza)
        {
            var createIngridient = _ctx.TblPizza.FirstOrDefault(x => x.Name == pizza.Name);

            if (createIngridient == null)
            {
                int?newId = _ctx.TblPizza.Max(x => (int?)x.PizzaId);

                if (newId == null)
                {
                    newId = 1;
                }

                else
                {
                    newId++;
                }

                if (pizza.Price == 0)
                {
                    pizza.Price = 75;
                }

                if (ModelState.IsValid)
                {
                    var createPizza = new TblPizza
                    {
                        PizzaId    = (int)newId,
                        Name       = pizza.Name,
                        Price      = pizza.Price,
                        CategoryId = pizza.CategoryId
                    };

                    _ctx.TblPizza.Add(createPizza);
                    _ctx.SaveChanges();

                    return(Json(new { status = "Successful" }));
                }
                return(Json(new { status = "Fail" }));
            }
            return(Json(new { status = "Already existing" }));
        }