public int Add(ContentSlideModel data) { int SlideSerial = 0; string slideImage = ""; string slideContents = ""; if (!string.IsNullOrEmpty(data.SlideImageFile)) { string baseDirectory = "/assets/images/slideshow/" + data.ModuleID + "/"; Image objImage = Image.FromFile(HttpContext.Current.Server.MapPath(baseDirectory + data.SlideImageFile)); ImageSaveModel imageSaveModel = new ImageSaveModel(); imageSaveModel.Height = objImage.Height.ToString(); imageSaveModel.Width = objImage.Width.ToString(); imageSaveModel.AltText = data.SlideTitle; imageSaveModel.Src = data.SlideImageFile; System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(imageSaveModel.GetType()); System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter writer = new System.IO.StringWriter(sb); ser.Serialize(writer, imageSaveModel); slideImage = sb.ToString(); } else { slideContents = data.SlideContents; } using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString)) { string SQL = "INSERT INTO cms_Slideshow (ModuleID, SlideTitle, SlideContents, SlideImage, SlideLink, SortOrder) " + "OUTPUT INSERTED.SlideSerial " + "VALUES (@ModuleID, @SlideTitle, @SlideContents, @SlideImage, @SlideLink, @SortOrder) "; using (SqlCommand cmd = new SqlCommand(SQL, cn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.Add("ModuleID", SqlDbType.UniqueIdentifier).Value = data.ModuleID; cmd.Parameters.Add("SlideTitle", SqlDbType.VarChar).Value = data.SlideTitle ?? SqlString.Null; cmd.Parameters.Add("SlideContents", SqlDbType.VarChar).Value = slideContents; cmd.Parameters.Add("SlideImage", SqlDbType.VarChar).Value = slideImage; cmd.Parameters.Add("SlideLink", SqlDbType.VarChar).Value = data.SlideLink ?? SqlString.Null; cmd.Parameters.Add("SortOrder", SqlDbType.Int).Value = 0; cmd.Connection.Open(); SlideSerial = (int)cmd.ExecuteScalar(); cmd.Connection.Close(); } } return(SlideSerial); }
public void SaveChanges(ImageViewModel imageViewModel) { System.Drawing.Image objImage = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(imageViewModel.Filename)); ImageSaveModel imageSaveModel = new ImageSaveModel(); imageSaveModel.Height = objImage.Height.ToString(); imageSaveModel.Width = objImage.Width.ToString(); imageSaveModel.AltText = imageViewModel.AltText; imageSaveModel.Src = imageViewModel.Filename; System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(imageSaveModel.GetType()); System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter writer = new System.IO.StringWriter(sb); ser.Serialize(writer, imageSaveModel); this.Contents = sb.ToString(); }
public ContentSlide(int SlideSerial) { _SlideSerial = SlideSerial; using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString)) { string SQL = "SELECT [ModuleID], [SlideTitle], [SlideContents], [SlideImage], [SlideLink], [SortOrder] " + "FROM [cms_Slideshow] " + "WHERE SlideSerial = @SlideSerial"; using (SqlCommand cmd = new SqlCommand(SQL, cn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.Add("SlideSerial", SqlDbType.Int).Value = SlideSerial; cmd.Connection.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow); if (dr.HasRows) { dr.Read(); _ModuleID = dr.GetGuid(0); _SlideTitle = dr[1].ToString(); _SlideContents = dr[2].ToString(); _SlideImage = dr[3].ToString(); _SlideLink = dr[4].ToString(); _SortOrder = dr.GetInt32(5); } cmd.Connection.Close(); } if (!string.IsNullOrEmpty(_SlideImage)) { ImageSaveModel imageSaveModel = new ImageSaveModel(); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.LoadXml(_SlideImage); System.Xml.XmlNodeReader reader = new System.Xml.XmlNodeReader(doc.DocumentElement); System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(imageSaveModel.GetType()); imageSaveModel = (ImageSaveModel)ser.Deserialize(reader); _SlideImageFile = imageSaveModel.Src; _DimHeight = Convert.ToInt32(imageSaveModel.Height); _DimWidth = Convert.ToInt32(imageSaveModel.Width); } } }
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(); _URL = 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(); _URL = dr[3].ToString(); } else { _ContentID = Guid.Empty; } cmd.Connection.Close(); } if (!string.IsNullOrEmpty(_Contents)) { try { ImageSaveModel imageSaveModel = new ImageSaveModel(); 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(imageSaveModel.GetType()); //object obj = ser.Deserialize(reader); //imageSaveModel = (ImageSaveModel)obj; imageSaveModel = (ImageSaveModel)ser.Deserialize(reader); _AltText = imageSaveModel.AltText; _Filename = imageSaveModel.Src; _Height = imageSaveModel.Height; _Width = imageSaveModel.Width; } catch { _AltText = _Contents; } } } } }