コード例 #1
0
        public TomasosModel GetCustomer(List <BestallningMatratt> prodList)
        {
            int numberOfItems = 0;

            if (prodList == null)
            {
                numberOfItems = 0;
            }
            else
            {
                foreach (var item in prodList)
                {
                    numberOfItems += item.Antal;
                }
            }


            var model = new TomasosModel
            {
                Customer    = _context.Kund.SingleOrDefault(x => x.AnvandarNamn == _userManager.GetUserName(User)),
                Dishes      = _context.Matratt.ToList(),
                Ingredients = _context.Produkt.ToList(),
                DishIngredientConnection = _context.MatrattProdukt.ToList(),
                Types       = _context.MatrattTyp.ToList(),
                itemsInCart = numberOfItems,
                Cart        = prodList
            };

            return(model);
        }
コード例 #2
0
        public IActionResult Start()
        {
            if (!_signInManager.IsSignedIn(User))
            {
                var empty = new TomasosModel();
                return(View(empty));
            }

            //if (userName != null)
            //{
            //    customer = _context.Kund.SingleOrDefault(x => x.AnvandarNamn == userName);
            //}
            //return View(customer);

            var dish        = _context.Matratt.ToList();
            var ingredients = _context.Produkt.ToList();
            var con         = _context.MatrattProdukt.ToList();
            var type        = _context.MatrattTyp.ToList();
            var customer    = _context.Kund.SingleOrDefault(x => x.AnvandarNamn == _userManager.GetUserName(User));
            List <BestallningMatratt> prodList;

            if (HttpContext.Session.GetString("Varukorg") == null)
            {
                prodList = null;
            }
            else
            {
                var serializedValue = HttpContext.Session.GetString("Varukorg");
                prodList = JsonConvert.DeserializeObject <List <BestallningMatratt> >(serializedValue);
            }

            int numberOfItems = 0;

            if (prodList == null)
            {
                numberOfItems = 0;
            }
            else
            {
                foreach (var item in prodList)
                {
                    numberOfItems += item.Antal;
                }
            }

            var model = new ViewModels.TomasosModel
            {
                Customer    = customer,
                Dishes      = dish,
                Ingredients = ingredients,
                DishIngredientConnection = con,
                Types       = type,
                itemsInCart = numberOfItems,
                Cart        = prodList
            };

            return(View(model));
        }