Ejemplo n.º 1
0
        /// <summary>
        /// Performs the actual entity action specified by the delegate <paramref name="executor"/>
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="executor"></param>
        /// <returns></returns>
        protected static BoolResult <T> DoEntityAction(T entity, Func <IActionContext, IEntityService <T>, BoolResult <T> > executor)
        {
            IActionContext ctx = ActiveRecordRegistration.GetContext <T>();

            ctx.CombineMessageErrors = true;
            ctx.Item = entity;
            IEntityService <T> service = EntityRegistration.GetService <T>();

            return(executor(ctx, service));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieve the model associated with the id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BoolResult <T> Get(int id)
        {
            IEntityService <T> service = ActiveRecordRegistration.GetService <T>();
            IActionContext     context = ActiveRecordRegistration.GetContext <T>();

            context.Id = id;
            BoolResult <T> result = service.Get(context);

            ActiveRecordRegistration.Init <T>(result.Item, service);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieve all instances of model.
        /// </summary>
        /// <returns></returns>
        public static BoolResult <IList <T> > GetAll()
        {
            IEntityService <T>      service = ActiveRecordRegistration.GetService <T>();
            IActionContext          ctx     = ActiveRecordRegistration.GetContext <T>();
            BoolResult <IList <T> > result  = service.GetAll(ctx);

            foreach (T item in result.Item)
            {
                ActiveRecordRegistration.Init <T>(item, service);
            }
            return(result);
        }