Example #1
0
        async Task <TCategory> BuildCategoryFromResultSets(DbDataReader reader)
        {
            TCategory model = null;

            if ((reader != null) && (reader.HasRows))
            {
                // Category
                model = ActivateInstanceOf <TCategory> .Instance();

                await reader.ReadAsync();

                model.PopulateModel(reader);

                // Data
                if (await reader.NextResultAsync())
                {
                    if (reader.HasRows)
                    {
                        var data = new List <CategoryData>();
                        while (await reader.ReadAsync())
                        {
                            data.Add(new CategoryData(reader));
                        }
                        model.Data = data;
                    }
                }
            }

            return(model);
        }
Example #2
0
        async Task <TModel> BuildFromResultSets(DbDataReader reader)
        {
            TModel model = null;

            if ((reader != null) && (reader.HasRows))
            {
                model = ActivateInstanceOf <TModel> .Instance();

                // Entity
                await reader.ReadAsync();

                model.PopulateModel(reader);

                // Data
                if (await reader.NextResultAsync())
                {
                    var data = new List <EntityData>();
                    if (reader.HasRows)
                    {
                        while (await reader.ReadAsync())
                        {
                            var entityData = new EntityData(reader);
                            data.Add(entityData);
                        }
                    }

                    model.Data = data;
                }
            }

            return(model);
        }
Example #3
0
        public async Task <IEnumerable <TCategory> > SelectByFeatureIdAsync(int featureId)
        {
            IList <TCategory> output = null;

            using (var context = _dbContext)
            {
                output = await context.ExecuteReaderAsync <IList <TCategory> >(
                    CommandType.StoredProcedure,
                    "SelectCategoriesByFeatureId",
                    async reader =>
                {
                    if ((reader != null) && (reader.HasRows))
                    {
                        output = new List <TCategory>();
                        while (await reader.ReadAsync())
                        {
                            var category = ActivateInstanceOf <TCategory> .Instance();
                            category.PopulateModel(reader);
                            output.Add(category);
                        }
                    }

                    return(output);
                }, new IDbDataParameter[]
                {
                    new DbParam("FeatureId", DbType.Int32, featureId)
                });
            }

            return(output);
        }
Example #4
0
        public async Task <IPagedResults <TModel> > SelectAsync(IDbDataParameter[] dbParams)
        {
            IPagedResults <TModel> output = null;

            using (var context = _dbContext)
            {
                output = await context.ExecuteReaderAsync <IPagedResults <TModel> >(
                    CommandType.StoredProcedure,
                    "SelectTagsPaged",
                    async reader =>
                {
                    if ((reader != null) && (reader.HasRows))
                    {
                        output = new PagedResults <TModel>();
                        while (await reader.ReadAsync())
                        {
                            var tag = ActivateInstanceOf <TModel> .Instance();
                            tag.PopulateModel(reader);
                            output.Data.Add(tag);
                        }

                        if (await reader.NextResultAsync())
                        {
                            await reader.ReadAsync();
                            output.PopulateTotal(reader);
                        }
                    }

                    return(output);
                },
                    dbParams);
            }

            return(output);
        }
Example #5
0
        public async Task <TModel> SelectByIdAsync(int id)
        {
            TModel tag = null;

            using (var context = _dbContext)
            {
                tag = await context.ExecuteReaderAsync <TModel>(
                    CommandType.StoredProcedure,
                    "SelectTagById",
                    async reader =>
                {
                    if ((reader != null) && (reader.HasRows))
                    {
                        await reader.ReadAsync();
                        tag = ActivateInstanceOf <TModel> .Instance();
                        tag.PopulateModel(reader);
                    }

                    return(tag);
                }, new[]
                {
                    new DbParam("Id", DbType.Int32, id)
                });
            }

            return(tag);
        }
Example #6
0
        public async Task <TLabel> SelectByIdAsync(int id)
        {
            TLabel label = null;

            using (var context = _dbContext)
            {
                label = await context.ExecuteReaderAsync <TLabel>(
                    CommandType.StoredProcedure,
                    "SelectLabelById",
                    async reader =>
                {
                    if ((reader != null) && (reader.HasRows))
                    {
                        await reader.ReadAsync();
                        label = ActivateInstanceOf <TLabel> .Instance();
                        label.PopulateModel(reader);
                    }

                    return(label);
                }, new IDbDataParameter[]
                {
                    new DbParam("Id", DbType.Int32, id)
                });
            }

            return(label);
        }
