public void Insert(FavoritItem entity) { if (entity == null) { throw new ArgumentNullException("favorit"); } _favoritRepository.Insert(entity); _cacheManager.RemoveByPattern(FAVORIT_PATTERN_KEY); //event notification _eventPublisher.EntityInserted(entity); }
public void DeleteFavorit(FavoritItem item) { if (item == null) { throw new ArgumentNullException("favorit"); } this._favoritRepository.Delete(item); _cacheManager.RemoveByPattern(FAVORIT_PATTERN_KEY); _eventPublisher.EntityDeleted(item); }
public ActionResult AddToFavorits(int productId) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(RedirectToRoute("HomePage")); } if (productId == 0) { return(new JsonResult()); } var favorit = new FavoritItem() { ProductId = productId, CustomerId = _workContext.CurrentCustomer.Id, CreatedOnUtc = DateTime.UtcNow }; _favoritsService.Insert(favorit); return(new JsonResult()); }
protected FavoritItemModel PrepareFavoritItemModel(FavoritItem item) { var model = new FavoritItemModel(); model.Id = item.Id; model.ProductId = item.ProductId; var category = item.Product.ProductCategories.First().Category; model.CategoryString = category.Name; while (category.ParentCategoryId != 0) { category = _categoryService.GetCategoryById(category.ParentCategoryId); model.CategoryString = model.CategoryString.Insert(0, category.GetLocalized(x => x.Name) + "->"); } var languages = new OrderedLanguageCultures(); model.ProductTitle = item.Product.GetLocalized(p => p.Name, _workContext.WorkingLanguage.Id, true); //process favorit product language specific information #region if (model.ProductTitle != null) { model.ProductDescription = item.Product.GetLocalized(p => p.ShortDescription, _workContext.WorkingLanguage.Id); model.ProductSeName = item.Product.GetSeName(_workContext.WorkingLanguage.Id); } else { for (int i = 0; i < languages.Cultures.Count; i++) { var langid = _languageService.GetAllLanguages().Where(x => x.LanguageCulture == languages.Cultures[i]).FirstOrDefault().Id; model.ProductTitle = item.Product.GetLocalized(p => p.Name, langid, false); if (model.ProductTitle != null) { model.ProductDescription = item.Product.GetLocalized(p => p.ShortDescription, langid); model.ProductSeName = item.Product.GetSeName(langid); break; } } } #endregion //process favorit product company information #region model.CompanyName = item.Product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, _workContext.WorkingLanguage.Id, false); if (model.CompanyName != null) { model.CompanySeName = item.Product.Customer.CompanyInformation.GetSeName(_workContext.WorkingLanguage.Id); } else { for (int i = 0; i < languages.Cultures.Count; i++) { var langid = _languageService.GetAllLanguages().Where(x => x.LanguageCulture == languages.Cultures[i]).FirstOrDefault().Id; model.CompanyName = item.Product.Customer.CompanyInformation.GetLocalized(x => x.CompanyName, langid, false); if (model.CompanyName != null) { model.CompanySeName = item.Product.Customer.CompanyInformation.GetSeName(langid); break; } } } #endregion var picture = item.Product.ProductPictures.Where(x => x.DisplayOrder == 0).FirstOrDefault(); if (picture == null && item.Product.ProductPictures.Count > 0) { picture = item.Product.ProductPictures.First(); model.PictureUrl = _pictureService.GetPictureUrl(picture.PictureId, showDefaultPicture: false); } else { if (picture != null) { model.PictureUrl = _pictureService.GetPictureUrl(picture.PictureId, showDefaultPicture: false); } } return(model); }