public ActionResult EditAdvertisement(int id)
        {
            Advertisement    ad     = _advertisementRepository.GetAdvertisement(id);
            int              cardId = ad.CardId;
            Card             card   = _cardRepository.GetCard(cardId);
            AdsListViewModel result = new AdsListViewModel {
                Cards = card, Advertisements = ad
            };

            return(PartialView("Partial2", result));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Advertisement advertisement = _repository.GetAdvertisement(id.Value);

            if (advertisement == null)
            {
                return(HttpNotFound());
            }
            return(View(advertisement));
        }
        public IActionResult GetAdvertisement(int advertisementId)
        {
            var result = _advertisementRepository.GetAdvertisement(advertisementId);

            if (result == null)
            {
                return(NotFound("Advertisement not found"));
            }
            return(Ok(result));
        }
Beispiel #4
0
        public ActionResult AddToCart(int advertisementId)
        {
            string        accountId = HttpContext.Session.GetString("username"); //session
            ShoppingCart  cart      = _shoppingCartRepository.GetShoppingCart(accountId);
            Advertisement ad        = _advertisementRepository.GetAdvertisement(advertisementId);

            ShoppingCartItem item = new ShoppingCartItem {
                ShoppingCartId = cart, ad = ad
            };

            _shoppingCartRepository.AddToCart(ad, cart);
            TempData["success"] = "The card has been succesfully added to your cart";
            return(RedirectToAction("list", "Advertisement"));
        }
Beispiel #5
0
        public IActionResult AddFavourite(FavouriteItemRequest request)
        {
            var email           = User.Claims.First().Value;
            var advertisementId = request.AdvertisementId;
            var advertisement   = _advertisementRepository.GetAdvertisement(advertisementId);
            var favourites      = _favouritesRepository.GetAllFavourites().LastOrDefault(
                f => f.UserId == GetCurrentUser(email).Id) ?? new Favourites
            {
                User   = GetCurrentUser(email),
                UserId = GetCurrentUser(email).Id
            };

            var favouriteItem = new FavouritesItem
            {
                Advertisement   = advertisement,
                AdvertisementId = advertisementId,
                Favourites      = favourites,
                FavouritesId    = favourites.Id
            };

            _favouritesRepository.AddOrUpdate(favourites);
            _favouritesItemRepository.Add(favouriteItem);
            return(Ok("Successful"));
        }