public async Task <IActionResult> AddJoke(AddJokeBindingModel model) { if (!ModelState.IsValid) { return(BadRequest()); } var joke = mapper.Map <Joke>(model); await this.jokeService.AddJoke(joke); return(RedirectToAction("AllJokes", "Joke")); }
public async Task <IActionResult> AddJoke(AddJokeBindingModel model) { if (!this.ModelState.IsValid) { SetErrorMessage(CommonConstants.DangerMessage); return(this.AddJoke()); } int generatedId = await this.jokeService.AddJokeAsync(model); if (generatedId < 1) { SetErrorMessage(CommonConstants.DuplicateMessage); return(this.AddJoke()); } SetSuccessMessage(string.Format(CommonConstants.SuccessMessage, CommonConstants.JokeSuffix)); return(Redirect(string.Format(RedirectConstants.AdministratorAreaJokeDetailsPage, generatedId))); }
public async Task <int> AddJokeAsync(AddJokeBindingModel model) { var checkForDuplicate = this.DbContext .Jokes .FirstOrDefault(x => x.Title == model.Title); if (checkForDuplicate != null) { return(ErrorId); } var joke = this.Mapper.Map <Joke>(model); joke.Title = Html_String_Utility.EncodeThisPropertyForMe(joke.Title); joke.PhotoURL = Html_String_Utility.EncodeThisPropertyForMe(joke.PhotoURL); joke.Content = Html_String_Utility.EncodeThisPropertyForMe(joke.Content); await this.DbContext.Jokes.AddAsync(joke); await this.DbContext.SaveChangesAsync(); return(joke.Id); }