public ActionResult BatchDeletePrivateMessages(BatchDeletePrivateMessagesViewModel viewModel) { try { var pms = _privateMessageService.GetPrivateMessagesOlderThan(viewModel.Days); var pmToDelete = new List <PrivateMessage>(); pmToDelete.AddRange(pms); var count = pmToDelete.Count; foreach (var pm in pmToDelete) { _privateMessageService.DeleteMessage(pm); } Context.SaveChanges(); TempData[Constants.MessageViewBagName] = new GenericMessageViewModel { Message = $"{count} Private Messages deleted", MessageType = GenericMessages.success }; } catch (Exception ex) { Context.RollBack(); LoggingService.Error(ex); TempData[Constants.MessageViewBagName] = new GenericMessageViewModel { Message = ex.Message, MessageType = GenericMessages.danger }; } return(View(viewModel)); }
public ActionResult BatchDeletePrivateMessages(BatchDeletePrivateMessagesViewModel viewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var pms = _privateMessageService.GetPrivateMessagesOlderThan(viewModel.Days); var pmToDelete = new List <PrivateMessage>(); pmToDelete.AddRange(pms); var count = pmToDelete.Count; foreach (var pm in pmToDelete) { _privateMessageService.DeleteMessage(pm); } unitOfWork.Commit(); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = string.Format("{0} Private Messages deleted", count), MessageType = GenericMessages.success }; } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = ex.Message, MessageType = GenericMessages.danger }; } } return(View(viewModel)); }