public IActionResult Create(Genre genre) { genre.Slug = UrlEncoder.ToFriendlyUrl(Request.Form["Name"]); _context.Genres.Add(genre); _context.SaveChanges(); TempData["message"] = $"{genre.Name} has been created"; return(RedirectToAction(nameof(Index))); }
public IActionResult Edit(Genre tempGenre) { var genre = _context.Genres.FirstOrDefault(x => x.Id == tempGenre.Id); if (ModelState.IsValid) { _context.Genres.Attach(genre); genre.Name = tempGenre.Name; genre.Slug = UrlEncoder.ToFriendlyUrl(tempGenre.Name); genre.UpdatedAt = DateTime.Now; _context.SaveChanges(); TempData["message"] = $"{genre.Name} has been changed"; return(RedirectToAction(nameof(Index))); } return(View(genre)); }
public virtual ActionResult EditTopic(EditTopicViewModel viewModel) { if (!this.ModelState.IsValid) { viewModel.AllUserNames = this.GetSelectListOfAllUsernamesExceptCurrent(); return(this.View(MVC.Forum.Views.EditTopic, viewModel)); } string topicId = this.forumStorageWriter.SaveTopic(viewModel, this.User.Identity.Name); if (string.IsNullOrEmpty(viewModel.Id)) { this.forumNotificationSender.SendNewTopicNotifications(topicId); } return(this.RedirectToAction(MVC.Forum.Topic().AddRouteValues(new { id = topicId, name = UrlEncoder.ToFriendlyUrl(viewModel.Title) }))); }
private ActionResult RedirectToPost(TopicPageRoutedata topicPage) { string url = this.Url.Action(MVC.Forum.Topic().AddRouteValues(new { id = topicPage.TopicId, name = UrlEncoder.ToFriendlyUrl(topicPage.TopicTitle), topicPage = topicPage.PageNumber })); url += $"#{topicPage.PostIndex}"; return(this.Redirect(url)); }