Esempio n. 1
0
        public IActionResult Articles()
        {
            var model = new ArticlesViewModel();

            model.Articles = new ArticleRepository().GetLatest();
            return(View(model));
        }
Esempio n. 2
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            if (!hasInitialization)
            {
                BindingContext = new ArticlesViewModel(position);

                this.ArticlesListView.ItemSelected += async delegate
                {
                    var articles = ArticlesListView.SelectedItem as Articles;
                    this.ArticlesListView.SelectedItem = null;
                    if (articles == null)
                    {
                        return;
                    }

                    var articlesDetails = new ArticlesDetailsPage(articles);

                    await NavigationService.PushAsync(Navigation, articlesDetails);
                };

                ViewModel.GetClientArticlesAsync();

                hasInitialization = true;
            }
            UpdatePage();
        }
Esempio n. 3
0
        /// <summary>
        /// Sets up the page with a binding context.
        /// </summary>
        public ArticlesPage(ArticlesViewModel viewModel)
        {
            InitializeComponent();

            // Setup binding context.
            BindingContext = this.viewModel = viewModel;
        }
Esempio n. 4
0
        public IActionResult Put([FromBody] ArticlesViewModel model)
        {
            // http status 500 (Server Error)
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            var artc = new Articles();

            // Properties

            artc.Title            = model.Title;
            artc.Article_text     = model.Article_text;
            artc.ArticleMid       = model.ArticleMid;
            artc.Article_Btm      = model.Article_Btm;
            artc.ArticleUrl       = model.ArticleUrl;
            artc.LastModifiedDate = DateTime.Now;
            artc.LastModifiedBy   = "CE1";

            // Add to db
            DbContext.Articles.Add(artc);
            _ = DbContext.SaveChanges();

            // Return
            return(new JsonResult(artc.Adapt <ArticlesViewModel>(),
                                  new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented
            }));
        }
Esempio n. 5
0
        public ActionResult AddArticle(ArticlesViewModel model)
        {
            bool isModelValid = CheckArticleModelValidity(model);

            if (!isModelValid)
            {
                model.IsUserAuthenticated = Session["UserCredentials"] != null;
                model.Articles            = GetArticlesListFromDatabase();
                return(View("Articles", model));
            }

            // in case that session would expire
            if (((UserCredentials)Session["UserCredentials"]) != null)
            {
                var username = ((UserCredentials)Session["UserCredentials"]).Username;
                model.Article.RegisteredUser  = _context.RegisteredUsers.First(user => user.Nickname == username);
                model.Article.PublicationDate = DateTime.Now;

                if (model.PhotosToInsertIDs != null)
                {
                    var photosToInsert = _context.Photos.Where(photo => model.PhotosToInsertIDs.Contains(photo.PhotoId)).ToList();

                    photosToInsert.ToList().ForEach(p => model.Article.Photos.Add(p));
                    _context.SaveChanges();
                }

                _context.Articles.Add(model.Article);
                _context.SaveChanges();
            }
            return(RedirectToAction("Articles"));
        }
Esempio n. 6
0
        // GET: Articles/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Articles articles = db.Articles.Find(id);

            if (articles == null)
            {
                return(HttpNotFound());
            }
            ArticlesViewModel articlesviewmodel = new ArticlesViewModel()
            {
                ID              = articles.ID,
                Titre_article   = articles.Titre_article,
                Description     = articles.Description,
                Contenu_article = articles.Contenu_article,
                Image           = articles.Image,
                Url_video       = articles.Url_video,
                Date_creation   = articles.Date_creation.Value,
                statu           = articles.statu
            };

            return(View(articlesviewmodel));
        }
