// GET: api/Boards public List <Board> Get() { List <Board> list = new List <Board>(); using (var db = new BoardSystemContext()) { try { list = getList(0); } catch { } } return(list); }
// DELETE: api/Boards/5 public void Delete(int boardNum) { using (var db = new BoardSystemContext()) { Board board; try { board = db.Boards.Find(boardNum); db.Boards.Remove(board); db.SaveChanges(); } catch { } } }
private List <Board> getList(int page) { using (var db = new BoardSystemContext()) { List <Board> list; if (page == 0) { list = db.Boards.OrderByDescending(s => s.BoardNum).Take(20).ToList(); } else { list = db.Boards.OrderByDescending(s => s.BoardNum).Skip(20 + (page - 1) * 10).Take(10).ToList(); } return(list); } }
public IActionResult Register(User model) { if (ModelState.IsValid) { using (var db = new BoardSystemContext()) { db.Users.Add(model); try { db.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex); return(RedirectToAction("Error", "Home")); } } return(RedirectToAction("Index", "Home")); } return(View(model)); }
// GET: /<controller>/ public IActionResult Index() { if (HttpContext.Session.GetString("USER_LOGIN_KEY") == null) { return(RedirectToAction("Login", "Account")); } using (var db = new BoardSystemContext()) { List <Board> list; try { list = getList(0); } catch { return(RedirectToAction("Error", "Home")); } return(View(list)); } }
public IActionResult DeleteComment(int boardNum, int commentNum) { if (HttpContext.Session.GetString("USER_LOGIN_KEY") == null) { return(RedirectToAction("Login", "Account")); } using (var db = new BoardSystemContext()) { Comment comment; try { comment = db.Comments.Find(commentNum); db.Comments.Remove(comment); db.SaveChanges(); } catch { return(RedirectToAction("Error", "Home")); } return(Redirect("Detail?boardNum=" + boardNum)); } }
// POST: api/Boards public void Post([System.Web.Http.FromBody] Board board) { if (ModelState.IsValid) { using (var db = new BoardSystemContext()) { try { db.Boards.Add(board); if (db.SaveChanges() > 0) { // return Redirect("Index"); } } catch { // return RedirectToAction("Error", "Home"); } } ModelState.AddModelError(string.Empty, "投稿できません。"); } }
public IActionResult Delete(int boardNum) { if (HttpContext.Session.GetString("USER_LOGIN_KEY") == null) { return(RedirectToAction("Login", "Account")); } using (var db = new BoardSystemContext()) { Board board; try { board = db.Boards.Find(boardNum); db.Boards.Remove(board); db.SaveChanges(); } catch { return(RedirectToAction("Error", "Home")); } return(Redirect("Index")); } }
public string Post([FromBody] User user, int id) { User loginUser = null; string login = "******"; using (var db = new BoardSystemContext()) { try { loginUser = db.Users.FirstOrDefault(u => u.UserId.Equals(user.UserId) && u.UserPassword.Equals(user.UserPassword)); if (loginUser != null) { login = "******"; } } catch { //return RedirectToAction("Error", "Home"); } } Console.Write(user); return(login); }
public IActionResult Detail(int boardNum) { if (HttpContext.Session.GetString("USER_LOGIN_KEY") == null) { return(RedirectToAction("Login", "Account")); } using (var db = new BoardSystemContext()) { Board board; IEnumerable <Comment> commentList; try { board = db.Boards.FirstOrDefault(n => n.BoardNum.Equals(boardNum)); db.Entry(board).Entity.BoardViews = board.BoardViews + 1; db.SaveChanges(); commentList = db.Comments.ToList().Where(d => d.BoardNum.Equals(boardNum)); ViewBag.commentList = commentList; } catch { return(RedirectToAction("Error", "Home")); } return(View(board)); } }