public async Task <IActionResult> Details(string id)
        {
            if (!advertisementService.Contains(id))
            {
                return(Redirect("/Home/Index"));
            }

            var loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            var ad = await advertisementService.GetByIdAsync(id);

            var user = await userManager.FindByIdAsync(ad.UserId);

            var town = await townService.GetByIdAsync(ad.TownId);

            if (user.Id != loggedInUserId)
            {
                await advertisementService.IncrementViewsAsync(id);
            }

            var category = await categoryService.GetByIdAsync(ad.CategoryId);

            string subCategoryName = null;

            if (await subCategoryService.ContainsByIdAsync(ad.SubCategoryId))
            {
                var subCategory = await subCategoryService.GetByIdAsync(ad.SubCategoryId);

                subCategoryName = subCategory.Name;
            }

            var viewModel = new DetailsViewModel()
            {
                Id                       = ad.Id,
                Address                  = ad.Address,
                CategoryName             = category.Name,
                CategoryId               = category.Id,
                SubCategoryId            = ad.SubCategoryId,
                SubCategoryName          = subCategoryName,
                CreatedOn                = ad.CreatedOn.ToString(GlobalConstants.DateTimeFormat),
                Description              = ad.Description,
                UserId                   = ad.UserId,
                Username                 = user.UserName,
                Name                     = ad.Name,
                Phone                    = ad.Number,
                TownName                 = town.Name,
                Price                    = ad.Price,
                Images                   = ad.Images,
                Condition                = ad.Condition.ToString(),
                IsAdInLoggedUserWishlist = await userAdWishlistService.IsAdInWishlistAsync(User.FindFirstValue(ClaimTypes.NameIdentifier), ad.Id)
            };

            ViewData["loggedUserId"] = User.FindFirstValue(ClaimTypes.NameIdentifier);

            return(View(viewModel));
        }
        public IActionResult Promote(string adId)
        {
            if (!advertisementService.Contains(adId))
            {
                return(RedirectToAction("All"));
            }

            return(View(new AdvertisementPromoteViewModel {
                Id = adId
            }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddToWishlist(string adId)
        {
            if (!advertisementService.Contains(adId))
            {
                return(Redirect("/Home/Index"));
            }

            var ad = await advertisementService.GetByIdAsync(adId);

            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (userId == ad.UserId)
            {
                return(Redirect($"/Advertisement/Details?id={adId}"));
            }

            await userAdWishlistService.AddToWishlistAsync(userId, adId);

            return(Redirect($"/Advertisement/Details?id={adId}"));
        }