コード例 #1
0
ファイル: BaseAction.cs プロジェクト: shosca/Dry.Common
        public object ExecuteDelete(IEngineContext context, IController controller, IControllerContext controllerContext)
        {
            using (var transaction = new TransactionScope()) {
                var instance = AR.Find <T>(context.GetParameter("id"));
                try {
                    OnPreDelete(controller, instance);
                    AR.Delete <T>(instance);
                    OnPostDelete(controller, instance);

                    transaction.Flush();
                    transaction.VoteCommit();

                    context.SuccessMessage(instance + " has been deleted");
                } catch (Exception ex) {
                    transaction.VoteRollBack();
                    context.ErrorMessages(ex);
                } finally {
                    controllerContext.PropertyBag[TemplateObjectName] = instance;
                    context.Flash[TemplateObjectName] = instance;
                }
            }

            return(null);
        }