Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("PageID,GroupID,PageTitle,ShortDescription,PageText,PageVisit,ImageName,PageTags,ShowInSlider,CreateDate")] Page page, IFormFile imgup)
        {
            if (id != page.PageID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (imgup != null)
                    {
                        if (page.ImageName == 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.UpdatePage(page);
                    _pageRepoitory.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PageExists(page.PageID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GroupID"] = new SelectList(_pageGroupRepository.GetAllPageGroups(), "GroupID", "GroupTitle", page.GroupID);
            return(View(page));
        }