public ActionResult BatchMoveTopics() { var viewModel = new BatchMoveTopicsViewModel { Categories = _categoryService.GetAll().ToList() }; return View(viewModel); }
public ActionResult BatchMoveTopics(BatchMoveTopicsViewModel viewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var categoryFrom = _categoryService.Get((Guid)viewModel.FromCategory); var categoryTo = _categoryService.Get((Guid)viewModel.ToCategory); var topicsToMove = _topicService.GetRssTopicsByCategory(int.MaxValue, categoryFrom.Id); var count = topicsToMove.Count; foreach (var topic in topicsToMove) { topic.Category = categoryTo; } unitOfWork.SaveChanges(); categoryFrom.Topics.Clear(); viewModel.Categories = _categoryService.GetAll().ToList(); unitOfWork.Commit(); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = string.Format("{0} topics moved", count), MessageType = GenericMessages.success }; } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = ex.Message, MessageType = GenericMessages.error }; } } return View(viewModel); }