Пример #1
0
        public void AddRemoveWishlist(BookDto book, bool remove)
        {
            if (remove)
            {
                try
                {
                    var wish = _wishListService.GetAll()
                               .FirstOrDefault(c => c.BookId == book.Id && c.ClientId == _authService.GetCurrentClientId());

                    _wishListService.Delete(wish.Id);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message, ex);
                }
            }
            else
            {
                try
                {
                    _wishListService.Create(
                        new WishDto
                    {
                        ClientId = _authService.GetCurrentClientId().Value,
                        BookId   = book.Id
                    });
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message, ex);
                }
            }
        }
Пример #2
0
        // GET: WishList
        public ActionResult Index()
        {
            var userId   = User.Identity.GetUserId();
            var wishlist = AutoMapper.Mapper.Map <List <WishListViewModel> >(_wishListService.GetAll(userId));

            return(View(wishlist));
        }
Пример #3
0
        public ActionResult Index(string contactValue)
        {
            HomeViewModel          model       = new HomeViewModel();
            List <Product>         products    = _productService.Get().ToList();
            List <Image>           images      = _imageService.GetAll().ToList();
            List <Manufactor>      manufactors = _manufactorService.GetAll().ToList();
            IEnumerable <Category> categories  = _categoryService.GetAll().ToList();
            IEnumerable <Anime>    animes      = _animeService.GetAll().ToList();

            model.products    = products;
            model.images      = images;
            model.manufactors = manufactors;
            model.categories  = categories;
            model.animes      = animes;
            model.wishLists   = User.Identity.IsAuthenticated ? _wishListService.GetAll().Where(m => m.UserID == User.Identity.GetUserId()) : null;

            if (contactValue != null)
            {
                ViewBag.ContactSuccessfull = "Your message was submit. We will contact you later!";
            }
            return(View(model));
        }
Пример #4
0
        // GET: Product
        //Product/ProductDetail/id
        public ActionResult ProductDetail(int?id)
        {
            Product product = _productService.GetById(id.HasValue ? id.Value : 0);

            if (product != null && !product.isDelete)//check xem product co tren db ko va product da bi xoa ?
            {
                //khoi tao para cho filter Models
                IEnumerable <Category>   categories  = _categoryService.GetAll();
                IEnumerable <Manufactor> manufactors = _manufactorService.GetAll();
                IEnumerable <Status>     status      = _statusService.GetAll();
                IEnumerable <ProductTag> productTags = _productTagService.GetAll().Where(m => m.ProductID == product.Id);
                IEnumerable <Image>      images      = _imageService.GetAll().Where(m => m.ProductID == product.Id);

                ProductIndex p = new ProductIndex();//xu ly va fill du lieu vao Models
                p.product = product;
                List <Tag> tags = new List <Tag>();
                foreach (var item in productTags)
                {
                    tags.Add(_tagService.GetAll().FirstOrDefault(m => m.Id == item.TagID));
                }
                p.tags = tags;
                Category category = categories.FirstOrDefault(m => m.id == product.CategoryID);
                p.category = category;
                Manufactor manufactor = manufactors.FirstOrDefault(m => m.Id == product.ManufactorID);
                p.manufactor = manufactor;
                Status s = status.FirstOrDefault(m => m.Id == product.StatusID);
                p.status        = s;
                p.images        = images;
                p.comments      = _commentService.GetAll().Where(m => m.ProductID == product.Id && m.Type == 1 && m.isDelete == false).OrderByDescending(m => m.dateCreate).AsEnumerable();
                p.wishLists     = User.Identity.IsAuthenticated ? _wishListService.GetAll().Where(m => m.UserID == User.Identity.GetUserId()) : null;
                product.C_View += 1;//tang luot view len 1
                _productService.editProduct(product);
                return(View(p));
            }
            else
            {
                return(HttpNotFound());//trang view loi~
            }
        }
Пример #5
0
        public void RemoveWish_WhenRemoveWish_ThenInvokeRemoveByService()
        {
            // Arrange
            var book = new BookDto {
                Id = Guid.NewGuid()
            };
            var userId = Guid.NewGuid();

            A.CallTo(() => _authService.GetCurrentClientId()).Returns(userId);

            A.CallTo(() => _wishListService.GetAll())
            .Returns(new List <WishDto> {
                new WishDto {
                    Id = Guid.NewGuid(), BookId = book.Id, ClientId = userId
                }
            });

            // Act
            _page.AddRemoveWishlist(book, true);

            // Assert
            A.CallTo(() => _wishListService.Delete(A <Guid> ._)).MustHaveHappened();
        }
Пример #6
0
 public Task <IEnumerable <WishListViewModel> > GetAll()
 {
     return(_wishListService.GetAll());
 }