Пример #1
0
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            AbstractEntityFrameworkApiController controller = (AbstractEntityFrameworkApiController)actionExecutedContext.ActionContext.ControllerContext.Controller;

            if (actionExecutedContext.Exception == null)
            {
                try
                {
                    if (controller.Context.Database.CurrentTransaction != null)
                    {
                        controller.Context.Database.CurrentTransaction.Commit();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    controller.Context.Dispose();
                }
            }
            else
            {
                try
                {
                    if (controller.Context.Database.CurrentTransaction != null)
                    {
                        controller.Context.Database.CurrentTransaction.Rollback();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    controller.Context.Dispose();
                }
            }

            base.OnActionExecuted(actionExecutedContext);
        }
Пример #2
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            AbstractEntityFrameworkApiController controller = (AbstractEntityFrameworkApiController)actionContext.ControllerContext.Controller;

            controller.Context.Configuration.AutoDetectChangesEnabled = false; //disable change tracking in context
        }
Пример #3
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            AbstractEntityFrameworkApiController controller = (AbstractEntityFrameworkApiController)actionContext.ControllerContext.Controller;

            controller.Context.Database.BeginTransaction();
        }