public async Task <IActionResult> AddGame(string name, string description, ImageModel imageModel) { if (!ModelState.IsValid) { return(BadRequest()); } var role = int.Parse(User.FindFirst(ClaimTypes.Role)?.Value); if (role != (int)UserRoles.admin) { return(Unauthorized()); } var gameModel = new GameModel() { Name = name, Description = description, Image = imageModel.Image }; var result = await _gameService.AddGame(gameModel); if (result.Error != null) { return(BadRequest(result)); } return(Ok(result)); }
public async Task <ActionResult <GameDTO> > AddGame([FromBody] GameDTO gameDTO) { var dto = _gameDTOToGame.Map(gameDTO); var result = await _gamesService.AddGame(dto); return(Ok(result)); }
public HttpStatusCodeResult New(GameViewModel model) { if (model != null) { if (ModelState.IsValid) { try { _gameService.AddGame(Mapper.Map <GameViewModel, GameDTO>(model)); return(new HttpStatusCodeResult(HttpStatusCode.Created)); } catch (ArgumentNullException e) { _logger.Error(e); return(new HttpStatusCodeResult(400)); } catch (InvalidOperationException e) { _logger.Error(e); return(new HttpStatusCodeResult(400)); } } } return(new HttpStatusCodeResult(HttpStatusCode.NotAcceptable)); }
public IActionResult OnPost() { if (!ModelState.IsValid) { InitializeGenreTypes(); return(Page()); } var genreId = this.referenceService.GetGenreTypes().Single(genre => genre.Name == Game.GenreType.Name).Id; Game.GenreType.Id = genreId; long gameId; if (Game.Id > 0) { gameService.UpdateGame(Game); gameId = Game.Id; } else { gameId = gameService.AddGame(Game); } TempData["Message"] = "Game saved!"; return(RedirectToPage("./Details", new { gameId = gameId })); }
public async Task <IActionResult> AddGame([FromBody] AddGameRequest addGameRequest) { return(new OkObjectResult(new { message = "Игра успешно добавлена", game = await gameService.AddGame(addGameRequest) })); }
public void AddGame_SuccesfullyAddNewGameToDB_GameViewModelIsValid() { //Arrange _mockUnitOfWork.Setup(m => m.Game.GetById(It.IsAny <int>())).Returns(Mapper.Map <Game>(_games.ToList()[0])); _mockUnitOfWork.Setup(m => m.Game.Get(It.IsAny <Expression <Func <Game, bool> > >())).Returns(new List <Game> { }); var FakeGame = new GameDTO { Name = "Mortal Combat", Description = "Fight" }; //Act _gameService.AddGame(Mapper.Map <GameDTO>(FakeGame)); //Assert _mockUnitOfWork.Verify(m => m.Game.Add(It.IsAny <Game>()), Times.Once); _mockUnitOfWork.Verify(m => m.SaveChanges(), Times.Once); }
public async Task <ActionResult <Game> > AddGame([FromBody] Game game) { if (ModelState.IsValid) { await _gameService.AddGame(game); return(RedirectToAction("GetAllGames")); } return(BadRequest(ModelState)); }
public ActionResult Create(GameViewModel model) { if (ModelState.IsValid) { var game = mapper.Map <Game>(model); gameService.AddGame(game); return(RedirectToAction("Index")); } return(Create()); }
public ActionResult <Game> Post([FromBody] Game game) { try { return(Ok(_gameService.AddGame(game))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult AddGame(Game game) { try { gameService.AddGame(game); return(CreatedAtAction("AddGame", game)); } catch (Exception) { return(BadRequest()); } }
public ActionResult Create(GameViewModel model, HttpPostedFileBase imageFile) { if (ModelState.IsValid) { var game = mapper.Map <Game>(model); game.Image = SaveImage(imageFile); gameService.AddGame(game); return(RedirectToAction("Index")); } return(Create()); }
public ActionResult Create(GameViewModel item, HttpPostedFileBase image) { if (ModelState.IsValid) { Bitmap convertedPicture = null; string filename = Guid.NewGuid().ToString() + ".jpg"; string fullName = Server.MapPath("~/images/") + filename; if (image != null) { convertedPicture = CustomImageConvertor.ConvertToBitmap(new System.Drawing.Bitmap(image.InputStream), 200, 300); if (convertedPicture != null) { convertedPicture.Save(fullName, ImageFormat.Jpeg); item.Image = "/images/" + filename; } } else { if (item.Image.Contains("data:image/png;base64")) { string str = item.Image.Replace("data:image/png;base64,", ""); System.Text.StringBuilder sbText = new System.Text.StringBuilder(str, str.Length); sbText.Replace("\r\n", String.Empty); sbText.Replace(" ", String.Empty); convertedPicture = CustomImageConvertor.ConvertToBitmap(new System.Drawing.Bitmap(new MemoryStream(Convert.FromBase64String(sbText.ToString()))), 200, 300); if (convertedPicture != null) { convertedPicture.Save(fullName, ImageFormat.Jpeg); item.Image = "/images/" + filename; } } else { WebRequest request = WebRequest.Create(item.Image); WebResponse response = request.GetResponse(); using (Stream stream = response.GetResponseStream()) { convertedPicture = CustomImageConvertor.ConvertToBitmap(new System.Drawing.Bitmap(stream), 200, 300); } if (convertedPicture != null) { convertedPicture.Save(fullName, ImageFormat.Jpeg); item.Image = "/images/" + filename; } } } gameService.AddGame(mapper.Map <Game>(item)); return(RedirectToAction("Index")); } return(Create()); }
public IActionResult AddGame([FromBody] GameDto game) { game.StartTime = DateTime.Now; GameDto addedGame = _gameService.AddGame(game); if (addedGame == null) { return(BadRequest()); } else { return(CreatedAtAction(nameof(GetGame), addedGame)); } }
public async Task <IActionResult> CreateGame([FromBody] GameCreateModel game) { CreateGameDto createdGame = new CreateGameDto() { Name = game.Name, Description = game.Description, PublisherId = game.PublisherId, Genres = game.Genres, Platforms = game.Platforms, }; await gameService.AddGame(createdGame); return(StatusCode((int)HttpStatusCode.Created, "Game was added")); }
public async Task <PartialViewResult> AddGame(GameViewModel model) { GameDto game = new GameDto() { Name = model.Name, Year = model.Year, Producer = new ProducerDto { Name = model.Producer } }; await gamesService.AddGame(game); return(PartialView("AddGameForm")); }
private void AddGame() { var(valid, message) = ValidateDataEntry(); if (!valid) { _messageBoxService.Show(message !, "Invalid Data", MessageBoxButton.OK, MessageBoxImage.Error); return; } var newGame = MapNewGameValues(); _gameService.AddGame(newGame); LoadGamesForSelectedSeason(); SelectedGame = null; }
public async Task <HubResult> CreateGame(MafiaCreateGameOptions options) { if (_activeUserService.HasGameConnections(Context.UserIdentifier)) { return(HubResult.Fail("User already in game.")); } var user = await _userManager.FindByIdAsync(Context.UserIdentifier); var game = _mafiaGameBuilder .CreateGame() .WithName(options.Name) .HasMaxPlayers(options.MaxPlayers) .ContainsPlayer(user) .Build(); _gameService.AddGame(game); return(HubResult.Ok(game.Id)); }
public async Task <ActionResult> Create(GameViewModel item, HttpPostedFileBase image) { if (ModelState.IsValid) { string fileName = Guid.NewGuid().ToString() + ".jpg"; string fullPath = Server.MapPath("~/Images/Games/") + fileName; Bitmap bitmap = null; if (image == null) { string imagePath = item.Image; using (HttpClient webClient = new HttpClient()) { bitmap = new Bitmap(await webClient.GetStreamAsync(imagePath)); var convertedPicture = CustomImageConverter.ConvertImage(bitmap, 600, 600); if (convertedPicture != null) { convertedPicture.Save(fullPath, ImageFormat.Jpeg); item.Image = "/Images/Games/" + fileName; } } } else { var convertedPicture = CustomImageConverter.ConvertImage(new Bitmap(image.InputStream), 600, 600); if (convertedPicture != null) { convertedPicture.Save(fullPath, ImageFormat.Jpeg); item.Image = "/Images/Games/" + fileName; } } var game = mapper.Map <Game>(item); gameService.AddGame(game); return(RedirectToAction("Index")); } return(Create()); }
public ActionResult Create(GameCreateViewModel viewModel, HttpPostedFileBase imageFile) { if (ModelState.IsValid) { string filename = Guid.NewGuid().ToString() + ".jpg"; string FullPathImage = Server.MapPath(Config.ProductImagePath) + "\\" + filename; using (Bitmap bmp = new Bitmap(imageFile.InputStream)) { var readyImage = ImageWorker.CreateImage(bmp, 450, 450); if (readyImage != null) { readyImage.Save(FullPathImage, ImageFormat.Jpeg); var game = mapper.Map <Game>(viewModel); game.Image = filename; gameService.AddGame(game); return(RedirectToAction("Index")); } } } return(Create()); }
public async Task Post([FromBody] CreateGameModel model) { await _gameService.AddGame(model.Name, model.Creator); }
public void AddGame_Give_CreategameDto_Return_true() { //assign var gameDto = new Fixture().Build <CreateGameDto>() .With(e => e.Platforms, new List <int>() { 1 }) .With(e => e.Genres, new List <int>() { 1 }) .Create(); Genre genre = new Genre() { Id = 1, }; PlatformType platform = new PlatformType() { Id = 1, }; gameRepositoryMoq.Setup(p => p.GetSingleAsync(It.IsAny <Expression <Func <Game, bool> > >())) .Returns(Task.FromResult(game_Null_Entity)); publisherRepositoryMoq.Setup(p => p.GetSingleAsync(It.IsAny <Expression <Func <Publisher, bool> > >())) .Returns(Task.FromResult(publisher)); genreRepositoryMoq.Setup(p => p.GetSingleAsync(It.IsAny <Expression <Func <Genre, bool> > >())) .Returns(Task.FromResult(genre)); platformRepositoryMoq.Setup(p => p.GetSingleAsync(It.IsAny <Expression <Func <PlatformType, bool> > >())) .Returns(Task.FromResult(platform)); //act service.AddGame(gameDto); //if game not exists gameRepositoryMoq.Verify(p => p.GetSingleAsync(It.IsAny <Expression <Func <Game, bool> > >()), Times.Once); //if publisher exists publisherRepositoryMoq.Verify(p => p.GetSingleAsync(It.IsAny <Expression <Func <Publisher, bool> > >()), Times.Once); platformRepositoryMoq.Verify(p => p.GetSingleAsync(It.IsAny <Expression <Func <PlatformType, bool> > >()), Times.Once); gamePlatformpositoryMoq.Verify(p => p.Create(It.IsAny <GamePlatformType>()), Times.Once); gameGenreRepositoryMoq.Verify(p => p.Create(It.IsAny <GenreGame>()), Times.Once); gameRepositoryMoq.Verify(p => p.Create(It.IsAny <Game>()), Times.Once); unitofworkMoq.Verify(p => p.CommitAsync(), Times.Once); }
public ActionResult Create(GameViewModel model, HttpPostedFileBase image) { if (ModelState.IsValid) { Image sourceImage = null; if (image != null) { try { sourceImage = Bitmap.FromStream(image.InputStream); } catch (ArgumentException ex) { Debug.WriteLine(ex.Message); } } else if (model.Image.StartsWith("data:image")) { sourceImage = DataUrlConverter.ToImage(model.Image); } else { WebClient client = new WebClient(); try { using (var ms = new MemoryStream(client.DownloadData(model.Image))) { sourceImage = Bitmap.FromStream(ms); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } string fileName = Guid.NewGuid().ToString() + ".jpg"; string fullPath = Server.MapPath("~/Images/Games/" + fileName); var converterPicture = CustomImageConverter.ConvertImage(sourceImage, 400, 700); if (converterPicture != null) { converterPicture.Save(fullPath, ImageFormat.Jpeg); model.Image = "/Images/Games/" + fileName; } //var game = new Game //{ // Id = model.Id, // Name = model.Name, // Price = model.Price, // Year = model.Year, // Description = model.Description, // Image = model.Image, // Developer = new Developer { Name = model.Developer }, // Genre = new Genre { Name = model.Genre } //}; var game = mapper.Map <Game>(model); gameService.AddGame(game); return(RedirectToAction("Index")); } else { return(Create()); } }
public IActionResult New([FromBody] NewGameDTO newgame) { var id = gameService.AddGame(newgame); return(Created("", id.ToString())); }