public async Task <IHttpActionResult> GetRelatedArticles(int id)
        {
            ArticlesProvider           articlesProvider = new ArticlesProvider();
            IEnumerable <ArticleModel> relatedArticles  = await articlesProvider.GetRelatedArticles(id);

            if (relatedArticles == null)
            {
                return(this.NotFound());
            }

            return(this.Ok(relatedArticles));
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> GetLikedArticles()
        {
            ArticlesProvider           articlesProvider = new ArticlesProvider();
            IEnumerable <ArticleModel> likedArticles    = await articlesProvider.GetLikedArticles(new Guid(this.User.Identity.GetUserId()));

            if (likedArticles == null)
            {
                return(this.NotFound());
            }

            return(this.Ok(likedArticles));
        }
        public async Task <bool> ValidateOrderedItem(OrderedItemModel orderedItem)
        {
            ArticlesProvider articlesProvider  = new ArticlesProvider();
            Task <bool>      articleExistsTask = articlesProvider.HasArticleWithPrice(orderedItem.ArticleId.Value, orderedItem.Price.Value);

            StocksProvider stocksProvider = new StocksProvider();
            Task <bool>    hasStocksTask  = stocksProvider.HasEnoughStocksOfArticle(orderedItem.ArticleId.Value, orderedItem.SizeId.Value, orderedItem.ColorId, orderedItem.Quantity.Value);

            bool articleExists   = await articleExistsTask;
            bool hasEnoughStocks = await hasStocksTask;

            bool isOrderValid = articleExists && hasEnoughStocks;

            return(isOrderValid);
        }
Esempio n. 4
0
        public ArticlesProviderTest()
        {
            errorListProvider  = new ErrorListProvider();
            articlesAccessMock = new Mock <IArticlesAccess>();
            articlesProvider   = new ArticlesProvider(articlesAccessMock.Object, errorListProvider);

            articleDTOMock = new ArticleDTO()
            {
                ArticleHeader = new ArticleHeader()
                {
                    Name = "TestFileName"
                }, ArticleContent = "TestTextMock"
            };
            articleMock = new Article()
            {
                Name = "TestFileName", ArticleContent = "TestTextMock"
            };
        }
Esempio n. 5
0
        public async Task <IHttpActionResult> GetDiscountedArticles()
        {
            Guid?currentUserId = null;

            if (this.User.Identity.IsAuthenticated)
            {
                currentUserId = new Guid(this.User.Identity.GetUserId());
            }

            ArticlesProvider           articlesProvider   = new ArticlesProvider();
            IEnumerable <ArticleModel> discountedArticles = await articlesProvider.GetDiscountedArticles(currentUserId);

            if (discountedArticles == null)
            {
                return(this.NotFound());
            }

            return(this.Ok(discountedArticles));
        }
Esempio n. 6
0
        public async Task <IHttpActionResult> Get(int collectionId)
        {
            Guid?currentUserId = null;

            if (this.User.Identity.IsAuthenticated)
            {
                currentUserId = new Guid(this.User.Identity.GetUserId());
            }

            ArticlesProvider           articlesProvider     = new ArticlesProvider();
            IEnumerable <ArticleModel> articlesInCollection = await articlesProvider.GetArticlesInCollection(collectionId, currentUserId);

            if (articlesInCollection == null)
            {
                return(this.NotFound());
            }

            return(this.Ok(articlesInCollection));
        }
Esempio n. 7
0
        public async Task <IHttpActionResult> Get(string categoryUrl, string orderBy, SortDirection sortDirection, string filter = null)
        {
            Guid?currentUserId = null;

            if (this.User.Identity.IsAuthenticated)
            {
                currentUserId = new Guid(this.User.Identity.GetUserId());
            }

            ArticlesProvider  articlesProvider = new ArticlesProvider();
            ArticlesListModel articlesList     = await articlesProvider.GetArticlesInCategory(categoryUrl, filter, orderBy, sortDirection, currentUserId);

            if (articlesList == null)
            {
                return(this.NotFound());
            }

            return(this.Ok(articlesList));
        }
Esempio n. 8
0
        public IHttpActionResult Get(string urlName)
        {
            Guid?currentUserId = null;

            if (this.User.Identity.IsAuthenticated)
            {
                currentUserId = new Guid(this.User.Identity.GetUserId());
            }

            ArticlesProvider articlesProvider = new ArticlesProvider();

            FullArticleModel articleModel = articlesProvider.GetFullArticleByUrlName(urlName, currentUserId);

            if (articleModel == null)
            {
                return(this.NotFound());
            }

            return(this.Ok(articleModel));
        }
Esempio n. 9
0
        public IEnumerable <ArticleModel> AssembleItems(IEnumerable <Document> indexDocuments)
        {
            Dictionary <int, int> articlesOrderMap = new Dictionary <int, int>();
            int documentIndex = 0;

            foreach (Document document in indexDocuments)
            {
                articlesOrderMap.Add(int.Parse(document.Get("Id")), documentIndex++);
            }

            if (articlesOrderMap.Count == 0)
            {
                return(new List <ArticleModel>());
            }

            IEnumerable <int>          articleIds       = articlesOrderMap.Keys;
            ArticlesProvider           articlesProvider = new ArticlesProvider();
            IEnumerable <ArticleModel> foundArticles    = articlesProvider.GetArticlesByIds(articleIds).OrderBy(a => articlesOrderMap[a.Id]).ToList();

            return(foundArticles);
        }
Esempio n. 10
0
 public LikesMediator(ArticlesProvider articlesProvider, UserLikesProvider userLikesProvider)
 {
     this.articlesProvider  = articlesProvider;
     this.userLikesProvider = userLikesProvider;
 }
 protected override async Task ExecuteCore(CancellationToken cancellationToken, IEnumerable <ArticleOrderCountModel> context)
 {
     ArticlesProvider articlesProvider = new ArticlesProvider();
     await articlesProvider.UpdateOrdersCounts(context);
 }