コード例 #1
0
        private EntityServiceResult <TEntity> RunWithValidation(TEntity entity, Func <TEntity> func)
        {
            var result = new EntityServiceResult <TEntity>();

            result.Success = false;
            if (Validate(entity))
            {
                result = EntityServiceResult <TEntity> .Run(func);

                if (result.Exception != null)
                {
                    ModelState.AddError("Exception", result.Exception.ToString());
                }
            }
            return(result);
        }
コード例 #2
0
        public static EntityServiceResult <TEntity> Run <TEntity>(Func <TEntity> func)
            where TEntity : class
        {
            var result = new EntityServiceResult <TEntity>();

            result.Success = false;
            try
            {
                result.Entity  = func();
                result.Success = true;
            }
            catch (Exception ex)
            {
                //if (HttpContext.Current != null)
                //{
                //    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                //}
                result.Exception = ex;
            }
            return(result);
        }
コード例 #3
0
        private EntityServiceResult <TEntity> RunWithValidation(EntityModel <TEntity> model, TEntity entity, Func <TEntity, TEntity> func)
        {
            var result = new EntityServiceResult <TEntity>();

            result.Success = false;
            try
            {
                if (entity == null)
                {
                    //model -> to entity
                    entity = model.ModelToEntity <TEntity>();
                }
                else
                {
                    //model -> to entity
                    entity = model.ModelToEntity <TEntity>(entity);
                }

                //validate
                if (Validate(entity))
                {
                    result = EntityServiceResult <TEntity> .Run(() => { return(func(entity)); });

                    if (result.Exception != null)
                    {
                        ModelState.AddError("Exception", result.Exception.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddError("Exception", ex.ToString());
                result.Exception = ex;
            }

            return(result);
        }