Пример #1
0
        public async Task <IActionResult> Create([Bind("PageID,GroupID,PageTitle,ShortDescription,PageText,PageVisit,ImageName,PageTags,ShowInSlider,CreateDate")] Page page, IFormFile imgup)
        {
            if (ModelState.IsValid)
            {
                page.PageVisit  = 0;
                page.CreateDate = DateTime.Now;

                if (imgup != null)
                {
                    page.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imgup.FileName);
                    string savePath = Path.Combine(
                        Directory.GetCurrentDirectory(), "wwwroot/PageImages", page.ImageName
                        );

                    using (var stream = new FileStream(savePath, FileMode.Create))
                    {
                        await imgup.CopyToAsync(stream);
                    }
                }

                _pageRepoitory.InsertPage(page);
                _pageRepoitory.Save();
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GroupID"] = new SelectList(_pageGroupRepository.GetAllPageGroups(), "GroupID", "GroupTitle", page.GroupID);
            return(View(page));
        }
Пример #2
0
        public IActionResult ShowNews(int newsId)
        {
            var page = pageRepoitory.GetPageById(newsId);

            if (page != null)
            {
                page.PageVisit += 1;
                pageRepoitory.UpdatePage(page);
                pageRepoitory.Save();
            }

            return(View(page));
        }