public ActionResult Delete(Guid id, int?p, string search) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var email = _bannedEmailService.Get(id); if (email == null) { throw new ApplicationException("Cannot delete email - email does not exist"); } _bannedEmailService.Delete(email); ViewBag.Message = new GenericMessageViewModel { Message = "Email delete successfully", MessageType = GenericMessages.success }; unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); ViewBag.Message = new GenericMessageViewModel { Message = string.Format("Delete failed: {0}", ex.Message), MessageType = GenericMessages.danger }; } return(RedirectToAction("Index", new { p, search })); } }
public ActionResult Delete(Guid id, int?p, string search) { try { var email = _bannedEmailService.Get(id); if (email == null) { throw new ApplicationException("Cannot delete email - email does not exist"); } _bannedEmailService.Delete(email); TempData[Constants.MessageViewBagName] = new GenericMessageViewModel { Message = "Email delete successfully", MessageType = GenericMessages.success }; Context.SaveChanges(); } catch (Exception ex) { Context.RollBack(); LoggingService.Error(ex); TempData[Constants.MessageViewBagName] = new GenericMessageViewModel { Message = $"Delete failed: {ex.Message}", MessageType = GenericMessages.danger }; } return(RedirectToAction("Index", new { p, search })); }