public IActionResult Add(HttpResponse response, HttpSession session, AddGameBM model) { if (!AuthenticationManager.IsAuthenticated(session)) { this.Redirect(response, "/home/login"); return(null); } if (!AuthenticationManager.IsAdmin(session)) { this.Redirect(response, "/home/index"); return(null); } if (!this.service.IsValidGameAddBM(model)) { this.Redirect(response, "/game/add"); return(null); } this.service.AddGameFromBM(model); this.Redirect(response, "/game/admin"); return(null); }
public void AddGameFromBM(AddGameBM model) { var game = new Game() { Title = model.Title, Description = model.Description, Price = model.Price, Size = model.Size, ImageThumbnail = model.ImageThumbnail, Trailer = model.Trailer, ReleaseDate = model.ReleaseDate }; this.Context.Games.Add(game); this.Context.SaveChanges(); }
public bool IsValidGameAddBM(AddGameBM model) { if (string.IsNullOrEmpty(model.Title) || string.IsNullOrEmpty(model.Description) || string.IsNullOrEmpty(model.ImageThumbnail) || string.IsNullOrEmpty(model.Trailer) || model.Price <= 0 || model.Size <= 0) { return(false); } if (model.Title.Length > 100 || model.Title.Length < 3 || !model.Title[0].ToString().Equals(model.Title[0].ToString().ToUpper())) { return(false); } if (model.Trailer.Length != 11) { return(false); } if (!Regex.IsMatch(model.ImageThumbnail, @"^(https:\/\/)|(http:\/\/).+$")) { return(false); } if (model.Description.Length < 20) { return(false); } return(true); }