Esempio n. 7
0
        // zrobione w ten sposób, aby wyświetlać wszystkie błędy bezpośrednio
        private bool CheckArticleModelValidity(ArticlesViewModel model)
        {
            bool validationResult = true;

            if (string.IsNullOrEmpty(model.Article.Title))
            {
                model.TitleErrorMessage = "~ Tytuł nie może być pusty";
                validationResult        = false;
            }
            else if (model.Article.Title.Length > 60)
            {
                model.TitleErrorMessage = "~ Tytuł jest za długi. Maksymalna liczba znaków to 60";
                validationResult        = false;
            }

            if (string.IsNullOrEmpty(model.Article.Content))
            {
                model.ContentErrorMessage = "~ Treść nie może być pusta";
                validationResult          = false;
            }
            else if (model.Article.Content.Length > 4000)
            {
                model.ContentErrorMessage = "~ Treść jest za długa. Maksymalna liczba znaków to 4000";
                validationResult          = false;
            }

            return(validationResult);
        }
Esempio n. 8
0
        public ActionResult InsertPhotosToArticle(InsertPhotosToArticleViewModel givenModel)
        {
            var photosToInsert = new List <Photo>();

            try
            {
                photosToInsert = _context.Photos.Where(photo => givenModel.PhotosToInsertIDs.Contains(photo.PhotoId)).ToList();
            }
            catch (Exception ex) {}

            var model = new ArticlesViewModel
            {
                IsUserAuthenticated = Session["UserCredentials"] != null,
                Articles            = GetArticlesListFromDatabase(),
                PhotosToInsert      = photosToInsert,
                Article             = givenModel.Article
            };

            // if id is not 0 -> some article came from photo management
            if (givenModel.Article != null && givenModel.Article.ArticleId != 0)
            {
                model.HeaderMode = HeaderModes.EDIT;
            }

            return(View("Articles", model));
        }
Esempio n. 9
0
        public ActionResult EditArticle(ArticlesViewModel model)
        {
            bool isModelValid = CheckArticleModelValidity(model);

            if (!isModelValid)
            {
                model.IsUserAuthenticated = Session["UserCredentials"] != null;
                model.Articles            = GetArticlesListFromDatabase();
                return(View("Articles", model));
            }

            var articleToUpdate = _context.Articles.First(art => art.ArticleId == model.Article.ArticleId);

            articleToUpdate.Title   = model.Article.Title;
            articleToUpdate.Content = model.Article.Content;

            // to reset photos before new inserts, and in case that user didn't selected any photo
            articleToUpdate.Photos.Clear();

            if (model.PhotosToInsertIDs != null && model.PhotosToInsertIDs.Count > 0)
            {
                var photosToInsert = _context.Photos.Where(photo => model.PhotosToInsertIDs.Contains(photo.PhotoId)).ToList();
                photosToInsert.ToList().ForEach(p => articleToUpdate.Photos.Add(p));
            }

            _context.SaveChanges();

            return(RedirectToAction("Articles"));
        }
Esempio n. 10
0
        public ArticlesViewModel GetArticlesViewModel(int?categoryId, int?tagId, DateTime?start, DateTime?end, int page)
        {
            var listArticles  = GetArticlesModelCollection();
            var filterArticle = categoryId == null ? listArticles : listArticles.Where(i => i.Category.CategoryId == categoryId);

            filterArticle = tagId == null ? filterArticle : GetArticlesModelCollectionByTag(tagId.Value, filterArticle);
            filterArticle = start != null && end != null
                ? GetArticlesModelCollectionByDate(start.Value, end.Value, filterArticle)
                : filterArticle;

            var articlesModel = new ArticlesViewModel
            {
                Articles = filterArticle
                           .OrderBy(article => article.ArticleId)
                           .Skip((page - 1) * pageSize)
                           .Take(pageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = filterArticle.Count()
                }
            };

            return(articlesModel);
        }
Esempio n. 11
0
        public ActionResult Edit(byte?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Article article = _dbContext.Articles.Find(id);

            var viewModel = new ArticlesViewModel
            {
                Categories = _dbContext.Categories.ToList(),
                Header     = article.Header,
                Content    = article.Content,
                DateTime   = article.DateTime,
                CategoryId = article.CategoryId,
                Image      = article.Image,
                Id         = article.Id
            };

            if (viewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(viewModel));
        }
