public async Task <IActionResult> EditJoke(EditJokeBindingModel model) { if (!this.ModelState.IsValid) { SetErrorMessage(CommonConstants.DangerMessage); return(this.EditJoke(model.Id)); } int generatedId = await this.jokeService.EditJokeAsync(model); if (generatedId < 1) { return(RedirectToAction(RedirectConstants.IndexSuffix)); } return(Redirect(string.Format(RedirectConstants.AdministratorAreaJokeDetailsPage, generatedId))); }
public async Task <int> EditJokeAsync(EditJokeBindingModel model) { var joke = this.DbContext .Jokes .FirstOrDefault(x => x.Id == model.Id); if (joke == null) { return(ErrorId); } joke.Title = model.Title; joke.Content = model.Content; joke.PhotoURL = model.PhotoURL; 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.SaveChangesAsync(); return(joke.Id); }
public async Task <IActionResult> DeleteJoke(EditJokeBindingModel model) { bool isDeleted = await this.jokeService.DeleteJokeAsync(model.Id); return(RedirectToAction(RedirectConstants.IndexSuffix)); }