public ActionResult MoveTags() { using (UnitOfWorkManager.NewUnitOfWork()) { var viewModel = new MoveTagsViewModel { Tags = TagsSelectList() }; return View(viewModel); } }
public ActionResult MoveTags(MoveTagsViewModel viewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var oldTag = _topicTagService.Get(viewModel.CurrentTagId); var newTag = _topicTagService.Get(viewModel.NewTagId); // Look through the topics and add the new tag to it and remove the old! var topics = new List<Topic>(); topics.AddRange(oldTag.Topics); foreach (var topic in topics) { topic.Tags.Remove(oldTag); topic.Tags.Add(newTag); } // Reset the tags viewModel.Tags = TagsSelectList(); try { unitOfWork.Commit(); ShowMessage(new GenericMessageViewModel { Message = string.Format("All topics tagged with {0} have been updated to {1}", oldTag.Tag, newTag.Tag), MessageType = GenericMessages.success }); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); ShowMessage(new GenericMessageViewModel { Message = string.Format("Error: {0}", ex.Message), MessageType = GenericMessages.danger }); } return View(viewModel); } }