예제 #1
0
        private void Initialize()
        {
            if (_ContentID == Guid.Empty)
            {
                using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString)) {
                    string SQL = "SELECT ContentID " +
                                 "FROM [cms_Content] " +
                                 "WHERE ModuleID = @ModuleID " +
                                 "AND IsDraft = 0 " +
                                 "AND UpdateDate IS NULL";
                    using (SqlCommand cmd = new SqlCommand(SQL, cn)) {
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.Add("ModuleID", SqlDbType.UniqueIdentifier).Value = ModuleID;

                        cmd.Connection.Open();
                        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow);
                        if (dr.HasRows)
                        {
                            dr.Read();
                            _ContentID = dr.GetGuid(0);
                        }
                        cmd.Connection.Close();
                    }
                }
            }

            if (_ContentID == Guid.Empty)
            {
                //still not found - at least get the containing page's information
                using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString)) {
                    string SQL = "SELECT p.VirtualPath, p.PageID, m.ModuleName, mt.ModuleTypeName, ps.PageSectionName, p.Locale " +
                                 "	FROM cms_Module m JOIN cms_Page p ON m.PageID = p.PageID "+
                                 "	JOIN cms_ModuleType mt ON m.ModuleTypeID = mt.ModuleTypeID "+
                                 "	JOIN cms_PageSection ps ON m.PageSectionID = ps.PageSectionID "+
                                 "	WHERE m.ModuleID = @ModuleID";
                    using (SqlCommand cmd = new SqlCommand(SQL, cn)) {
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.Add("ModuleID", SqlDbType.UniqueIdentifier).Value = ModuleID;

                        cmd.Connection.Open();
                        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow);
                        if (dr.HasRows)
                        {
                            dr.Read();
                            _Locale          = dr[5].ToString();
                            _ModuleName      = dr[2].ToString();
                            _ModuleTypeName  = dr[3].ToString();
                            _PageID          = dr.GetGuid(1);
                            _PageSectionName = dr[4].ToString();
                            _PageURL         = dr[0].ToString();
                        }
                        cmd.Connection.Close();
                    }
                }
            }
            else
            {
                using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString)) {
                    string SQL = "SELECT c.ModuleID, c.Contents, c.IsDraft, p.VirtualPath, p.PageID, " +
                                 "	s.MetaTitle, m.ModuleName, mt.ModuleTypeName, ps.PageSectionName, p.Locale "+
                                 "	FROM [cms_Content] c JOIN cms_Module m ON c.ModuleID = m.ModuleID "+
                                 "	JOIN cms_Page p ON m.PageID = p.PageID "+
                                 "	JOIN cms_ModuleType mt ON m.ModuleTypeID = mt.ModuleTypeID "+
                                 "	JOIN cms_PageSection ps ON m.PageSectionID = ps.PageSectionID "+
                                 "	LEFT JOIN cms_SEO s ON p.PageID = s.EntityGUID "+
                                 "	WHERE ContentID = @ContentID";
                    using (SqlCommand cmd = new SqlCommand(SQL, cn)) {
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.Add("ContentID", SqlDbType.UniqueIdentifier).Value = _ContentID;

                        cmd.Connection.Open();
                        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow);
                        if (dr.HasRows)
                        {
                            dr.Read();
                            _Contents        = dr[1].ToString();
                            _Locale          = dr[9].ToString();
                            _ModuleID        = dr.GetGuid(0);
                            _ModuleName      = dr[6].ToString();
                            _ModuleTypeName  = dr[7].ToString();
                            _PageID          = dr.GetGuid(4);
                            _PageSectionName = dr[8].ToString();
                            _PageTitle       = dr[5].ToString();
                            _PageURL         = dr[3].ToString();
                        }
                        else
                        {
                            _ContentID = Guid.Empty;
                        }
                        cmd.Connection.Close();
                    }
                    if (!string.IsNullOrEmpty(_Contents))
                    {
                        try {
                            VideoSaveModel         vidSaveModel = new VideoSaveModel();
                            System.Xml.XmlDocument doc          = new System.Xml.XmlDocument();
                            doc.LoadXml(_Contents);
                            System.Xml.XmlNodeReader reader            = new System.Xml.XmlNodeReader(doc.DocumentElement);
                            System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(vidSaveModel.GetType());
                            vidSaveModel = (VideoSaveModel)ser.Deserialize(reader);

                            _VideoURL    = vidSaveModel.URL;
                            _VideoSource = vidSaveModel.Src;
                            _Height      = vidSaveModel.Height;
                            _Width       = vidSaveModel.Width;
                        } catch {
                        }
                    }
                }
            }
        }
예제 #2
0
        public void SaveChanges(ContentVideoViewModel data)
        {
            VideoSaveModel videoSaveModel = new VideoSaveModel();

            videoSaveModel.Src    = data.VideoSource;
            videoSaveModel.URL    = data.VideoURL;
            videoSaveModel.Height = data.Height;
            videoSaveModel.Width  = data.Width;

            System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(videoSaveModel.GetType());
            System.Text.StringBuilder sb     = new System.Text.StringBuilder();
            System.IO.StringWriter    writer = new System.IO.StringWriter(sb);
            ser.Serialize(writer, videoSaveModel);

            this.Contents = sb.ToString();
        }