Beispiel #1
0
        public void Delete(Models.WishList item)
        {
            this.IsLoading = true;

            App.Azure.GetTable <Models.WishList>().DeleteAsync(item).ContinueWith((t) =>
            {
                var ex = t.Exception;

                this.IsLoading = false;

                if (t.Status != System.Threading.Tasks.TaskStatus.RanToCompletion)
                {
                    ReportError("Failed to delete WishList!");
                }
                else
                {
                    this.lists.Remove(item);
                    this.RaisePropertyChanged("Lists");
                }
            });
        }
        public async Task <IActionResult> PrivateList(int?pageNumber, int?pageSize)
        {
            var user = await _workContext.GetCurrentUser();

            var wishList = await _wishListRepository
                           .Query()
                           .SingleOrDefaultAsync(x => x.UserId == user.Id);

            if (wishList == null)
            {
                wishList = new Models.WishList()
                {
                    UserId = user.Id
                };

                _wishListRepository.Add(wishList);
                await _wishListRepository.SaveChangesAsync();
            }

            var wishlistVm = await List(wishList, pageNumber, pageSize);

            return(View(wishlistVm));
        }
        private async Task <WishListVm> List(Models.WishList wishList, int?pageNumber, int?pageSize)
        {
            var itemsPerPage   = pageSize.HasValue ? pageSize.Value : DefaultPageSize;
            var currentPageNum = pageNumber.HasValue ? pageNumber.Value : 1;
            var offset         = (itemsPerPage * currentPageNum) - itemsPerPage;

            var wishlistVm = new WishListVm()
            {
                Id          = wishList.Id,
                SharingCode = wishList.SharingCode
            };

            var wishListItemsQuery = _wishListItemRepository
                                     .Query()
                                     .Where(x => x.WishListId == wishList.Id)
                                     .Select(x => new WishListItemVm()
            {
                Id           = x.Id,
                WishListId   = x.WishListId,
                ProductId    = x.Product.Id,
                ProductName  = x.Product.Name,
                Description  = x.Description,
                ProductImage = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage),
                Quantity     = x.Quantity
            });

            wishlistVm.Items.Data = await wishListItemsQuery
                                    .Skip(offset)
                                    .Take(itemsPerPage)
                                    .ToListAsync();

            wishlistVm.Items.PageNumber = currentPageNum;
            wishlistVm.Items.PageSize   = itemsPerPage;
            wishlistVm.Items.TotalItems = await wishListItemsQuery.CountAsync();

            return(wishlistVm);
        }
        public async Task <IActionResult> AddItem([FromBody] AddToWishList model)
        {
            if (ModelState.IsValid)
            {
                var user = await _workContext.GetCurrentUser();

                var resultModel = new AddToWishListResult();

                var product = await _productRepository
                              .Query()
                              .Include(x => x.ThumbnailImage)
                              .SingleOrDefaultAsync(x => x.Id == model.ProductId);

                if (product == null)
                {
                    return(NotFound());
                }

                var wishList = await _wishListRepository
                               .Query()
                               .Include(x => x.Items)
                               .SingleOrDefaultAsync(x => x.UserId == user.Id);

                if (wishList == null)
                {
                    wishList = new Models.WishList()
                    {
                        UserId = user.Id
                    };

                    _wishListRepository.Add(wishList);
                    await _wishListRepository.SaveChangesAsync();
                }

                var existingWishlistItem = wishList
                                           .Items
                                           .SingleOrDefault(x => x.ProductId == model.ProductId);

                if (existingWishlistItem != null)
                {
                    resultModel.Message = "The product already exists in your wish list";
                    resultModel.Item    = new WishListItemVm()
                    {
                        Id           = existingWishlistItem.Id,
                        WishListId   = wishList.Id,
                        ProductName  = product.Name,
                        ProductImage = _mediaService.GetThumbnailUrl(product.ThumbnailImage),
                        Quantity     = existingWishlistItem.Quantity,
                    };
                }
                else
                {
                    var wishListItem = new WishListItem()
                    {
                        WishListId = wishList.Id,
                        ProductId  = model.ProductId,
                        Quantity   = model.Quantity
                    };

                    _wishListItemRepository.Add(wishListItem);

                    wishList.UpdatedOn = DateTimeOffset.Now;
                    await _wishListRepository.SaveChangesAsync();

                    resultModel.Message = "The product has been added to your wish list";
                    resultModel.Item    = new WishListItemVm()
                    {
                        Id           = wishListItem.Id,
                        WishListId   = wishList.Id,
                        ProductName  = product.Name,
                        ProductImage = _mediaService.GetThumbnailUrl(product.ThumbnailImage),
                        Quantity     = model.Quantity,
                    };
                }

                return(PartialView("AddToWishListResult", resultModel));
            }

            return(NotFound());
        }
Beispiel #5
0
 public void Select(Models.WishList item)
 {
     RequestNavigate <WishListViewModel>(new { listId = item.Id });
 }