Beispiel #1
0
        public IActionResult Shownews(int newsid)
        {
            var page = pageRepository.GetPageById(newsid);

            if (page != null)
            {
                page.PageVisit += 1;
                pageRepository.UpdatePage(page);
                pageRepository.Save();
            }
            return(View(page));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("PageID,GroupID,PageTitle,ShortDescription,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/Image", page.ImageName);
                        using (var stream = new FileStream(savepath, FileMode.Create))
                        {
                            await Imgup.CopyToAsync(stream);
                        }
                    }

                    PageRepository.UpdatePage(page);
                    PageRepository.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PageExists(page.PageID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GroupID"] = new SelectList(PageGroupRepository.GetAllPageGroup(), "GroupID", "GroupTitle", page.GroupID);
            return(View(page));
        }