コード例 #1
0
        // GET: Articles
        public ActionResult Index()
        {
            int i = 0;

            if (HttpContext.Session["ListAttach" + i] != null)
            {
                while (HttpContext.Session["ListAttach" + i] != null)
                {
                    HttpContext.Session["ListAttach" + i] = null;
                    i++;
                }
            }
            ArticlesListViewModel model = new ArticlesListViewModel();

            model.CurrentLang = Thread.CurrentThread.CurrentUICulture.ToString().ToLower();
            model.ListArticle = BusinessManagement.Article.GetListArticle();
            List <List <DBO.Translation> > translations = new List <List <DBO.Translation> >();

            if (!model.CurrentLang.Equals("fr-fr"))
            {
                foreach (var article in model.ListArticle)
                {
                    translations.Add(BusinessManagement.Translation.GetListValidatedTranslationByArticle(article.Id));
                }
            }
            model.ListTranslations = translations;
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Index(ArticlesListViewModel articlesListViewModel)
        {
            var articles = new List <Article>();

            try
            {
                articles = await apiClient.Articles.GetAll(new ApiService.Models.SearchQueries.ArticleSearchQuery
                {
                    Title = articlesListViewModel.ArticleSearchQuery != null ? articlesListViewModel.ArticleSearchQuery.Title : null
                });
            }
            catch (ApiException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    return(View(articlesListViewModel));
                }

                articlesListViewModel.Error = articlesListViewModel.Error = new Error {
                    Message = "მოხდა შეცდომა, გთხოვთ სცადოთ მოგვიანებით"
                };
                return(View(articlesListViewModel));
            }


            if (articles != null && articles.Count > 0)
            {
                var result = _mapper.Map <List <Article>, List <ArticleViewModel> >(articles);
                articlesListViewModel.Articles = result;
            }
            return(View(articlesListViewModel));
        }
コード例 #3
0
        //
        //GET: /Admin/Article/List
        public ActionResult List(int CategoryId = 0)
        {
            ViewBag.SelectedPage = Navigator.Items.LISTARTICLES;
            ArticlesListViewModel view_model = new ArticlesListViewModel()
            {
                CategoryId = CategoryId
            };

            FillArticleCategories(CategoryId);
            return(View(view_model));
        }
コード例 #4
0
        // GET: /<controller>/
        public IActionResult List()
        {
            //ViewBag.CurrentCategory = "Modern Art";

            //return View(_articleRepository.AllArticles);
            ArticlesListViewModel articlesListViewModel = new ArticlesListViewModel();

            articlesListViewModel.Articles = _articleRepository.AllArticles;

            articlesListViewModel.CurrentCategory = "Modern Art";
            return(View(articlesListViewModel));
        }
コード例 #5
0
        public Detail(ArticlesListViewModel model)
        {
            InitializeComponent();

            HurriyetApi api          = new HurriyetApi();
            var         articlesJson = api.Get($"v1/articles/{model.Id}");

            JsonModelMapper <ArticlesDetailModel> jsonModel = new JsonModelMapper <ArticlesDetailModel>();
            var article = jsonModel.GetItem(articlesJson);

            cvImages.ItemsSource = article.Files;
            lblTitle.Text        = article.Title;
        }
コード例 #6
0
        private async void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return;
            }

            ArticlesListViewModel selectedItem = (ArticlesListViewModel)e.SelectedItem;

            //navigate to Detail page
            await Navigation.PushModalAsync(new Detail(selectedItem));

            var lv = (ListView)sender;

            lv.SelectedItem = null;
        }
コード例 #7
0
        // /Article/FullVersionArticle
        public ActionResult FullVersionArticle(int fullId, string slug)
        {
            ArticlesListViewModel article = new ArticlesListViewModel
            {
                Articles = repository.Articles.Where(a => a.ArticleId == fullId)
            };

            if (article != null)
            {
                return(View(article));
            }
            else
            {
                return(View("Error"));
            }
        }
コード例 #8
0
        public ActionResult List(string category, int page = 1)
        {
            ArticlesListViewModel model = new ArticlesListViewModel
            {
                Articles = articles.GetArticlesForMainPage(PageSize, category, page),

                PageInfo = new PageInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = articles.GetCountArtiles(category)
                },
                CurrentCategory = category
            };

            return(View(model));
        }
コード例 #9
0
        // /Article/ListArticles
        public ViewResult ListArticles(string category, string searchString, int page = 1)
        {
            if (!String.IsNullOrEmpty(searchString))
            {
                ArticlesListViewModel model1 = new ArticlesListViewModel
                {
                    Articles = repository.Articles
                               .Where(a => a.TitlePost.ToLower().Contains(searchString.ToLower()))
                               .OrderByDescending(a => a.Date)
                               .Skip((page - 1) * pageSize)
                               .Take(pageSize),

                    PagingInfo = new PagingInfo
                    {
                        CurrentPage  = page,
                        ItemsPerPage = pageSize,
                        TotalItems   = category == null?
                                       repository.Articles.Count() :
                                           repository.Articles.Where(article => article.Category == category).Count()
                    },
                    CurrentCategory = category
                };
                return(View(model1));
            }

            ArticlesListViewModel model = new ArticlesListViewModel
            {
                Articles = repository.Articles
                           .Where(a => category == null || a.Category == category)
                           .OrderByDescending(a => a.Date)
                           .Skip((page - 1) * pageSize)
                           .Take(pageSize),

                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = category == null?
                                   repository.Articles.Count() :
                                       repository.Articles.Where(article => article.Category == category).Count()
                },
                CurrentCategory = category
            };

            return(View(model));
        }