Example #7
0
        public async Task<TModel> SelectByNameNormalizedAsync(string nameNormalized)
        {
            TModel tag = null;
            using (var context = _dbContext)
            {
                tag = await context.ExecuteReaderAsync<TModel>(
                    CommandType.StoredProcedure,
                    "SelectTagByNameNormalized",
                    async reader =>
                    {
                        if ((reader != null) && (reader.HasRows))
                        {
                            await reader.ReadAsync();
                            tag = ActivateInstanceOf<TModel>.Instance();
                            tag.PopulateModel(reader);
                        }

                        return tag;
                    }, new IDbDataParameter[]
                    {
                        new DbParam("NameNormalized", DbType.String, 255, nameNormalized), 
                    });
            }

            return tag;

        }
Example #8
0
        public T GetOrCreate <T>() where T : class
        {
            if (_metaData.ContainsKey(typeof(T)))
            {
                return((T)_metaData[typeof(T)]);
            }

            return(ActivateInstanceOf <T> .Instance());
        }
Example #9
0
        public ILayoutZoneView View <TViewModel>(string viewName, Func <TViewModel, TViewModel> configure) where TViewModel : class
        {
            // Create proxy model
            var proxy = ActivateInstanceOf <TViewModel> .Instance();

            // Configure model
            var model = configure((TViewModel)proxy);

            // Return a view we can optionally position
            return(new LayoutZoneView(viewName, model));
        }
Example #10
0
        // -----------------

        async Task <TModel> BuildFromResultSets(DbDataReader reader)
        {
            TModel model = null;

            if ((reader != null) && (reader.HasRows))
            {
                model = ActivateInstanceOf <TModel> .Instance();

                await reader.ReadAsync();

                model.PopulateModel(reader);
            }

            return(model);
        }
Example #11
0
        public async Task <ICommandResult <TUser> > CreateAsync(
            string userName,
            string displayName,
            string email,
            string password,
            string[] roleNames = null)
        {
            // Build user
            var user = ActivateInstanceOf <TUser> .Instance();

            user.UserName    = userName;
            user.DisplayName = displayName;
            user.Email       = email;
            user.RoleNames   = new List <string>(roleNames ?? new string[] { DefaultRoles.Member });

            return(await CreateAsync(user, password));
        }
Example #12
0
        public TType ConvertToType <TType>() where TType : class, ITag
        {
            var tag = ActivateInstanceOf <TType> .Instance();

            tag.Id             = TagId;
            tag.FeatureId      = FeatureId;
            tag.Name           = Name;
            tag.NameNormalized = NameNormalized;
            tag.Description    = Description;
            tag.Alias          = Alias;
            tag.TotalEntities  = TotalEntities;
            tag.TotalFollows   = TotalFollows;
            tag.LastSeenDate   = LastSeenDate;
            tag.CreatedUserId  = CreatedUserId;
            tag.CreatedDate    = CreatedDate;
            return(tag);
        }
Example #13
0
        public async Task <IPagedResults <TModel> > SelectAsync(IDbDataParameter[] dbParams)
        {
            PagedResults <TModel> results = null;

            using (var context = _dbContext)
            {
                results = await context.ExecuteReaderAsync(
                    CommandType.StoredProcedure,
                    "SelectEntityRepliesPaged",
                    async reader =>
                {
                    if ((reader != null) && (reader.HasRows))
                    {
                        var output = new PagedResults <TModel>();
                        while (await reader.ReadAsync())
                        {
                            var reply = ActivateInstanceOf <TModel> .Instance();
                            reply.PopulateModel(reader);
                            output.Data.Add(reply);
                        }

                        if (await reader.NextResultAsync())
                        {
                            if (reader.HasRows)
                            {
                                await reader.ReadAsync();
                                output.PopulateTotal(reader);
                            }
                        }

                        return(output);
                    }

                    return(null);
                },
                    dbParams);
            }

            return(results);
        }
Example #14
0
 public static async Task <T> DeserializeGenericTypeAsync <T>(
     this ISerializable serializable, string data) where T : class
 {
     return(await((ISerializable)ActivateInstanceOf <T> .Instance()).DeserializeAsync <T>(data));
 }