public static bool IsValidGame(NewGameBindingModel game) { //Why you inject in data more than 5 symbols for title..I made it 50 for test cases! string titleRegex = "^[A-Z]{1}.{2,50}$"; if (!Regex.IsMatch(game.Title, titleRegex)) { return(false); } if (game.Price <= 0 || game.Size <= 0) { return(false); } if (!Regex.IsMatch(game.Trailer, "^.{11}$")) { return(false); } if (!game.Thumbnail.StartsWith("http://") && !game.Thumbnail.StartsWith("https://")) { return(false); } if (game.Description.Length < 20) { return(false); } return(true); }
public void EditGame(HttpResponse responce, HttpSession session, NewGameBindingModel editGameBm) { if (this.RedirectNotLoggedAdmin(responce, session)) { return; } var location = this.catalogService.EditGame(editGameBm); this.Redirect(responce, location); }
public void AddNewGame(NewGameBindingModel ngbm) { Game game = new Game() { Description = ngbm.Description, ImageThumbnail = ngbm.ImageThumbnail, Price = ngbm.Price, ReleaseDate = ngbm.ReleaseDate, Size = ngbm.Size, Title = ngbm.Title, Trailer = ngbm.Trailer }; this.Context.Games.Add(game); this.Context.SaveChanges(); }
public IActionResult Add(HttpResponse response, HttpSession session, NewGameBindingModel ngbm) { User activeUser = AuthenticationManager.GetAuthenticatedUser(session.Id); if (activeUser == null) { this.Redirect(response, "/users/login"); return(null); } if (!activeUser.IsAdmin) { this.Redirect(response, "/store/home"); return(null); } this.service.AddNewGame(ngbm); this.Redirect(response, "games/all"); return(null); }
public string EditGame(NewGameBindingModel editGameBm) { if (!NewGameValidator.IsValidGame(editGameBm)) { return("/catalog/AllGames"); } var game = this.games.GetById(editGameBm.GameId); game.Description = editGameBm.Description; game.Size = editGameBm.Size; game.Title = editGameBm.Title; game.Price = editGameBm.Price; game.ImageThumbnail = editGameBm.Thumbnail; game.Trailer = editGameBm.Trailer; this.games.SaveChanges(); return("/home/all"); }
public string AddNewGame(NewGameBindingModel newGameBm) { if (!NewGameValidator.IsValidGame(newGameBm)) { return("/catalog/AddGame"); } var game = new Game() { Title = newGameBm.Title, Price = newGameBm.Price, Size = newGameBm.Size, Description = newGameBm.Description, ImageThumbnail = newGameBm.Thumbnail, Trailer = newGameBm.Trailer }; this.games.Add(game); this.games.SaveChanges(); return("/home/all"); }