public UnitTestApiCart()
        {
            controller = new ApiCartController(null);
            Token t = new Token();

            token = t.CreateToken();
        }
Пример #2
0
        public async Task <IActionResult> Cart()
        {
            string           priceCur = ConstClass.priceCurrency;
            decimal          total    = 0;
            List <ModelCart> list;
            string           token = "";
            int?customerId         = 0;

            ModelParameters modelParameters = cache.Get <ModelParameters>("globalParams");

            if (modelParameters != null)
            {
                token      = modelParameters.Token;
                customerId = modelParameters.CustomerId;
            }

            ViewBag.Token      = token;
            ViewBag.CustomerId = customerId;

            if (localizer != null)
            {
                ViewData["Title"]   = localizer["Title"].Value;
                ViewBag.CartTitle   = localizer["ShoppingCart"].Value;
                ViewBag.NotFound    = localizer["NotFound"].Value;
                ViewBag.SubmitOrder = localizer["SubmitOrder"].Value;
                ViewBag.TotalLabel  = localizer["Total"].Value;
                ViewBag.Name        = localizer["Name"].Value;
                ViewBag.Type        = localizer["Type"].Value;
                ViewBag.Days        = localizer["Days"].Value;
                ViewBag.Duration    = localizer["Duration"].Value;
                ViewBag.Price       = localizer["Price"].Value;
                ViewBag.Delete      = localizer["Delete"].Value;
            }

            try
            {
                using (var context = new ApplicationDbContext())
                {
                    ApiCartController cartController = new ApiCartController(localizer); //_repository
                    list = await cartController.Get(token);

                    total = list.Sum(p => p.Price);
                    if (logger != null)
                    {
                        logger.LogInformation("ApiCartController result: {0}", list);
                    }
                    ViewBag.Total = total + " " + priceCur;
                }
                return(View(list));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message + "; " + ex.InnerException);
                ViewBag.StatusMessage = ex.Message + "<br />" + ex.InnerException;
                return(View());
            }
        }