public async Task <ActionResult> AddGame([Bind] Game game, HttpPostedFileBase gameImage, HttpPostedFileBase fonImage) { if (ModelState.IsValid) { game.GameImage = gameImage?.ToBase64(); game.BackImage = fonImage?.ToBase64(); if (!string.IsNullOrEmpty(game.PreviewLink)) { game.PreviewLink = game.PreviewLink.PreviewLink(); } await _repository.AddGameAsync(game); TempData["message"] = $"Game {game.Name} was added"; return(RedirectToAction("Index")); } GameEditViewModel model = new GameEditViewModel { Game = game, Categories = Categories, Publishers = Publishers }; return(View(model)); }
public async Task <IActionResult> Edit(GameEditViewModel viewModel) { Game game = gameService.GetByID(viewModel.Game.ID); game.Name = viewModel.Game.Name; game.Description = viewModel.Game.Description; game.GenreID = viewModel.GenreID; game.DeveloperID = viewModel.DeveloperID; game.PublisherID = viewModel.PublisherID; game.PlatformID = viewModel.PlatformID; string uniqueFileName = null; string coverImageFolder = Path.Combine(hostingEnv.WebRootPath, "images\\Game\\CoverImage"); if (viewModel.Game.CoverImage != null) { uniqueFileName = Guid.NewGuid().ToString() + "_" + viewModel.Game.CoverImage.FileName; string filePath = Path.Combine(coverImageFolder, uniqueFileName); await viewModel.Game.CoverImage.CopyToAsync(new FileStream(filePath, FileMode.Create)); game.CoverImageFilePath = uniqueFileName; game.CoverImage = viewModel.Game.CoverImage; gameService.Update(game); } return(RedirectToAction("Details", game)); }
public async Task <IActionResult> Create(GameEditViewModel editViewModel, int[] selectedOwners, int[] selectedDesigners) { var game = new Game() { Title = editViewModel.GameWithPersonInfo.Title, PlayTimeID = editViewModel.GameWithPersonInfo.PlayTimeID, MinPlayers = editViewModel.GameWithPersonInfo.MinPlayers, MaxPlayers = editViewModel.GameWithPersonInfo.MaxPlayers }; db.Add(game); foreach (int selectedOwner in selectedOwners) { db.Add(new GamePersonRelationship { GameID = game.ID, PersonID = selectedOwner, Role = Role.Owner }); } foreach (int selectedDesigner in selectedDesigners) { db.Add(new GamePersonRelationship { GameID = game.ID, PersonID = selectedDesigner, Role = Role.Designer }); } await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
// GET: Game/Edit/5 public IActionResult Edit(long?id) { if (id == null) { return(NotFound()); } var game = this.gameRepository.GetGame(id.Value); if (game == null) { return(NotFound()); } var vm = new GameEditViewModel(); vm.RecordId = game.RecordId; vm.Date = game.Date; vm.Description = game.Description; vm.Developer = game.Developer; vm.ImageFileName = game.ImageFileName; vm.IsDownloadable = game.IsDownloadable; vm.Price = game.Price; vm.Publisher = game.Publisher; vm.Title = game.Title; return(View(vm)); }
public async Task <IActionResult> Edit(int id) { var game = await _gameService.GetByIdAsync(id); if (game == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } var model = new GameEditViewModel() { Id = game.Id, Name = game.Name, HasSite = game.HasSite, GameKey = game.GameKey, Status = game.Status, HasLogo = game.GameLogo != null, ValueEntryTypes = game.ValueEntryTypes, LinkEntryTypes = game.LinkEntryTypes, StringEntryTypes = game.StringEntryTypes, TagEntryTypes = game.TagEntryTypes }; return(View(model)); }
public IActionResult Edit(int?id) { if (id == null || id == 0) { return(NotFound()); } var obj = _db.Game.Find(id); if (obj == null) { return(NotFound()); } var objViewModel = new GameEditViewModel { Id = obj.Id, Name = obj.Name, ReleaseDate = obj.ReleaseDate, Platform = obj.Platform, Publisher = obj.Publisher, Genre = obj.Genre, Description = obj.Description, Developer = obj.Developer, MinimalRequirements = _db.Requirement.Find(obj.MinimalRequirementsId), RecommendedRequirements = _db.Requirement.Find(obj.RecommendedRequirementsId), Image = obj.Image, }; return(View(objViewModel)); }
public async Task <ActionResult> Edit([Bind] Game game, HttpPostedFileBase gameImage, HttpPostedFileBase fonImage) { Game currentGame = _repository.GetGameById(game.GameId); if (ModelState.IsValid) { game.GameImage = gameImage != null?gameImage.ToBase64() : currentGame?.GameImage; game.BackImage = fonImage != null?fonImage.ToBase64() : currentGame?.BackImage; if (!string.IsNullOrEmpty(game.PreviewLink)) { game.PreviewLink = game.PreviewLink.PreviewLink(); } await _repository.UpdateGameAsync(game); TempData["message"] = $"Game {game.Name} was saved"; return(RedirectToAction("Index")); } GameEditViewModel model = new GameEditViewModel { Game = game, Categories = Categories, Publishers = Publishers }; return(View(model)); }
public void ImageReplaceMultiTest() { using (var temp = TempDirectory.Create()) { var db = new GameDatabase(temp.TempPath); db.OpenDatabase(); var game = new Game() { GameId = "testid", Name = "Test Game" }; var origIcon = db.AddFile(PlayniteUITests.CreateFakeFile(), game.Id); var origImage = db.AddFile(PlayniteUITests.CreateFakeFile(), game.Id); var origBackground = db.AddFile(PlayniteUITests.CreateFakeFile(), game.Id); game.Icon = origIcon; game.CoverImage = origImage; game.BackgroundImage = origBackground; db.Games.Add(game); game = new Game() { GameId = "testid2", Name = "Test Game 2" }; origIcon = db.AddFile(PlayniteUITests.CreateFakeFile(), game.Id); origImage = db.AddFile(PlayniteUITests.CreateFakeFile(), game.Id); origBackground = db.AddFile(PlayniteUITests.CreateFakeFile(), game.Id); game.Icon = origIcon; game.CoverImage = origImage; game.BackgroundImage = origBackground; db.Games.Add(game); var newIcon = PlayniteUITests.CreateFakeFile(); var newImage = PlayniteUITests.CreateFakeFile(); var newBackground = PlayniteUITests.CreateFakeFile(); // Replaces all images for all games var games = db.Games.ToList(); var model = new GameEditViewModel(games, db, new MockWindowFactory(), new MockDialogsFactory(), new MockResourceProvider(), null); model.EditingGame.Icon = newIcon.OriginalUrl; model.EditingGame.CoverImage = newImage.OriginalUrl; model.EditingGame.BackgroundImage = newBackground.OriginalUrl; model.ConfirmDialog(); Assert.AreEqual(3, Directory.GetFiles(db.GetFileStoragePath(games[0].Id)).Count()); Assert.AreEqual(3, Directory.GetFiles(db.GetFileStoragePath(games[1].Id)).Count()); CollectionAssert.AreEqual(newIcon.Content, File.ReadAllBytes(db.GetFullFilePath(games[0].Icon))); CollectionAssert.AreEqual(newImage.Content, File.ReadAllBytes(db.GetFullFilePath(games[0].CoverImage))); CollectionAssert.AreEqual(newBackground.Content, File.ReadAllBytes(db.GetFullFilePath(games[0].BackgroundImage))); CollectionAssert.AreEqual(newIcon.Content, File.ReadAllBytes(db.GetFullFilePath(games[1].Icon))); CollectionAssert.AreEqual(newImage.Content, File.ReadAllBytes(db.GetFullFilePath(games[1].CoverImage))); CollectionAssert.AreEqual(newBackground.Content, File.ReadAllBytes(db.GetFullFilePath(games[1].BackgroundImage))); } }
public IActionResult Edit(long id, [Bind("Title,Description,Price,Date,Developer,Publisher,RecordId,IsDownloadable,ImageFileName")] GameEditViewModel vm) { if (id != vm.RecordId) { return(NotFound()); } if (ModelState.IsValid) { try { var game = new Game(); game.Title = vm.Title; game.Description = vm.Description; game.Price = vm.Price; game.Date = vm.Date; game.Developer = vm.Developer; game.Publisher = vm.Publisher; game.RecordId = vm.RecordId; game.IsDownloadable = vm.IsDownloadable; game.ImageFileName = vm.ImageFileName; if (vm.File != null) { var file = vm.File; var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition); var filename = Path.Combine(_hostingEnvironment.WebRootPath, "images", "games", parsedContentDisposition.FileName.Trim('"')); using (var stream = System.IO.File.OpenWrite(filename)) { file.CopyTo(stream); } game.ImageFileName = parsedContentDisposition.FileName.Trim('"'); } this.gameRepository.UpdateGame(game); this.gameRepository.Save(); } catch (DbUpdateConcurrencyException) { if (!GameExists(vm.RecordId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(vm)); }
public bool?EditGames(List <IGame> games) { var model = new GameEditViewModel( games, database, GameEditWindowFactory.Instance, new DialogsFactory(), new ResourceProvider()); return(model.OpenView()); }
public bool?EditGames(List <Game> games) { var model = new GameEditViewModel( games, Database, new GameEditWindowFactory(), Dialogs, new ResourceProvider(), Extensions); return(model.OpenView()); }
public bool?EditGame(IGame game) { var model = new GameEditViewModel( game, database, GameEditWindowFactory.Instance, new DialogsFactory(), new ResourceProvider(), appSettings); return(model.OpenView()); }
public bool?EditGame(Game game) { var model = new GameEditViewModel( game, database, GameEditWindowFactory.Instance, new DialogsFactory(), new DefaultResourceProvider(), extensions); return(model.OpenView()); }
public IActionResult Edit(GameEditViewModel model) { if (ModelState.IsValid) { try { Game game = _gameRepository.GetGameByID(model.Id); game.GameName = model.GameName; game.GameCreator = model.GameCreator; game.Price = model.Price; game.Description = model.Description; game.IsOnSale = model.IsOnSale; game.IsInStock = model.IsInStock; game.GenreId = model.GenreId; game.GenreName = model.GenreName; game.ConsoleId = model.ConsoleId; game.ConsoleName = model.ConsoleName; if (model.Photo != null) { // If a new photo is uploaded, the existing photo must be // deleted. So check if there is an existing photo and delete if (model.ExistingPhotoPath != null) { string filePath = Path.Combine(_webHostEnvironment.WebRootPath, "images", model.ExistingPhotoPath); System.IO.File.Delete(filePath); } // Save the new photo in wwwroot/images folder and update // PhotoPath property of the employee object which will be // eventually saved in the database game.PhotoPath = UploadedFile(model); _logger.LogInformation(LoggerMessageDisplay.PhotoEdited); } _context.Games.Update(game); _logger.LogInformation(LoggerMessageDisplay.GameEdited); _context.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { _logger.LogWarning(LoggerMessageDisplay.GameEditErrorModelStateInvalid + "--->" + ex); return(View("Error")); } } PopulateChoices(model); return(View(model)); }
public bool?EditGame(Game game) { var model = new GameEditViewModel( game, Database, new GameEditWindowFactory(), Dialogs, new ResourceProvider(), Extensions, Application.Api); return(model.OpenView()); }
public ViewResult AddGame() { GameEditViewModel model = new GameEditViewModel { Game = new Game { ReleaseDate = DateTime.Now }, Categories = Categories, Publishers = Publishers }; return(View(model)); }
public ViewResult Edit(Guid gameId) { Game game = _repository.GetGameById(gameId); GameEditViewModel model = new GameEditViewModel { Game = game, Categories = Categories, Publishers = Publishers }; return(View(model)); }
protected void PopulateEditChoices(GameEditViewModel model) { model.Genres = _context.Genres.Select(m => new SelectListItem { Value = m.GenreId.ToString(), Text = m.GenreName }); model.Consoles = _context.Consoles.Select(m => new SelectListItem { Value = m.ConsoleId.ToString(), Text = m.ConsoleName }); }
public ActionResult Edit(GameEditViewModel gameEditViewModel) { if (ModelState.IsValid) { var game = new Game() { gameID = gameEditViewModel.gameID, gameGeneric = gameEditViewModel.gameGeneric, gameName = gameEditViewModel.gameName, gamePrice = gameEditViewModel.gamePrice }; //db.Entry(game).State = System.Data.Entity.EntityState.Modified; } return(View()); }
public IActionResult Edit(int id) { if (id == 0) { return(NotFound()); } Game game = gameService.GetByID(id); if (game == null) { return(NotFound()); } GameEditViewModel viewModel = new GameEditViewModel(); viewModel.Game = game; viewModel.Genres = genreService.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.ID.ToString() }).ToList(); viewModel.GenreID = game.GenreID; viewModel.Developers = developerService.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.ID.ToString() }).ToList(); viewModel.DeveloperID = game.DeveloperID; viewModel.Publishers = publisherService.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.ID.ToString() }).ToList(); viewModel.PublisherID = game.PublisherID; viewModel.Platforms = platformService.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.ID.ToString() }).ToList(); viewModel.PlatformID = game.PlatformID; return(View(viewModel)); }
public ActionResult Edit(Guid?id) { var game = UnitOfWork.Game.Get(id); var model = new GameEditViewModel { Id = game.Id, Name = game.Name, Description = game.Description, Price = game.Price, GenderId = game.Gender.Id }; model.BindData(UnitOfWork); return(View(model)); }
public GameEditViewModel GetEditGame(int id) { var game = this.data.Games.GetById(id); GameEditViewModel vm = new GameEditViewModel() { Title = game.Title, Description = game.Description, Id = game.Id, Price = game.Price, Size = game.Size, Thumbnail = game.ImageThumbnail, Trailer = game.Trailer }; return(vm); }
public void ImageReplaceTest() { using (var temp = TempDirectory.Create()) { var db = new GameDatabase(temp.TempPath); db.OpenDatabase(); var game = new Game() { GameId = "testid", Name = "Test Game" }; var origIcon = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id); var origImage = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id); var origBackground = db.AddFile(PlayniteTests.GenerateFakeFile(), game.Id); game.Icon = origIcon; game.CoverImage = origImage; game.BackgroundImage = origBackground; db.Games.Add(game); var newIcon = PlayniteTests.GenerateFakeFile(); var newImage = PlayniteTests.GenerateFakeFile(); var newBackground = PlayniteTests.GenerateFakeFile(); File.WriteAllBytes(Path.Combine(temp.TempPath, newIcon.FileName), newIcon.Content); File.WriteAllBytes(Path.Combine(temp.TempPath, newImage.FileName), newImage.Content); File.WriteAllBytes(Path.Combine(temp.TempPath, newBackground.FileName), newBackground.Content); // Images are replaced var model = new GameEditViewModel(game, db, new MockWindowFactory(), new MockDialogsFactory(), new MockResourceProvider(), null); model.EditingGame.Icon = Path.Combine(temp.TempPath, newIcon.FileName); model.EditingGame.CoverImage = Path.Combine(temp.TempPath, newImage.FileName); model.EditingGame.BackgroundImage = Path.Combine(temp.TempPath, newBackground.FileName); model.ConfirmDialog(); Assert.AreNotEqual(game.Icon, origIcon); Assert.AreNotEqual(game.CoverImage, origImage); Assert.AreNotEqual(game.BackgroundImage, origBackground); var dbFiles = Directory.GetFiles(db.GetFileStoragePath(game.Id)); Assert.AreEqual(3, dbFiles.Count()); CollectionAssert.AreEqual(newIcon.Content, File.ReadAllBytes(db.GetFullFilePath(game.Icon))); CollectionAssert.AreEqual(newImage.Content, File.ReadAllBytes(db.GetFullFilePath(game.CoverImage))); CollectionAssert.AreEqual(newBackground.Content, File.ReadAllBytes(db.GetFullFilePath(game.BackgroundImage))); } }
public IActionResult <GameEditViewModel> Edit(HttpSession session, HttpResponse response, int id) { if (!this.signInManager.IsAuthenticated(session)) { Redirect(response, "/users/login"); return(null); } if (!this.signInManager.IsAdmin(session)) { Redirect(response, "/games/all"); return(null); } GameEditViewModel game = this.service.GetEditGame(id); return(this.View(game)); }
public async Task EditPost_ReturnsModel_WhenModelInvalid() { //Arrange var model = new GameEditViewModel { Name = "test" }; controller.ModelState.AddModelError("", "error"); //Act var result = await controller.Edit(model); //Assert var viewResult = Assert.IsType <ViewResult>(result); Assert.IsType <GameEditViewModel>(viewResult.Model); }
public ActionResult Edit(GameEditViewModel model) { if (!ModelState.IsValid) { model.BindData(UnitOfWork); return(View(model)); } var game = UnitOfWork.Game.Get(model.Id); game.Name = model.Name; game.Description = model.Description; game.Price = model.Price; game.Gender = model.GenderId.HasValue ? UnitOfWork.Gender.Get(model.GenderId) : null; UnitOfWork.SaveChanges(); return(RedirectToAction("Index")); }
public async Task EditPost_Returns404_WhenGameDoesntExist() { //Arrange var model = new GameEditViewModel { Id = 1, Name = "test" }; mockGameService.Setup(s => s.GetByIdAsync(It.IsAny <int>())).ReturnsAsync((GameDto)null); //Act var result = await controller.Edit(model); //Assert var statusCodeResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal(404, statusCodeResult.StatusCode); }
public ViewResult Edit(int id) { var game = gameRepository.GetById(id); if (game == null) { return(View("NotFound")); } GameEditViewModel model = new GameEditViewModel { Id = game.Id, Name = game.Name, Description = game.Description, Genres = game.Genres, RelaseDate = game.RelaseDate, ExistingPhoto = game.PhotoUrl, Rating = game.Rating }; return(View(model)); }
public async Task <IActionResult> Edit(GameEditViewModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var imageUrl = string.Empty; if (input.Image != null) { var fileName = ContentDispositionHeaderValue.Parse(input.Image.ContentDisposition).FileName.Trim('"'); await using var stream = input.Image.OpenReadStream(); var uploadParams = new ImageUploadParams { File = new FileDescription(fileName, stream), Format = "jpg", }; var uploadResult = await this.cloudinary.UploadAsync(uploadParams); imageUrl = uploadResult.SecureUri.ToString(); } var gameId = await this.gamesService.EditAsync( input.Id, input.Title, input.SubTitle, input.Description, imageUrl); if (gameId == null) { return(this.NotFound()); } this.TempData["InfoMessage"] = "Game edited successfully!"; return(this.RedirectToAction(nameof(this.ByName), new { name = input.Url, subTitle = input.SubTitle })); }
public async Task <IActionResult> Edit(int id, GameEditViewModel viewModel) { var currentUser = await GetCurrentUserAsync(); if (currentUser.RoleId == 2 || currentUser.RoleId == 3) { if (id != viewModel.Game.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(viewModel.Game); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameExists(viewModel.Game.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(viewModel)); } else { return(View()); } }