예제 #1
0
        /// <summary>
        /// Retrieves dashboard gadgets for a given Dashboard page and fill up given DTO object collection.
        /// </summary>
        /// <param name="page">Dashboard page DTO Object.</param>
        private static void ReadDashboardGadgets(DashboardPageDto page)
        {
            const string sql = @"
SELECT   [Id]
        ,[Guid]
        ,[Name]
        ,[GadgetType]
        ,[Settings]
        ,[IsLocked]
FROM    [DashboardGadgets]
WHERE   [DashboardPageId] = @pageId";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;
                if (cn.State != ConnectionState.Open)
                {
                    cn.Open();
                }

                using (var cmd = new SqlCommand(sql, cn))
                {
                    cmd.Parameters.AddWithValue("@pageId", page.Id);

                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var gadgetDto = new DashboardGadgetDto
                                                {
                                                    Id = reader.GetInt32(0),
                                                    Guid = reader.GetGuid(1),
                                                    Name = reader.GetString(2),
                                                    GadgetType = reader.GetString(3),
                                                    Settings = reader.GetString(4),
                                                    IsLocked = reader.GetSafeBool(5)
                                                };

                            page.Gadgets.Add(gadgetDto);
                        }
                    }
                }
            }
        }