public IActionResult Index() { var userId = _userManager.GetUserId(HttpContext.User); var query = from p in _db.CartItem where p.CustomerId == userId group p by new { p.Product.ProductName, p.Product.UnitPrice } into g select new { Name = g.Key.ProductName, Count = g.Count(), Price = g.Key.UnitPrice }; CardIndexViewModel cardVM = new CardIndexViewModel(); foreach (var item in query) { CardProductViewModel cProd = new CardProductViewModel(); cProd.ProductName = item.Name; cProd.Quantity = item.Count; cProd.Price = item.Price; cProd.ProductTotal = item.Price * item.Count; cardVM.CardProductVMList.Add(cProd); } cardVM.CardTotalPrice = cardVM.CardProductVMList.Sum(c => c.ProductTotal); return(View(cardVM)); }
public static void SetupViewBag(CardIndexViewModel homeIndexVM, dynamic ViewBag) { ViewBag.KeyWords = homeIndexVM.KeyWords; ViewBag.MaxResults = homeIndexVM.MaxResults; ViewBag.TotalJobs = homeIndexVM.MaxResults != 0 ? homeIndexVM.MaxResults : 100; ViewBag.Page = homeIndexVM.Page; }
public static CardIndexViewModel SetDefaultFindModel(CardIndexViewModel CardIndexVM) { if (CardIndexVM == null) { CardIndexVM = new CardIndexViewModel(); } CardIndexVM.KeyWords ??= ""; if (CardIndexVM.MaxResults == 0) { CardIndexVM.MaxResults = 100; } if (CardIndexVM.Page == 0) { CardIndexVM.Page = 1; } if (CardIndexVM.CardType == null) { CardIndexVM.CardType = CardType.Generic; } return(CardIndexVM); }
// GET: prepaidCards public async Task <IActionResult> Index(int?pageNumber, string searchString) { int total = _context.prepaidCard.Count(); int pagecount = total / 10 + 1; if (pagecount > 10) { pagecount = 10; } PaginatedList <prepaidCard> cards = null; if (searchString != null) { cards = await PaginatedList <prepaidCard> .CreateAsync(_context.prepaidCard.Where(c => c.CardCode == searchString), pageNumber ?? 1, 10); } else { cards = await PaginatedList <prepaidCard> .CreateAsync(_context.prepaidCard, pageNumber ?? 1, 10); } CardIndexViewModel ViewModels = new CardIndexViewModel() { Cards = cards, PageIndex = pageNumber ?? 1, PageTotal = pagecount }; // int pageSize = 3; return(View(ViewModels)); // return View(snackInfoViewModels); }
public async Task <IActionResult> Index() { var cards = await _cardRepository.GetRandomSetOfCardsAsyncDb(9); CardIndexViewModel vm = new CardIndexViewModel(); vm.Cards = cards; return(View(vm)); }
public async Task <List <Card> > ConfigureSearchAsync(CardIndexViewModel cardIndexVM) { var fromNumber = 0; if (cardIndexVM.Page > 1) { fromNumber = cardIndexVM.Page * 12; } var jobsCollection = await _es.QueryJobPosting(fromNumber, cardIndexVM.KeyWords, 12, cardIndexVM.CardType); return(jobsCollection); }
public IActionResult IndexPost(CardIndexViewModel homeIndexVm) { homeIndexVm = CardHelpers.SetDefaultFindModel(homeIndexVm); CardHelpers.SetupViewBag(homeIndexVm, ViewBag); var vmData = JsonConvert.SerializeObject(homeIndexVm); HttpContext.Session.SetString(SearchVMCacheKey, vmData); return(RedirectToAction("Index")); }
public void Can_View_Cart_Contents() { //arrange CartController taget = new CartController(null, null); Cart cart = new Cart(); //action CardIndexViewModel modelCard = (CardIndexViewModel)taget.Index(cart, "myUrl").ViewData.Model; //лезем в представление и там в модель //assert Assert.AreEqual(modelCard.Cart, cart); Assert.AreEqual(modelCard.ReturnUrl, "myUrl"); }
public void Can_View_Cart_Contents() { //Организация - создание экземпляра Cart Cart cart = new Cart(); //Организация - создание контроллера CartController target = new CartController(null, null); //Действие - вызов метода действия Index() CardIndexViewModel result = (CardIndexViewModel)target.Index(cart, "myUrl").ViewData.Model; //Утверждение Assert.AreSame(result.Cart, cart); Assert.AreEqual(result.ReturnUrl, "myUrl"); }
public async Task <IActionResult> Index() { var value = HttpContext.Session.GetString(SearchVMCacheKey); CardIndexViewModel cardIndexViewModel = string.IsNullOrEmpty(value) ? CardHelpers.SetDefaultFindModel(new CardIndexViewModel()) : JsonConvert.DeserializeObject <CardIndexViewModel>(value); CardHelpers.SetupViewBag(cardIndexViewModel, ViewBag); var result = await _cardRepository.ConfigureSearchAsync(cardIndexViewModel); var count = await _cardRepository.GetTotalCards(); ViewBag.MaxPage = count / cardIndexViewModel.Page; ViewBag.Page = cardIndexViewModel.Page; cardIndexViewModel.Cards = result; return(View(cardIndexViewModel)); }