public static List <wishlist_data> fill_page() { // this class will fetch all the product data from class to home page WishlistModel model = new WishlistModel(); ProductModel productmodel = new ProductModel(); string userId = Convert.ToString(HttpContext.Current.Session["Userid"]); List <Wishlist> items = new List <Wishlist>(); items = model.get_itmesinWishlist(userId); List <wishlist_data> info = new List <wishlist_data>(); foreach (Wishlist item in items) { wishlist_data wishlist = new wishlist_data(); Product product = productmodel.get_product_ef(item.ProductID); wishlist.image = product.Image; wishlist.Price = product.Price; wishlist.name = product.Name; wishlist.wishlistid = item.ID; info.Add(wishlist); } return(info); }
public virtual async Task <IActionResult> Wishlist(Guid?customerGuid) { if (!await _permissionService.Authorize(StandardPermissionProvider.EnableWishlist)) { return(RedirectToRoute("HomePage")); } Customer customer = customerGuid.HasValue ? await _customerService.GetCustomerByGuid(customerGuid.Value) : _workContext.CurrentCustomer; if (customer == null) { return(RedirectToRoute("HomePage")); } var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.Wishlist); if (!string.IsNullOrEmpty(_storeContext.CurrentStore.Id)) { cart = cart.LimitPerStore(_shoppingCartSettings.CartsSharedBetweenStores, _storeContext.CurrentStore.Id); } var model = new WishlistModel(); await _shoppingCartViewModelService.PrepareWishlist(model, cart.ToList(), !customerGuid.HasValue); return(View(model)); }
public IActionResult Post([FromBody] WishlistModel model) //adding item to wishlist { if (obj.PostWIshlist(model)) { return(Ok()); } return(BadRequest()); }
public async Task <IActionResult> PostTestPurpose(WishlistModel wishlistmodel) { var wishListDetails = new Wishlist() { UserId = Convert.ToInt32(wishlistmodel.UserId), ProductCode = wishlistmodel.ProductCode }; await _context.Wishlists.AddAsync(wishListDetails); await _context.SaveChangesAsync(); return(Ok(wishlistmodel)); }
public void AddToWishList_Success() { WishlistModel entity = new WishlistModel { CustomerId = 1, ProductId = 3 }; _config.Setup(p => p.Wish(1, 3)).Returns(new WishlistSuccess { Message = "Product added to wishlist" }); var result = _controller.AddToWishList(entity); Assert.That(result, Is.InstanceOf <OkObjectResult>()); }
public Boolean PostWIshlist(WishlistModel model) //adding product ot wishlist { if (_wishlistDA.checkingExistance(model.Customer_ID, model.Product_ID)) //If already exist then do nothing { return(true); } var entity = _mapper.Map <WishlistModel, Wishlist>(model); if (_wishlistDA.PostWishlist(entity)) { return(true); } return(false); }
protected async Task <WishlistModel> PrepareWishlistModelAsync(IList <OrganizedShoppingCartItem> cart, bool isEditable = true) { Guard.NotNull(cart, nameof(cart)); var model = new WishlistModel { IsEditable = isEditable, EmailWishlistEnabled = _shoppingCartSettings.EmailWishlistEnabled, DisplayAddToCart = await Services.Permissions.AuthorizeAsync(Permissions.Cart.AccessShoppingCart) }; if (cart.Count == 0) { return(model); } var customer = cart.FirstOrDefault()?.Item.Customer ?? Services.WorkContext.CurrentCustomer; model.CustomerGuid = customer.CustomerGuid; model.CustomerFullname = customer.GetFullName(); model.ShowProductImages = _shoppingCartSettings.ShowProductImagesOnShoppingCart; model.ShowProductBundleImages = _shoppingCartSettings.ShowProductBundleImagesOnShoppingCart; model.ShowItemsFromWishlistToCartButton = _shoppingCartSettings.ShowItemsFromWishlistToCartButton; model.ShowSku = _catalogSettings.ShowProductSku; model.DisplayShortDesc = _shoppingCartSettings.ShowShortDesc; model.BundleThumbSize = _mediaSettings.CartThumbBundleItemPictureSize; // Cart warnings var warnings = new List <string>(); var cartIsValid = await _shoppingCartValidator.ValidateCartAsync(cart, warnings); if (!cartIsValid) { model.Warnings.AddRange(warnings); } foreach (var item in cart) { var wishlistCartItemModel = await PrepareWishlistCartItemModelAsync(item); model.Items.Add(wishlistCartItemModel); } return(model); }
public async Task <IActionResult> Wishlist(int pageSize, int page = 1) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } var name = User.Identity.Name; var user = await _userService.GetUserByName(name); pageSize = _configuration.GetValue <int>("PageSizeWishlist"); var wishlist = new WishlistModel(); wishlist.Wishlist = _wishlistService.GetAllPaging(user.Id.ToString(), pageSize, page); wishlist.Tags = _tagService.GetAllJobTag().OrderBy(x => Guid.NewGuid()).Take(10).ToList(); wishlist.User = user; return(View(wishlist)); }
public static WishlistModel ToWishlistModel([NotNull] this WishList wishList, IProductService productService = null) { var cartLineModel = new List <WishlistLineModel>(0); if (wishList.Lines != null && wishList.Lines.Any()) { foreach (var line in wishList.Lines) { cartLineModel.Add(line.ToWishlistLineModel(productService)); } } var wishlitstModel = new WishlistModel() { Lines = cartLineModel }; return(wishlitstModel); }
public IActionResult AddToWishList([FromBody] WishlistModel wish) { _log4net.Info("Add to WishList method initiated"); try { _log4net.Info("Add To Wishlist Provider called"); WishlistSuccess message = _provider.Wish(wish.CustomerId, wish.ProductId); if (message == null) { return(BadRequest()); } return(Ok(message)); } catch { _log4net.Info("Error calling Add Wishlist provider"); return(BadRequest()); } }
public IActionResult Index(WishlistModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!ModelState.IsValid) { ModelState.AddModelError("Error", "Invalid data"); return(View(ViewPath, model)); } model.LastUpdated = DateTime.Now; Database.Wishlist.RemoveRange(Database.Wishlist); Database.Wishlist.Add(model); Database.SaveChanges(); return(RedirectToAction("Index", "Admin")); }
public virtual async Task <IActionResult> Wishlist(Guid?customerGuid) { if (!await _permissionService.Authorize(StandardPermissionProvider.EnableWishlist)) { return(RedirectToRoute("HomePage")); } Customer customer = customerGuid.HasValue ? await _customerService.GetCustomerByGuid(customerGuid.Value) : _workContext.CurrentCustomer; if (customer == null) { return(RedirectToRoute("HomePage")); } var cart = _shoppingCartService.GetShoppingCart(_storeContext.CurrentStore.Id, ShoppingCartType.Wishlist); var model = new WishlistModel(); await _shoppingCartViewModelService.PrepareWishlist(model, cart, !customerGuid.HasValue); return(View(model)); }
protected void Page_Load(object sender, EventArgs e) { string Userid = Context.User.Identity.GetUserId(); Session["Userid"] = Userid; WishlistModel model = new WishlistModel(); if (Userid != null) { if (!string.IsNullOrWhiteSpace(Request.QueryString["id"])) { int id = Convert.ToInt32(Request.QueryString["id"]); Wishlist item = new Wishlist { UsersID = Userid, ProductID = id }; if (!(model.if_already_inserted(Userid, id))) { model.insert_in_wishlist(item); } } else if (!string.IsNullOrWhiteSpace(Request.QueryString["del"])) { int id = Convert.ToInt32(Request.QueryString["del"]); model.delete_in_wishlist(id); Response.Redirect("wishlist.aspx"); } } else { Response.Redirect("loginPage.aspx"); } }
public virtual IActionResult Wishlist(Guid?customerGuid) { if (!_permissionService.Authorize(StandardPermissionProvider.EnableWishlist)) { return(RedirectToRoute("HomePage")); } Customer customer = customerGuid.HasValue ? _customerService.GetCustomerByGuid(customerGuid.Value) : _workContext.CurrentCustomer; if (customer == null) { return(RedirectToRoute("HomePage")); } var cart = customer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.Wishlist) .LimitPerStore(_storeContext.CurrentStore.Id) .ToList(); var model = new WishlistModel(); _shoppingCartViewModelService.PrepareWishlist(model, cart, !customerGuid.HasValue); return(View(model)); }
public virtual async Task <CommerceCommand> Process(CommerceContext commerceContext, WishlistModel wishlistModel) { AddWishlistCommand addWishlistCommand = this; try { var customerEntity = await _getCustomerCommand.Process(commerceContext, wishlistModel.CustomerId); if (customerEntity != null) { if (customerEntity.HasComponent <WishlistComponent>()) { var component = customerEntity.GetComponent <WishlistComponent>(); // Checking if product is already added to list or not bool isProductAdded = false; if (component.WishlistCollection == null) { component.WishlistCollection = new List <WishlistEntity>(); } else { isProductAdded = component.WishlistCollection.Any(x => x.ProductId == wishlistModel.ProductId); } if (!isProductAdded) { WishlistEntity wishlistEntity = new WishlistEntity() { ProductId = wishlistModel.ProductId, ProductTitle = wishlistModel.ProductTitle, ProductPrice = wishlistModel.ProductPrice }; component.WishlistCollection.Add(wishlistEntity); customerEntity.SetComponent(component); commerceContext.Logger.LogInformation($"AddWishlistCommand for customer id: {wishlistModel.CustomerId} added product Id: {wishlistModel.ProductId}"); } else { commerceContext.Logger.LogInformation($"AddWishlistCommand for customer id: {wishlistModel.CustomerId} NOT ADDED product Id: {wishlistModel.ProductId} as it already exists"); } } else { WishlistComponent wishlistComponent = new WishlistComponent(); wishlistComponent.WishlistCollection = new List <WishlistEntity>(); WishlistEntity wishlistEntity = new WishlistEntity() { ProductId = wishlistModel.ProductId, ProductTitle = wishlistModel.ProductTitle, ProductPrice = wishlistModel.ProductPrice }; wishlistComponent.WishlistCollection.Add(wishlistEntity); customerEntity.SetComponent(wishlistComponent); } await this._persistEntityPipeline.Run(new PersistEntityArgument(customerEntity), commerceContext.PipelineContext); } } catch (Exception ex) { commerceContext.Logger.LogError($"Exception occured in getting customer { ex.StackTrace} and id is {ex.Message}"); } return(addWishlistCommand); }
public virtual async Task <IActionResult> AddItemsToCartFromWishlist(Guid?customerGuid, IFormCollection form) { if (!await _permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart)) { return(RedirectToRoute("HomePage")); } if (!await _permissionService.Authorize(StandardPermissionProvider.EnableWishlist)) { return(RedirectToRoute("HomePage")); } var pageCustomer = customerGuid.HasValue ? await _customerService.GetCustomerByGuid(customerGuid.Value) : _workContext.CurrentCustomer; if (pageCustomer == null) { return(RedirectToRoute("HomePage")); } var pageCart = _shoppingCartService.GetShoppingCart(_storeContext.CurrentStore.Id, ShoppingCartType.Wishlist); var allWarnings = new List <string>(); var numberOfAddedItems = 0; var allIdsToAdd = form.ContainsKey("addtocart") ? form["addtocart"].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x) .ToList() : new List <string>(); foreach (var sci in pageCart) { if (allIdsToAdd.Contains(sci.Id)) { var warnings = await _shoppingCartService.AddToCart(_workContext.CurrentCustomer, sci.ProductId, ShoppingCartType.ShoppingCart, _storeContext.CurrentStore.Id, sci.WarehouseId, sci.AttributesXml, sci.CustomerEnteredPrice, sci.RentalStartDateUtc, sci.RentalEndDateUtc, sci.Quantity, true); if (!warnings.Any()) { numberOfAddedItems++; } if (_shoppingCartSettings.MoveItemsFromWishlistToCart && //settings enabled !customerGuid.HasValue && //own wishlist !warnings.Any()) //no warnings ( already in the cart) { //let's remove the item from wishlist await _shoppingCartService.DeleteShoppingCartItem(_workContext.CurrentCustomer, sci); } allWarnings.AddRange(warnings); } } if (numberOfAddedItems > 0) { //redirect to the shopping cart page if (allWarnings.Any()) { ErrorNotification(_localizationService.GetResource("Wishlist.AddToCart.Error"), true); } return(RedirectToRoute("ShoppingCart")); } else { //no items added. redisplay the wishlist page if (allWarnings.Any()) { ErrorNotification(_localizationService.GetResource("Wishlist.AddToCart.Error"), false); } //no items added. redisplay the wishlist page var cart = _shoppingCartService.GetShoppingCart(_storeContext.CurrentStore.Id, ShoppingCartType.Wishlist); var model = new WishlistModel(); await _shoppingCartViewModelService.PrepareWishlist(model, cart, !customerGuid.HasValue); return(View(model)); } }
public virtual async Task <IActionResult> UpdateWishlist(IFormCollection form) { if (!await _permissionService.Authorize(StandardPermissionProvider.EnableWishlist)) { return(RedirectToRoute("HomePage")); } var customer = _workContext.CurrentCustomer; var cart = _shoppingCartService.GetShoppingCart(_storeContext.CurrentStore.Id, ShoppingCartType.Wishlist); var allIdsToRemove = !string.IsNullOrEmpty(form["removefromcart"].ToString()) ? form["removefromcart"].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x) .ToList() : new List <string>(); //current warnings <cart item identifier, warnings> var innerWarnings = new Dictionary <string, IList <string> >(); foreach (var sci in cart) { bool remove = allIdsToRemove.Contains(sci.Id); if (remove) { await _shoppingCartService.DeleteShoppingCartItem(customer, sci); } else { foreach (string formKey in form.Keys) { if (formKey.Equals(string.Format("itemquantity{0}", sci.Id), StringComparison.OrdinalIgnoreCase)) { if (int.TryParse(form[formKey], out int newQuantity)) { var currSciWarnings = await _shoppingCartService.UpdateShoppingCartItem(_workContext.CurrentCustomer, sci.Id, sci.WarehouseId, sci.AttributesXml, sci.CustomerEnteredPrice, sci.RentalStartDateUtc, sci.RentalEndDateUtc, newQuantity, true); innerWarnings.Add(sci.Id, currSciWarnings); } break; } } } } //updated wishlist _workContext.CurrentCustomer = await _customerService.GetCustomerById(customer.Id); cart = _shoppingCartService.GetShoppingCart(_storeContext.CurrentStore.Id, ShoppingCartType.Wishlist); var model = new WishlistModel(); await _shoppingCartViewModelService.PrepareWishlist(model, cart); //update current warnings foreach (var kvp in innerWarnings) { //kvp = <cart item identifier, warnings> var sciId = kvp.Key; var warnings = kvp.Value; //find model var sciModel = model.Items.FirstOrDefault(x => x.Id == sciId); if (sciModel != null) { foreach (var w in warnings) { if (!sciModel.Warnings.Contains(w)) { sciModel.Warnings.Add(w); } } } } return(View(model)); }
public Task SendWishlist(WishlistModel wishlistModel) { return(Clients.Group(wishlistModel.Id.ToString()).SendAsync("UpdateWishlist", wishlistModel)); }