public bool IsGameValid(GameBm bind) { if (!char.IsUpper(bind.Title[0]) || bind.Title.Length < 3 || bind.Title.Length > 100) { return(false); } if (bind.Price <= 0 || bind.Size <= 0) { return(false); } if (bind.Trailer.Length != 11) { return(false); } if (bind.Description.Length < 20) { return(false); } if (!bind.ImageThumbnail.StartsWith("http://") && !bind.ImageThumbnail.StartsWith("https://")) { return(false); } return(true); }
public void AddGame(GameBm bind) { Game gameToAdd = Mapper.Instance.Map <GameBm, Game>(bind); this.Context.Games.Add(gameToAdd); this.Context.SaveChanges(); }
public void UpdateBindVm(GameBm bind) { Game originalGame = this.Context.Games.Find(bind.Id); originalGame.Description = bind.Description; originalGame.ImageThumbnail = bind.ImageThumbnail; originalGame.Price = bind.Price; originalGame.Size = bind.Size; originalGame.Title = bind.Title; originalGame.Trailer = bind.Trailer; this.Context.SaveChanges(); }
public void Edit(HttpResponse response, HttpSession session, GameBm bind) { User admin = this.GetAuthenticatedAdmin(response, session.Id); if (admin == null) { return; } if (!this.service.IsGameValid(bind)) { this.Redirect(response, $"/admin/edit?id={bind.Id}"); return; } this.service.UpdateBindVm(bind); this.Redirect(response, "/admin/all"); }
public void Newgame(HttpSession session, HttpResponse response, GameBm bind) { User admin = this.GetAuthenticatedAdmin(response, session.Id); if (admin == null) { return; } if (!this.service.IsGameValid(bind)) { this.Redirect(response, "/admin/newgame"); return; } this.service.AddGame(bind); this.Redirect(response, "/admin/all"); }