private static GameInputViewModel GetGameNewViewModel() { var game = new GameInputViewModel { Description = "TestDescription1", Key = "TestKey1", Name = "TestName1", PlatformTypes = new List <PlatformTypeViewModel> { new PlatformTypeViewModel { Id = 1, Type = "Mobile" }, new PlatformTypeViewModel { Id = 2, Type = "Desktop" }, new PlatformTypeViewModel { Id = 4, Type = "Browser" } }, Genres = new List <GenreViewModel> { new GenreViewModel { Id = 4, Name = "Strategy" }, new GenreViewModel { Id = 3, Name = "Sports" }, new GenreViewModel { Id = 1, Name = "Adventure" } } }; return(game); }
public async Task <ActionResult> EditGame(GameInputViewModel game) { if (!ModelState.IsValid) { return(View(game)); } var gameBll = _mapperWeb.Map <GameBll>(game); try { await _gameService.UpdateAsync(gameBll); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); return(View(game)); } catch (AccessException ex) { ModelState.AddModelError("", ex.Message); return(View(game)); } catch (Exception) { ModelState.AddModelError("", "Bad request"); return(View(game)); } // Success!!! return(RedirectToAction("Index")); }
public ActionResult EditGame(int id) { var inputModel = new GameInputViewModel() { Id = id }; return(View("EditGame", inputModel)); }
public async Task <IActionResult> CreateGame(GameInputViewModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var gameViewModel = await this.gamesService.GetGameViewModelAsync(input); await this.hubContext.Clients.All.SendAsync("AddNewGame", gameViewModel.Name, gameViewModel.Color, gameViewModel.Id); return(this.View("Game", gameViewModel)); }
public async Task <GameViewModel> GetGameViewModelAsync(GameInputViewModel input) { var userId = this.usersService.GetCurrentUserAsync().GetAwaiter().GetResult().Id; var game = new Game { Id = Guid.NewGuid().ToString(), Name = input.Name, Color = input.Color.ToString(), HostId = userId, }; await this.db.Games.AddAsync(game); await this.db.SaveChangesAsync(); var gameViewModel = mapper.Map <GameViewModel>(game); return(gameViewModel); }
public IHttpResponse Edit(GameInputViewModel model) { //verification var game = this.Db.Games.FirstOrDefault(g => g.Id == model.Id); if (game == null) { return(this.BadRequestError("Game do not exist.")); } game.Description = model.Description; game.Price = decimal.Parse(model.Price); game.Title = model.Title; game.Thumbnail = model.Thumbnail; game.Trailer = model.Trailer; game.Size = int.Parse(model.Size); this.Db.SaveChanges(); return(this.Redirect("/games/details?id=" + model.Id)); }
public IHttpResponse Add(GameInputViewModel model, int other) { //verification var game = new Game() { Description = model.Description, Price = decimal.Parse(model.Price), Title = model.Title, Thumbnail = model.Thumbnail, Trailer = model.Trailer, Size = int.Parse(model.Size), ReleasedOn = DateTime.Parse(model.ReleasedOn) }; this.Db.Games.Add(game); this.Db.SaveChanges(); var id = game.Id; return(this.Redirect("/games/details?id=" + id)); }
public ActionResult NewGame() { var inputModel = new GameInputViewModel(); return(View("NewGame", inputModel)); }
public IHttpResponse Add(GameInputViewModel model) => model == null?this.View(new GameInputViewModel()) : this.View(model);