Esempio n. 12
0
        public async Task <IActionResult> Index()
        {
            var userId   = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var articles = await _unitService.Article.GetUserTutorialsAsync(Guid.Parse(userId));

            var articlesViewModel = new List <ArticlesViewModel>();

            foreach (var article in articles)
            {
                var categories = await _unitService.ArticleCategory.getCategoryByArticleIdAsync(article.Id);

                var categoryList = new List <Category>();
                foreach (var item in categories)
                {
                    var category = await _unitService.Category.GetByIdAsync(item.CategoryId);

                    categoryList.Add(category);
                }

                ArticlesViewModel ArticleCategory = new ArticlesViewModel()
                {
                    Id           = article.Id,
                    Title        = article.Title,
                    Category     = categoryList,
                    PostCategory = article.PostCategory,
                    Row          = article.Row,
                    CreatedDate  = article.CreatedDate,
                    UpdateDate   = article.UpdateDate
                };

                articlesViewModel.Add(ArticleCategory);
            }
            return(View(articlesViewModel));
        }
        public ActionResult Index()
        {
            var vm = new ArticlesViewModel();

            vm.Articles = _repository.GetAllArticle();

            return(View(vm));
        }
Esempio n. 14
0
        public ArticlesPage()
        {
            InitializeComponent();

            BindingContext = viewModel = new ArticlesViewModel();

            viewModel.LoadMessagePageList();
        }
