Example #1
0
        // GET: Boardgames/Create
        public ActionResult Create()
        {
            CreateBoardgameViewModel createBoardgameViewModel = new CreateBoardgameViewModel();

            UpdateCreateBoardgameViewModel(createBoardgameViewModel);
            return(View(createBoardgameViewModel));
        }
Example #2
0
 public ActionResult Create(CreateBoardgameViewModel createBoardgameViewModel)
 {
     if (ModelState.IsValid)
     {
         AddBoardgame(createBoardgameViewModel);
         return(RedirectToAction("Index", "Home"));
     }
     UpdateCreateBoardgameViewModel(createBoardgameViewModel);
     return(View(createBoardgameViewModel));
 }
Example #3
0
        private void UpdateCreateBoardgameViewModel(CreateBoardgameViewModel createBoardgameViewModel)
        {
            //Load Board Game Types
            var boardGameTypes = db.BoardGameTypes.ToList()
                                 .Select(x => new SelectListItem {
                Text = x.Name, Value = (x.Id).ToString()
            })
                                 .OrderBy(x => x.Text);

            createBoardgameViewModel.AvailableBoardGameTypes = new SelectList(boardGameTypes, nameof(SelectListItem.Value), nameof(SelectListItem.Text));
        }
Example #4
0
        private void AddBoardgame(CreateBoardgameViewModel viewModel)
        {
            Boardgame           boardgame = new Boardgame();
            MapperConfiguration config    = new MapperConfiguration(cfg => cfg.CreateMap <CreateBoardgameViewModel, Boardgame>());
            IMapper             mapper    = config.CreateMapper();

            boardgame             = mapper.Map <Boardgame>(viewModel);
            boardgame.CreatedBy   = HttpContext.User.Identity.Name;
            boardgame.CreatedDate = DateTime.Now;
            db.Boardgames.Add(boardgame);
            db.SaveChanges();
        }