예제 #1
0
 public bool DeletePage(PagesTB pages)
 {
     try
     {
         _db.Remove(pages);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #2
0
 public bool InsertPage(PagesTB page)
 {
     try
     {
         _db.Add(page);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #3
0
 public bool UpdatePage(PagesTB pages)
 {
     try
     {
         _db.Update(pages);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("PageID,Title,ShortDescription,Text,ImageName,CreateDate,Visist,Like,GroupID")] PagesTB pagesTB, IFormFile imgPage)
        {
            if (id != pagesTB.PageID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (imgPage != null)
                    {
                        pagesTB.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imgPage.FileName);
                        string savepath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/", pagesTB.ImageName);
                        System.IO.File.Delete(savepath);
                        using (var stream = new FileStream(savepath, FileMode.Create))
                        {
                            imgPage.CopyTo(stream);
                        }
                    }
                    _pageRepository.UpdatePage(pagesTB);
                    await _pageRepository.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PagesTBExists(pagesTB.PageID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.Groups = new SelectList(await _groupRepository.GetAllGroups(), "GroupID", "Title");
            return(View(pagesTB));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("PageID,Title,ShortDescription,Text,ImageName,CreateDate,Visist,Like,GroupID")] PagesTB pagesTB, IFormFile imgPage)
        {
            if (ModelState.IsValid)
            {
                pagesTB.Like       = 0;
                pagesTB.Visist     = 0;
                pagesTB.CreateDate = DateTime.Now;
                if (imgPage != null)
                {
                    pagesTB.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imgPage.FileName);
                    string savepath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/", pagesTB.ImageName);
                    using (var st = new FileStream(savepath, FileMode.Create))
                    {
                        imgPage.CopyTo(st);
                    }
                }
                _pageRepository.InsertPage(pagesTB);
                await _pageRepository.Save();

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.Groups = new SelectList(await _groupRepository.GetAllGroups(), "GroupID", "Title");
            return(View(pagesTB));
        }