public ActionResult Club(ClubAddViewModel model) { var otherClubs = this.clubService.GetAllNames(); if (model.Name == null || model.Name.Length < 3 || !(model.Name is string)) { return(this.RedirectToAction("Club", new { error = "Error! Name of club must be a string with 3 or more symbols!" })); } if (model.City == null || model.City.Length < 3 || !(model.City is string)) { return(this.RedirectToAction("Club", new { error = "Error! Name of city must be a string with 3 or more symbols!" })); } if (model.Surface == null || !(model.Surface is string)) { return(this.RedirectToAction("Club", new { error = "Error! Surface type is not specified!" })); } if (otherClubs.Contains(model.Name)) { return(this.RedirectToAction("Club", new { error = $"Error! Club {model.Name} already exists!" })); } int result = this.clubService.AddByNames(model.Name, model.City, model.Surface); if (result <= 0) { return(this.RedirectToAction("Club", new { error = $"Error! Club {model.Name} was not created!" })); } return(this.RedirectToAction("Club", new { success = $"Success! Club {model.Name} was added to database!" })); }
public ActionResult Club(string error, string success) { var cities = this.cityService.GetAllNames(); var clubAddModel = new ClubAddViewModel() { Cities = cities }; if (error != null) { clubAddModel.Error = error; } if (success != null) { clubAddModel.Success = success; } return(View(clubAddModel)); }