public HttpResponse Add(CreateCardFormModel model) { var modelErrors = this.validator.ValidateCard(model); if (modelErrors.Any()) { return(Error(modelErrors)); } var repository = new Card { Name = model.Name, Description = model.Description, Attack = model.Attack, Health = model.Health, ImageUrl = model.Image, Keyword = model.Keyword, }; this.db.Cards.Add(repository); this.db.SaveChanges(); return(Redirect("/Cards/All")); }
public ICollection <string> ValidateCard(CreateCardFormModel model) { var errors = new List <string>(); if (model.Name.Length < UserMinUsername || model.Name.Length > DefaultMaxLength) { errors.Add($"Name '{model.Name}' is not valid. It must be between {CardMinLength} and {CardMaxLength} characters long."); } return(errors); }