Esempio n. 15
0
        public async Task <IActionResult> AddPicture(ArticlesViewModel articlesViewModel)
        {
            if (ModelState.IsValid)
            {
                await _articleRepository.AddPictureOnArticle(articlesViewModel);
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 16
0
        public IActionResult AddComment(ArticlesViewModel articlesViewModel)
        {
            if (ModelState.IsValid)
            {
                _articleRepository.AddCommentOnArticle(articlesViewModel);
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 17
0
        public IActionResult Index()
        {
            var news = new ArticlesViewModel()
            {
                Articles = _articleRepository.GetTenNewestArticles()
            };

            return(View(news));
        }
Esempio n. 18
0
        public ActionResult Create()
        {
            var viewModel = new ArticlesViewModel
            {
                Categories = _dbContext.Categories.ToList()
            };

            return(View(viewModel));
        }
Esempio n. 19
0
        public ActionResult Index(ArticlesViewModel model)
        {
            int totalItem;
            var allCategory = _artilesService.GetData(model.Title, model.PageIndex, model.PageSize, out totalItem, (int)TypeArticle.SanPham).ToList();

            model.TotalItem = totalItem;
            model.ListData  = allCategory;
            return(View(model));
        }
        public ActionResult PostPage()
        {
            ArticlesViewModel model = new ArticlesViewModel
            {
                Channels = context.Channels.ToList(),
            };

            return(View(model));
        }
Esempio n. 21
0
        /// <summary>
        /// Init start-up pages here
        /// </summary>
        void SetupPages()
        {
            var detail_vm = new ArticlesViewModel(new NewsCategory {
                CategoryName = topstories
            });
            var master_vm    = new MenuViewModel();
            var bootstrapper = new NewsAppBootsrap();

            bootstrapper.SetupMasterDetailApp(master_vm, detail_vm);
        }
Esempio n. 22
0
        public ActionResult ArticlesMore()
        {
            ArticlesViewModel articlesViewModel = new ArticlesViewModel
            {
                Articles           = repoArticle.Articles().OrderBy(x => Guid.NewGuid()).Take(4).ToList(),
                ContentExternalUrl = repoConfig.Get(ConfigurationKeyStatic.CONTENT_EXTERNAL_URL)
            };

            return(View(articlesViewModel));
        }
Esempio n. 23
0
        public ActionResult Index(string searching)
        {
            var articles = _iArticleService.GetArticlesByName(searching);
            var model    = new ArticlesViewModel()
            {
                Articles = articles
            };

            return(View(model));
        }
        //
        // GET: /Article/
        public ActionResult Index()
        {
            ArticlesViewModel viewModel =
                new ArticlesViewModel()
            {
                Articles = _articles.RetrieveAll(),
                Authors  = null
            };

            return(View(viewModel));
        }
Esempio n. 25
0
        public async Task <IActionResult> OnGetAsync(Guid?pageId = null)
        {
            if (pageId != null)
            {
                PageId             = pageId;
                ViewData["PageId"] = PageId;
                AddArticleUrl      = "/WebPage/Articles/Add";
                UpdateArticleUrl   = "/WebPage/Articles/Update";

                var page = await _webPagesService.FindByIdAllIncludedAsync(pageId);

                if (page == null)
                {
                    return(NotFound());
                }

                Vm = new ArticlesViewModel
                {
                    Articles = page.Articles.OrderBy(a => a.Name).Select(a => new ArticleDto
                    {
                        Id              = a.Id,
                        Name            = a.Name,
                        DateTimeCreated = $"{a.DateTimeCreated?.ToShortDateString()} - ({a.DateTimeCreated?.ToShortTimeString()})"
                    }).ToList()
                };
            }
            else
            {
                AddArticleUrl    = "/Articles/Add";
                UpdateArticleUrl = "/Article/Index";

                var articles = await Service.GetAll().Include(a => a.Webpage)
                               .Include(a => a.Images)
                               .ToListAsync();

                Vm = new ArticlesViewModel
                {
                    Articles = articles.OrderBy(a => a.Name).Select(a => new ArticleDto
                    {
                        Id              = a.Id,
                        Name            = a.Name,
                        DateTimeCreated = $"{a.DateTimeCreated?.ToShortDateString()} - ({a.DateTimeCreated?.ToShortTimeString()})"
                    }).ToList()
                };
            }

            PageTitle = await TranslationsService.TranslateAsync("Artikels");

            TxtName = await TranslationsService.TranslateAsync("Name");

            TxtAddedOn = await TranslationsService.TranslateAsync("Toegevoegd op");

            return(Page());
        }
        public ActionResult PostPage(ArticlesViewModel model, [System.Web.Http.FromBody] string selectedChannel, [System.Web.Http.FromBody] int sortBy)
        {
            HttpWebRequest  request        = (HttpWebRequest)WebRequest.Create("http://localhost:54733/api/Articles/?selectedChannel=" + selectedChannel + "&selectedSort=" + sortBy);
            HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
            string          responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            List <Article>  articles       = JsonConvert.DeserializeObject <Article[]>(responseString).ToList();

            model.Channels = context.Channels.ToList();
            model.Articles = articles;
            return(View(model));
        }
Esempio n. 27
0
        public async Task AddArticle(ArticlesViewModel item)
        {
            var newArticle = new Article()
            {
                Title   = item.Title,
                Content = item.Content,
                Author  = item.Author
            };

            await _context.Articles.InsertOneAsync(newArticle);
        }
Esempio n. 28
0
        public ActionResult Index()
        {
            var articles = _iArticleService.GetFirstArticles();

            var model = new ArticlesViewModel()
            {
                Articles = articles
            };

            return(View(model));
        }
Esempio n. 29
0
        public PrendreArticle()
        {
            InitializeComponent();
            ArticlesViewModel vm = new ArticlesViewModel();

            this.DataContext = vm;
            if (vm.CloseAction == null)
            {
                vm.CloseAction = new Action(this.Close);
            }
        }
Esempio n. 30
0
        // GET: HelloWorld
        public ActionResult Index()
        {
            var hw        = WAFContext.Request.GetContent <HelloWorld>();
            var viewModel = new ArticlesViewModel();

            viewModel.Name = hw.Name;
            // viewModel.Articles = WAFContext.Session.GetContents<ArticleBase>(); // Ikke måten å gjøre det på.
            viewModel.Articles = WAFContext.Session.Query <ArticleBase>().OrderBy(AqlArticleBase.Name, false).Execute();
            viewModel.Content  = hw;
            return(View(viewModel));
        }
        public ActionResult Destroy([DataSourceRequest]DataSourceRequest request, ArticlesViewModel model)
        {
            this.Delete<Article>(model);

            return this.GridOperation(model, request);
        }