public ActionResult Save(Board board) { if (!ModelState.IsValid) { var viewModel = new BoardFormVm(board) { BoardTypes = _context.BoardTypes.ToList() }; return(View("BoardForm", viewModel)); } if (board.Id == 0) { board.DateAdded = DateTime.Now; _context.Boards.Add(board); } else { var boardInDb = _context.Boards.Single(b => b.Id == board.Id); boardInDb.Name = board.Name; boardInDb.ReleaseDate = board.ReleaseDate; boardInDb.BoardTypeId = board.BoardTypeId; boardInDb.NumberInStock = board.NumberInStock; } _context.SaveChanges(); return(RedirectToAction("Index", "Boards")); }
public ActionResult New() { var vm = new BoardFormVm { BoardTypes = _context.BoardTypes.ToList() }; return(View("BoardForm", vm)); }
public ActionResult Edit(int id) { var board = _context.Boards.SingleOrDefault(b => b.Id == id); if (board == null) { return(HttpNotFound()); } var vm = new BoardFormVm(board) { BoardTypes = _context.BoardTypes.ToList() }; return(View("BoardForm", vm)); }