public ActionResult MoveTags()
        {
            var viewModel = new MoveTagsViewModel
            {
                Tags = TagsSelectList()
            };

            return(View(viewModel));
        }
Example #2
0
 public ActionResult MoveTags()
 {
     using (UnitOfWorkManager.NewUnitOfWork())
     {
         var viewModel = new MoveTagsViewModel
         {
             Tags = TagsSelectList()
         };
         return(View(viewModel));
     }
 }
Example #3
0
        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));
            }
        }
        public ActionResult MoveTags(MoveTagsViewModel viewModel)
        {
            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
            {
                Context.SaveChanges();
                ShowMessage(new GenericMessageViewModel
                {
                    Message     = $"All topics tagged with {oldTag.Tag} have been updated to {newTag.Tag}",
                    MessageType = GenericMessages.success
                });
            }
            catch (Exception ex)
            {
                Context.RollBack();
                LoggingService.Error(ex);
                ShowMessage(new GenericMessageViewModel
                {
                    Message     = $"Error: {ex.Message}",
                    MessageType = GenericMessages.danger
                });
            }

            return(View(viewModel));
        }