public ActionResult CompareGoods(int id) { List <string> properties = new List <string>(); ListCompareGoodDTO goodsFromSession = Session["ComparingGoods"] as ListCompareGoodDTO; List <int> goodsIds = goodsFromSession.CompareGoods[id].ToList(); List <GoodDTO> goods = new List <GoodDTO>(); foreach (var good_id in goodsIds) { goods.Add(goodmanager.Get(good_id)); } foreach (var item in goods.First().PropertyValues.DictStringProperties) { string propertyname = propertymanager.Get(item.Key).Name; properties.Add(propertyname); } CompareGoodsDTO model = new CompareGoodsDTO() { Goods = goods, Properties = properties }; return(View(model)); }
public void SetCompareGood(int id) { GoodDTO good = goodmanager.Get(id); int categoryId = good.Category_Id; ListCompareGoodDTO compgoods = Session["ComparingGoods"] as ListCompareGoodDTO; if (compgoods == null) { compgoods = new ListCompareGoodDTO(); if (!compgoods.CompareGoods.ContainsKey(categoryId)) { compgoods.CompareGoods.Add(categoryId, new List <int>()); } compgoods.CompareGoods[categoryId].Add(id); Session["ComparingGoods"] = compgoods; return; } else { if (compgoods.CompareGoods[categoryId].Find(c => c == id) != -1) { compgoods.CompareGoods[categoryId].Add(id); Session["ComparingGoods"] = compgoods; return; } } }
public ActionResult ComparingCategories() { ComparingCategoriesDTO model = new ComparingCategoriesDTO(); ListCompareGoodDTO goods = Session["ComparingGoods"] as ListCompareGoodDTO; model.CategoriesGoods = new Dictionary <CategoryDTO, List <GoodDTO> >(); foreach (var key in goods.CompareGoods.Keys) { CategoryDTO category = categoryManager.Get(key); model.CategoriesGoods.Add(category, new List <GoodDTO>()); foreach (var good_id in goods.CompareGoods[key]) { GoodDTO good = goodmanager.Get(good_id); model.CategoriesGoods[category].Add(good); } } return(View(model)); }
public void UnsetCompareGood(int id) { GoodDTO good = goodmanager.Get(id); int categoryId = good.Category_Id; ListCompareGoodDTO compgoods = Session["ComparingGoods"] as ListCompareGoodDTO; if (compgoods == null) { return; } else { compgoods.CompareGoods[categoryId].Remove(id); Session["ComparingGoods"] = compgoods; return; } }
// GET: Good public ActionResult ConcreteGood(int id) { var comments = commentManager.GetAllCommentsByGoodId(id).ToList(); GoodViewModelDTO mainmodel = new GoodViewModelDTO(); GoodDTO good = goodmanager.GetAndCheckUser(id, Convert.ToInt32(User.Identity.GetUserId())); mainmodel.Good = good; ListCompareGoodDTO compgoods = Session["ComparingGoods"] as ListCompareGoodDTO; try { mainmodel.IsComparing = compgoods.CompareGoods[good.Category_Id].Contains(id); } catch { mainmodel.IsComparing = false; } List <GoodDTO> alloffers = new List <GoodDTO>(); List <GoodDTO> similaroffers = new List <GoodDTO>(); Dictionary <string, string> properties = new Dictionary <string, string>(); foreach (var item in good.PropertyValues.DictStringProperties) { string propertyname = propertymanager.Get(item.Key).Name; properties.Add(propertyname, item.Value); } //similaroffers = elasticmanager.GetSimilar(good.Name.Split(' ')[1]).ToList(); similaroffers = elasticmanager.GetSimilar(good.Name).ToList(); alloffers = elasticmanager.GetByName(good.Name).ToList(); foreach (var simgood in similaroffers) { simgood.Category = categoryManager.Get(simgood.Category_Id); simgood.WebShop = webShopManager.GetById(simgood.WebShop_Id); } decimal minprice = (decimal)(similaroffers.Select(c => c.Price).Min() ?? good.Price); decimal maxprice = (decimal)(similaroffers.Select(c => c.Price).Max() ?? good.Price); mainmodel.AllOffers = alloffers; mainmodel.SimilarOffers = similaroffers; mainmodel.MinPrice = minprice; mainmodel.MaxPrice = maxprice; mainmodel.Properties = properties; if (User.Identity.IsAuthenticated) { mainmodel.UserId = Convert.ToInt32(User.Identity.GetUserId()); } else { mainmodel.UserId = null; } mainmodel.Comments = commentManager.CheckCommentsDependency(Convert.ToInt32(User.Identity.GetUserId()), id).ToList(); foreach (var comment in mainmodel.Comments) { comment.User = userManager.GetById(comment.UserId); } return(View(mainmodel)); }