public HttpResponse Add(AddCardInputModel model) { if (!IsUserSignedIn()) { return(Redirect("/users/login")); } if (string.IsNullOrEmpty(model.Name) || model.Name.Length < 5 || model.Name.Length > 15) { return(Error("Name should be between 5 and 15 characters long.")); } if (string.IsNullOrWhiteSpace(model.Image)) { return(Error("The image is required!")); } if (string.IsNullOrWhiteSpace(model.Keyword)) { return(Error("Keyword is required.")); } if (model.Attack < 0) { return(Error("Attack should be non-negative integer.")); } if (model.Health < 0) { return(Error("Health should be non-negative integer.")); } if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 200) { return(Error("Description is required and its length should be at most 200 characters.")); } var cardId = cardsService.AddCard(model); var userId = GetUserId(); cardsService.AddCardToUserCollection(userId, cardId); var viewModel = new DoAddViewModel { Attack = model.Attack, Health = model.Health, }; return(View(viewModel)); }
public HttpResponse AddToCollection(string cardId) { if (!User.IsAuthenticated) { return(Redirect("/Users/Login")); } var checkForErrors = CardsService.AddCardToUserCollection(this.User.Id, cardId); if (!string.IsNullOrEmpty(checkForErrors) || !string.IsNullOrWhiteSpace(checkForErrors)) { return(Error(checkForErrors)); } return(Redirect("/Cards/All")); }