Exemple #1
0
        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"));
        }
Exemple #2
0
        public ActionResult New()
        {
            var vm = new BoardFormVm
            {
                BoardTypes = _context.BoardTypes.ToList()
            };

            return(View("BoardForm", vm));
        }
Exemple #3
0
        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));
        }