Пример #1
0
        public async Task <IActionResult> AddFavouriteAsync(int id)
        {
            Member myUser = await userManager.GetUserAsync(User);

            if (User.Identity.IsAuthenticated)
            {
                ViewBag.CartCount = unitOfWork.TemporaryItemsRepository.GetAll(new string[] { }).Where(x => x.MemberId == myUser.Id).Count();
                ViewBag.FavCount  = unitOfWork.MemberProductFavouriteRepository.GetAll(new string[] { }).Where(x => x.MemberId == myUser.Id).Count();
            }

            var chkFav = unitOfWork.MemberProductFavouriteRepository.Find(w => w.ProductId == id && w.MemberId == myUser.Id, new string[] { });

            if (chkFav.Count() == 0)
            {
                var prd = unitOfWork.ProductRepository.Get(id, new string[] { });

                MemberProductFavourite memberProductFavourite = new MemberProductFavourite()
                {
                    Member    = myUser,
                    MemberId  = myUser.Id,
                    Product   = prd,
                    ProductId = prd.Id
                };
                unitOfWork.MemberProductFavouriteRepository.Add(memberProductFavourite);
                unitOfWork.Complete();
            }

            return(RedirectToAction("Details", new { id = id }));
        }
        public async Task <IActionResult> AddFavouriteAsync(int id)
        {
            Member myUser = await userManager.GetUserAsync(User);

            var chkFav = unitOfWork.MemberProductFavouriteRepository.Find(w => w.ProductId == id && w.MemberId == myUser.Id, new string[] { });

            if (chkFav.Count() == 0)
            {
                var prd = unitOfWork.ProductRepository.Get(id, new string[] { });

                MemberProductFavourite memberProductFavourite = new MemberProductFavourite()
                {
                    Member    = myUser,
                    MemberId  = myUser.Id,
                    Product   = prd,
                    ProductId = prd.Id
                };
                unitOfWork.MemberProductFavouriteRepository.Add(memberProductFavourite);
                unitOfWork.Complete();
            }

            return(RedirectToAction("Details", new { id = id }));
        }