public bool IsValidRegistrationViewModel(AddNewGameBm newGame) { if (Convert.ToBoolean((char.ToUpper(newGame.Title[0]) + newGame.Title.Substring(1)))) { return(false); } if (newGame.Price < 0) { return(false); } if (newGame.Size.Contains("-")) { return(false); } if (newGame.YouTubeId.Length != 11) { return(false); } if (!newGame.ImageUrl.StartsWith("http://")) { return(false); } if (newGame.Description.Length < 20) { return(false); } return(true); }
public IActionResult Add(HttpResponse response, HttpSession session, AddNewGameBm newGame) { if (!manager.IsAuthenticated(session)) { Redirect(response, "/users/login"); return(null); } User getUser = manager.GetAuthenticatedUser(session); if (!getUser.IsAdmin) { Redirect(response, "/home/index"); return(null); } //if (!service.IsValidRegistrationViewModel(newGame)) //{ // Redirect(response, "/generic/add"); // return null; //} this.service.AddNewGame(newGame); Redirect(response, "home/index"); return(null); }
public void AddNewGame(AddNewGameBm newGame) { Game game = new Game() { Description = newGame.Description, Title = newGame.Title, ReleaseDate = newGame.ReleaseDate, ImageUrl = newGame.ImageUrl, Price = newGame.Price, YouTubeId = newGame.YouTubeId, Size = newGame.Size }; this.data.Games.InsertOrUpdate(game); this.data.Context.SaveChanges(); }