public bool DeletePage(PagesTB pages) { try { _db.Remove(pages); return(true); } catch { return(false); } }
public bool InsertPage(PagesTB page) { try { _db.Add(page); return(true); } catch { return(false); } }
public bool UpdatePage(PagesTB pages) { try { _db.Update(pages); return(true); } catch { return(false); } }
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)); }
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)); }