コード例 #10
0
        public ViewResult List(int page = 1)
        {
            ArticlesListViewModel viewModel = new ArticlesListViewModel
            {
                Articles = repository.Articles
                           .OrderByDescending(a => a.Date)
                           .Skip((page - 1) * PageSize)
                           .Take(PageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = repository.Articles.Count()
                },
            };

            return(View(viewModel));
        }
コード例 #11
0
        public async Task <IActionResult> Delete(int Id)
        {
            try
            {
                await apiClient.Articles.Delete(Id);

                return(RedirectToAction("Index"));
            }
            catch (ApiException ex)
            {
                var articleListViewModel = new ArticlesListViewModel();
                if (ex.StatusCode == System.Net.HttpStatusCode.BadRequest)
                {
                    articleListViewModel.Error.Message = $"განცხადება {Id} აიდით არ არსებობს";
                    return(RedirectToAction("Index", articleListViewModel));
                }
                articleListViewModel.Error.Message = "მოხდა უცნობი შეცდომა, გთხოვთ სცადოთ მოგვიანებით";
                return(RedirectToAction("Index", articleListViewModel));
            }
        }
コード例 #12
0
        public ViewResult Index(string category, int page = 1)
        {
            ArticlesListViewModel viewModel = new ArticlesListViewModel
            {
                Articles = repository.Articles
                           .Where(a => category == null || a.Category == category)
                           .OrderByDescending(a => a.ArticleID)
                           .Skip((page - 1) * PageSize)
                           .Take(PageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = category == null?
                                   repository.Articles.Count() :
                                       repository.Articles.Where(e => e.Category == category).Count()
                },
                CurrentCategory = category
            };

            return(View(viewModel));
        }
コード例 #13
0
ファイル: BlogController.cs プロジェクト: Icaka99/FitnessCare
        public IActionResult List(SearchStringInputModel input, int id)
        {
            if (id == 0)
            {
                id = 1;
            }

            var articles        = this.articleService.GetSearchedArticles(input, id, ItemsPerPage);
            var orderedArticles = this.articleService.GetAllOrderedArticles();

            var model = new ArticlesListViewModel
            {
                Articles        = articles,
                ArticlesCount   = articles.Count(),
                ItemsPerPage    = ItemsPerPage,
                PageNumber      = id,
                OrderedArticles = orderedArticles,
                SearchString    = input.SearchString,
                Categories      = this.categoryService.GetRandomCategories(6),
            };

            return(this.View(nameof(this.Blog), model));
        }
コード例 #14
0
ファイル: BlogController.cs プロジェクト: Icaka99/FitnessCare
        public IActionResult Blog(int id)
        {
            if (id == 0)
            {
                id = 1;
            }

            var articles        = this.articleService.GetArticles(id, ItemsPerPage);
            var orderedArticles = this.articleService.GetAllOrderedArticles();

            var model = new ArticlesListViewModel
            {
                ItemsPerPage    = ItemsPerPage,
                ArticlesCount   = this.articleService.GetCount(),
                Articles        = articles,
                OrderedArticles = orderedArticles,
                PageNumber      = id,
                SearchString    = null,
                Categories      = this.categoryService.GetRandomCategories(6),
            };

            return(this.View(model));
        }
