public void TestMobitelServiceAndRepository() { var mobitelService = new Mock <IMobitelService>(); var proizvodjacService = new Mock <IProizvodjacService>(); var logService = new Mock <ILogService>(); var emailService = new Mock <IEmailService>(); CustomerController customerController = new CustomerController(mobitelService.Object, proizvodjacService.Object, logService.Object, null, novostiService.Object, emailService.Object); var ivm = new IndexViewModel { Page = 1, PriceTo = 1200, TotalPages = 3, Mobiteli = MobitelViewModel.ConvertToMobitelViewModel(mobitelService.Object.GetMobiteli()) }; var result = customerController.Index(ivm); Assert.IsInstanceOf <ActionResult>(result); }
public IActionResult Index() { KosaricaIndexViewModel model = new KosaricaIndexViewModel(); model.TotalPrice = 0; List <Item> cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, CartName); if (cart.IsNullOrEmpty()) { return(RedirectToAction("Index", "Customer", new { area = "Customer" })); } // get all of the data for display view and calculate the total price of the phone foreach (var item in cart) { var mobitel = mobitelService.GetMobitel(item.Product.Id); item.Product.mobitel = MobitelViewModel.ConvertToMobitelViewModel(mobitel); model.TotalPrice += item.Product.mobitel.Cijena * item.Quantity; } model.TotalPrice = Converter.RoundToTwoDecimal(model.TotalPrice); model.Items = cart; return(View(model)); }
public IActionResult Index(int?id) { if (id == null) { return(RedirectToAction("Index", "Customer")); } MobitelIndexViewModel model = new MobitelIndexViewModel(); model.Mobitel = MobitelViewModel.ConvertToMobitelViewModel(mobitelService.GetMobitel(id.Value)); model.Komentari = komentarService.GetAllKomentariByPhoneId(id.Value); return(View(model)); }
public IActionResult Komentiraj(string komentar, int mobitelId) { if (komentar.IsNullOrEmpty() || komentar.Length > 1000) { ModelState.AddModelError("predugkomentar", "Vas komentar je predug, isti mora biti manji od 1000 karaktera."); MobitelIndexViewModel model = new MobitelIndexViewModel(); model.Mobitel = MobitelViewModel.ConvertToMobitelViewModel(mobitelService.GetMobitel(mobitelId)); model.Komentari = komentarService.GetAllKomentariByPhoneId(mobitelId); return(View(model)); } var userId = _userManager.GetUserId(HttpContext.User); int kupacId = kupacService.GetKupacByAspUserId(userId); komentarService.InsertKomentar(new Komentar { Datum = DateTime.UtcNow, KupacId = kupacId, Sadrzaj = komentar, MobitelId = mobitelId }); return(RedirectToAction("Index", new { id = mobitelId })); }
private void PopulateModel(ref NaruzbaViewModel returnModel) { KosaricaIndexViewModel model = new KosaricaIndexViewModel(); model.TotalPrice = 0; List <Item> cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, CartName); // get all of the data for display view and calculate the total price of the phone foreach (var item in cart) { var mobitel = mobitelService.GetMobitel(item.Product.Id); item.Product.mobitel = MobitelViewModel.ConvertToMobitelViewModel(mobitel); model.TotalPrice += Converter.RoundToTwoDecimal(item.Product.mobitel.Cijena * item.Quantity); } model.Items = cart; returnModel.Detalji = model; }
public IActionResult Index(IndexViewModel model) { model.Proizvodjaci = Converter.ConvertToSelectListItem(proizvodjacService.GetProizvodjaci()); var mobiteli = mobitelService.GetMobiteli(); if (!mobiteli.IsNullOrEmpty()) { model.PriceTo = (int)Math.Ceiling(mobiteli.Max(x => x.Cijena)); } else { model.PriceTo = 3500; } int TotalPages = 0; model.Mobiteli = MobitelViewModel.ConvertToMobitelViewModel(mobitelService.GetMobiteliSorted(model.Page ?? 0, model.PriceDesc, model.SearchName, model.my_range, model.ProizvodjacId, resultsPerPage, ref TotalPages)); model.TotalPages = TotalPages; // setup our slider data if (!string.IsNullOrEmpty(model.my_range)) { model.sliderFrom = Convert.ToInt32(model.my_range.Split(';')[0]); model.sliderTo = Convert.ToInt32(model.my_range.Split(';')[1]); } else { model.sliderFrom = 0; model.sliderTo = model.PriceTo; } return(View(model)); }