public bool Add(Guid adId, string currentUserId, Guid countryId)
        {
            Wishlist wishlist = new Wishlist
            {
                AdId      = adId,
                OwnerId   = currentUserId,
                CountryId = countryId
            };

            if (!_repository.Exists(adId, currentUserId))
            {
                return(_repository.Add(wishlist));
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        public List <AdGridViewModel> GetPageForAdGrid(PageModel pageModel, out int count, out int maxPrice)
        {
            List <Ad> sourceEntities;

            switch (pageModel.ColumnName.ToLower())
            {
            case "name":
                sourceEntities = _repository.GetAdGrid(pageModel.SearchString, pageModel.CountryId);
                break;

            default:
                sourceEntities = _repository.GetAdGrid(pageModel.CountryId);
                break;
            }

            if (sourceEntities == null)
            {
                throw new Exception(LOCALIZATION_AD_NOT_FOUND);
            }
            sourceEntities = _repository.OrderAdsByColumn(sourceEntities, pageModel.SortColumn);
            maxPrice       = (int)_repository.GetMaximumPriceForAd();
            count          = sourceEntities.Count;

            var entities = _repository.GetAdPage(sourceEntities, pageModel.PageIndex, pageModel.PageSize);

            if (entities == null)
            {
                throw new Exception(LOCALIZATION_AD_NOT_FOUND);
            }

            var list = AdMapper.MapToAdGridModel(entities);

            foreach (var ad in list)
            {
                ad.IsInWishlist = _wishlistRepository.Exists(ad.ID, pageModel.CurrentUser);
            }

            return(list);
        }