コード例 #15
0
        public void CallGetPageMethod_WhenParamsAreValid()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var articleMock       = new Article();
            var mappedArticleMock = new ArticleItemViewModel();
            var modelMock         = new ArticlesListViewModel();

            var articlesMock = new List <Article>()
            {
                articleMock
            };
            var mappedArticlesMock = new List <ArticleItemViewModel>()
            {
                mappedArticleMock
            };

            articleServiceMock.Setup(x => x.GetPagesCount(It.IsAny <string>())).Returns(1);
            utilsMock.Setup(x => x.GetPage(It.IsAny <int?>(), It.IsAny <int>())).Returns(1);
            articleServiceMock.Setup(x => x.GetFilteredArticlesByPage(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())).Returns(articlesMock);
            mappingServiceMock.Setup(x => x.Map <IEnumerable <ArticleItemViewModel> >(It.IsAny <IEnumerable <Article> >())).Returns(mappedArticlesMock);
            mappingServiceMock.Setup(x => x.Map <ArticlesListViewModel>(It.IsAny <IEnumerable <ArticleItemViewModel> >())).Returns(modelMock);
            utilsMock.Setup(x => x.AssignViewParams <ArticlesListViewModel>(It.IsAny <ArticlesListViewModel>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(modelMock);

            // Act
            controller.Index(null, null);

            // Assert
            utilsMock.Verify(x => x.GetPage(It.IsAny <int?>(), It.IsAny <int>()), Times.Once);
        }
コード例 #16
0
        public void ReturnDefaultViewWithCorrectModel_WhenParamsAreValid()
        {
            // Arrange
            var articleServiceMock = new Mock <IArticleService>();
            var mappingServiceMock = new Mock <IMappingService>();
            var storeServiceMock   = new Mock <IStoreService>();
            var userServiceMock    = new Mock <IUserService>();
            var utilsMock          = new Mock <IUtilitiesService>();

            var controller = new ArticlesController(articleServiceMock.Object, mappingServiceMock.Object, storeServiceMock.Object, userServiceMock.Object, utilsMock.Object);

            var articleMock       = new Article();
            var mappedArticleMock = new ArticleItemViewModel();
            var modelMock         = new ArticlesListViewModel();

            var articlesMock = new List <Article>()
            {
                articleMock
            };
            var mappedArticlesMock = new List <ArticleItemViewModel>()
            {
                mappedArticleMock
            };

            articleServiceMock.Setup(x => x.GetPagesCount(It.IsAny <string>())).Returns(1);
            utilsMock.Setup(x => x.GetPage(It.IsAny <int?>(), It.IsAny <int>())).Returns(1);
            articleServiceMock.Setup(x => x.GetFilteredArticlesByPage(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())).Returns(articlesMock);
            mappingServiceMock.Setup(x => x.Map <IEnumerable <ArticleItemViewModel> >(It.IsAny <IEnumerable <Article> >())).Returns(mappedArticlesMock);
            mappingServiceMock.Setup(x => x.Map <ArticlesListViewModel>(It.IsAny <IEnumerable <ArticleItemViewModel> >())).Returns(modelMock);
            utilsMock.Setup(x => x.AssignViewParams <ArticlesListViewModel>(It.IsAny <ArticlesListViewModel>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(modelMock);

            // Act & Assert
            controller.WithCallTo(x => x.Index(null, null))
            .ShouldRenderDefaultView()
            .WithModel <ArticlesListViewModel>();
        }
コード例 #17
0
        public async Task <IActionResult> Update(int Id)
        {
            try
            {
                var existingArticle = await apiClient.Articles.Get(Id);

                var result = _mapper.Map <Article, ArticleViewModel>(existingArticle);

                if (existingArticle != null)
                {
                    return(View(result));
                }

                var articleListViewModel = new ArticlesListViewModel();
                articleListViewModel.Error.Message = $"განცხადება {Id} აიდით არ არსებობს";
                return(RedirectToAction("Index", articleListViewModel));
            }
            catch
            {
                var articleListViewModel = new ArticlesListViewModel();
                articleListViewModel.Error.Message = "მოხდა შეცდომა";
                return(RedirectToAction("Index", articleListViewModel));
            }
        }
コード例 #18
0
        public async Task <IActionResult> Update(ArticleViewModel article, IFormFile Image)
        {
            if (string.IsNullOrEmpty(article.Title))
            {
                article.Exception.Message = "სათაური აუცილებელია!";

                return(View(article));
            }

            if (string.IsNullOrEmpty(article.Phone) || (!string.IsNullOrEmpty(article.Phone) && article.Phone.Any(x => !char.IsDigit(x))))
            {
                article.Exception.Message = "ტელეფონის ნომერი აუცილებელია და უნდა შეიცავდეს მხოლოდ ციფრებს";

                return(View(article));
            }

            try
            {
                var existingArticle = await apiClient.Articles.Get(article.Id);


                if (existingArticle != null)
                {
                    var result = _mapper.Map <ArticleViewModel, Article>(article);


                    if (Image != null)
                    {
                        using (var stream = new MemoryStream())
                        {
                            await Image.CopyToAsync(stream);

                            result.Image = stream.ToArray();
                        }
                    }
                    else
                    {
                        result.Image = existingArticle.Image != null ? existingArticle.Image : null;
                    }

                    await apiClient.Articles.Update(result);

                    return(RedirectToAction("Index"));
                }

                var articleListViewModel = new ArticlesListViewModel();
                articleListViewModel.Error.Message = $"განცხადება {article.Id} აიდით არ არსებობს";
                return(RedirectToAction("Index", articleListViewModel));
            }
            catch (ApiException ex)
            {
                var articleListViewModel = new ArticlesListViewModel();
                if (ex.StatusCode == System.Net.HttpStatusCode.BadRequest)
                {
                    articleListViewModel.Error.Message = $"განცხადება {article.Id} აიდით არ არსებობს";
                    return(RedirectToAction("Index", articleListViewModel));
                }
                articleListViewModel.Error.Message = "მოხდა შეცდომა";
                return(RedirectToAction("Index", articleListViewModel));
            }
        }
コード例 #19
0
        public ArticlesListPage()
        {
            InitializeComponent();

            BindingContext = viewModel = Container.Instance.ServiceProvider.GetRequiredService <ArticlesListViewModel>();
        }
コード例 #20
0
        public ArticlesListPage(string editionId)
        {
            InitializeComponent();

            BindingContext = viewModel = new ArticlesListViewModel(editionId);
        }