Exemplo n.º 1
0
        private EditBoardgameViewModel GetEditBoardgameViewModel(Boardgame boardgame)
        {
            EditBoardgameViewModel viewModel = new EditBoardgameViewModel();
            MapperConfiguration    config    = new MapperConfiguration(cfg => cfg.CreateMap <Boardgame, EditBoardgameViewModel>());
            IMapper mapper = config.CreateMapper();

            viewModel = mapper.Map(boardgame, viewModel);
            return(viewModel);
        }
Exemplo n.º 2
0
 public ActionResult Edit(EditBoardgameViewModel editBoardgameViewModel)
 {
     if (ModelState.IsValid)
     {
         EditBoardgame(editBoardgameViewModel);
         return(RedirectToAction("Index", "Home"));
     }
     UpdateEditBoardgameViewModel(editBoardgameViewModel);
     return(View(editBoardgameViewModel));
 }
Exemplo n.º 3
0
        private void UpdateEditBoardgameViewModel(EditBoardgameViewModel editBoardgameViewModel)
        {
            //Load Board Game Types
            var boardGameTypes = db.BoardGameTypes.ToList()
                                 .Select(x => new SelectListItem {
                Text = x.Name, Value = (x.Id).ToString()
            })
                                 .OrderBy(x => x.Text);

            editBoardgameViewModel.AvailableBoardGameTypes = new SelectList(boardGameTypes, nameof(SelectListItem.Value), nameof(SelectListItem.Text));
        }
Exemplo n.º 4
0
        private void EditBoardgame(EditBoardgameViewModel editBoardgameViewModel)
        {
            Boardgame           boardgame = new Boardgame();
            MapperConfiguration config    = new MapperConfiguration(cfg => cfg.CreateMap <EditBoardgameViewModel, Boardgame>());
            IMapper             mapper    = config.CreateMapper();

            boardgame                 = mapper.Map <Boardgame>(editBoardgameViewModel);
            boardgame.ModifiedBy      = HttpContext.User.Identity.Name;
            boardgame.ModifiedDate    = DateTime.Now;
            db.Entry(boardgame).State = EntityState.Modified;
            db.SaveChanges();
        }
Exemplo n.º 5
0
        // GET: Boardgames/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Boardgame boardgame = db.Boardgames.Find(id);

            if (boardgame == null)
            {
                return(HttpNotFound());
            }
            EditBoardgameViewModel editBoardgameViewModel = GetEditBoardgameViewModel(boardgame);

            UpdateEditBoardgameViewModel(editBoardgameViewModel);
            return(View(editBoardgameViewModel));
        }