示例#1
0
        /// <summary>
        /// Retrieve all instances of model.
        /// </summary>
        /// <returns></returns>
        public static new IList <T> GetAll()
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();
            IList <T>          result  = service.GetAll();

            return(result);
        }
示例#2
0
        /// <summary>
        /// Get items by page using Criteria.
        /// </summary>
        /// <param name="pageNumber">1 The page number to get.</param>
        /// <param name="pageSize">15 Number of records per page.</param>
        /// <returns></returns>
        public static PagedList <T> Find(IQuery criteria, int pageNumber, int pageSize)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();
            PagedList <T>      result  = service.Find(criteria, pageNumber, pageSize);

            return(result);
        }
示例#3
0
        /// <summary>
        /// Retrieve the model associated with the id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static T Get(int id)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();
            T item = service.Get(id);

            return(item);
        }
示例#4
0
        /// <summary>
        /// Get items by page using Criteria
        /// </summary>
        /// <param name="filter">e.g. "UserNameLowered = 'kishore'"</param>
        /// <returns></returns>
        public static IList <T> Find(IQuery criteria)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();
            IList <T>          result  = service.Find(criteria);

            return(result);
        }
示例#5
0
        /// <summary>
        /// Get items by page using filter.
        /// </summary>
        /// <param name="filter">e.g. "UserNameLowered = 'kishore'"</param>
        /// <returns></returns>
        public static IList <T> Find(string filter)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();
            IList <T>          result  = service.Find(filter);

            return(result);
        }
示例#6
0
        /// <summary>
        /// Get items by page.
        /// </summary>
        /// <param name="table">"BlogPosts"</param>
        /// <param name="pageNumber">1 The page number to get.</param>
        /// <param name="pageSize">15 Number of records per page.</param>
        /// <returns></returns>
        public static PagedList <T> GetRecent(int pageNumber, int pageSize)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();
            PagedList <T>      result  = service.GetRecent(pageNumber, pageSize);

            return(result);
        }
示例#7
0
        /// <summary>
        /// Get items by page using filter.
        /// </summary>
        /// <returns></returns>
        public static T First(string filter)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();
            T result = service.First(filter);

            return(result);
        }
示例#8
0
        /// <summary>
        /// Get items by page using filter.
        /// </summary>
        /// <param name="pageNumber">1 The page number to get.</param>
        /// <param name="pageSize">15 Number of records per page.</param>
        /// <returns></returns>
        public static PagedList <T> Find(string filter, int pageNumber, int pageSize)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();
            PagedList <T>      result  = service.Find(filter, pageNumber, pageSize);

            return(result);
        }
        /// <summary>
        /// Get entity from the type of (T) and from the id in the title. The id must by at the end of the url prefixed by "-" as in "my-post-123"
        /// </summary>
        /// <typeparam name="T">The type of entity to get.</typeparam>
        /// <param name="title">The title of the entity with the id in the end.</param>
        /// <returns></returns>
        public static T FromUrl <T>(string title)
        {
            int id = IdFromTitle(title);
            IEntityService <T> service = EntityRegistration.GetService <T>();
            T entity = service.Get(id);

            return(entity);
        }
        /// <summary>
        /// Delete the model associated with the id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BoolResult <T> Delete(int id)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();
            IActionContext     context = EntityRegistration.GetContext <T>();

            context.Id = id;
            return(service.Delete(context));
        }
        /// <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));
        }
示例#12
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 void DoEntityAction(T entity, Action <IActionContext, IEntityService <T> > executor)
        {
            IActionContext ctx = EntityRegistration.GetContext <T>();

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

            executor(ctx, service);
        }
        /// <summary>
        /// Convert this to a feed.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="author"></param>
        /// <param name="description"></param>
        /// <param name="title"></param>
        /// <param name="uri">The uri of the request</param>
        public static SyndicationFeed AsFeed <T>(Uri uri, string author, string title, string description)
        {
            IEntityService <T>   service = EntityRegistration.GetService <T>();
            IList <IPublishable> entries = service.GetRecentAs <IPublishable>(1, 20);
            //http://localhost:49739/Post/rss/

            string host = uri.Host;

            if (host.Contains("localhost"))
            {
                host = "http://localhost.com";
            }
            else
            {
                host = uri.AbsoluteUri;
            }
            var feed = FeedBuilder.Build(author, title, description, host, entries);

            return(feed);
        }
示例#14
0
        /// <summary>
        /// Gets all.
        /// </summary>
        /// <returns></returns>
        public virtual IList <T> GetAll()
        {
            var service = EntityRegistration.GetService <T>();

            return(service.GetAll());
        }
示例#15
0
        /// <summary>
        /// Deletes all.
        /// </summary>
        /// <returns></returns>
        public virtual void DeleteAll()
        {
            var service = EntityRegistration.GetService <T>();

            service.DeleteAll();
        }
示例#16
0
        /// <summary>
        /// Creates the entities conditionally based on whether they exists in the datastore.
        /// Existance in the datastore is done by finding any entities w/ matching values for the
        /// <paramref name="checkFields"/> supplied.
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="checkFields"></param>
        public static void Create(IList <T> entities, params Expression <Func <T, object> >[] checkFields)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();

            service.Create(entities, checkFields);
        }
示例#17
0
        /// <summary>
        /// Decrements the specified member.
        /// </summary>
        /// <param name="member">The member.</param>
        /// <param name="by">The by.</param>
        /// <param name="id">The id.</param>
        public static void Decrement(Expression <Func <T, object> > member, int by, int id)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();

            service.Decrement(member, by, id);
        }
示例#18
0
        /// <summary>
        /// Updates the entities.
        /// </summary>
        public static void Update(IList <T> entities)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();

            service.Update(entities);
        }
示例#19
0
        /// <summary>
        /// Saves the entity.
        /// </summary>
        public static void Save(T entity)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();

            service.Save(entity);
        }
示例#20
0
        /// <summary>
        /// Deletes all the entities from the system.
        /// </summary>
        /// <returns></returns>
        public static new void DeleteAll()
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();

            service.DeleteAll();
        }
示例#21
0
        /// <summary>
        /// Delete the model associated with the id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static void Delete(int id)
        {
            IEntityService <T> service = EntityRegistration.GetService <T>();

            service.Delete(id);
        }
示例#22
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns></returns>
        public virtual void Save()
        {
            var service = EntityRegistration.GetService <T>();

            service.Save(this as T);
        }