コード例 #1
0
        public ActionResult Edit(ModeratorGameServiceModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View());
            }

            this.games.EditGame(model);

            TempData.AddSuccessMessage($"Game {model.Title} was edited successful!");

            return(this.RedirectToAction(
                       nameof(HomeController.Index),
                       "Home",
                       new { area = string.Empty }));
        }
コード例 #2
0
        public void Create(ModeratorGameServiceModel model)
        {
            var game = new Game
            {
                Title        = model.Title,
                Price        = model.Price,
                Size         = model.Size,
                VideoUrl     = model.VideoUrl,
                ThumbnailUrl = model.ThumbnailUrl,
                Description  = model.Description,
                ReleaseDate  = model.ReleaseDate
            };

            this.data.Games.Add(game);
            this.data.Games.SaveChanges();
        }
コード例 #3
0
        public void EditGame(ModeratorGameServiceModel model)
        {
            var gameExist = this.data.Games.Find(model.Id);

            if (gameExist == null)
            {
                return;
            }

            gameExist.Title        = model.Title;
            gameExist.Price        = model.Price;
            gameExist.Size         = model.Size;
            gameExist.VideoUrl     = model.VideoUrl;
            gameExist.ThumbnailUrl = model.ThumbnailUrl;
            gameExist.Description  = model.Description;
            gameExist.ReleaseDate  = model.ReleaseDate;

            this.data.Games.Update(gameExist);
            this.data.Games.SaveChanges();
        }