void GetInfo() { if (!string.IsNullOrEmpty(PageSectionId)) { _rpoObj = new PageSectionsRepository(); PageSection PageSectionEnt = _rpoObj.LoadById(PageSectionId); if (PageSectionEnt != null) { txtSectionTitle.Text = PageSectionEnt.SectionTitle; //if (!string.IsNullOrEmpty(PageSectionEnt.ImageFile)) //{ // imgSection.ImageUrl = ConfigurationManager.AppSettings["Pages"].ToString() + PageSectionEnt.ImageFile; // imgSection.Visible = true; //} //else // imgSection.Visible = false; edSectionContent.Content = PageSectionEnt.SectionContent; try { ddlPage.SelectedValue = PageSectionEnt.PageId.ToString(); ddlLanguage.SelectedValue = PageSectionEnt.LanguageId.ToString(); } catch { ddlPage.SelectedIndex = -1; ddlLanguage.SelectedIndex = -1; } } } }
void Save() { string ImageFile = string.Empty; _rpoObj = new PageSectionsRepository(); #region Manage Item string FileName = string.Empty; _rpoObj._Obj.PageId = new Guid(ddlPage.SelectedValue.ToString()); _rpoObj._Obj.LanguageId = new Guid(ddlLanguage.SelectedValue.ToString()); _rpoObj._Obj.SectionTitle = txtSectionTitle.Text; _rpoObj._Obj.SectionContent = edSectionContent.Content; _rpoObj._Obj.IsDefault = chkIsDefault.Checked; if (string.IsNullOrEmpty(PageSectionId)) { _rpoObj._Obj.CreatedBy = new Guid(Request.Cookies["CooLoginUserId"].Value); if (fpld.PostedFile.FileName != "") { FileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(fpld.PostedFile.FileName); string PathUrl = Server.MapPath(ConfigurationManager.AppSettings["Pages"].ToString()) + FileName; fpld.SaveAs(PathUrl); // DAL.ImagesFact.ResizeWithCropResizeImage("", FileName, "Section"); _rpoObj._Obj.ImageFile = FileName; } PageSectionId = _rpoObj.Add().ToString(); //if (!string.IsNullOrEmpty(PageSectionId)) //{ // BackendMessages(101); //} //else //{ // BackendMessages(201); //} } else { _rpoObj._Obj = _rpoObj.LoadById(PageSectionId); _rpoObj._Obj.PageId = new Guid(ddlPage.SelectedValue); _rpoObj._Obj.LanguageId = new Guid(ddlLanguage.SelectedValue); _rpoObj._Obj.SectionTitle = txtSectionTitle.Text; _rpoObj._Obj.SectionContent = edSectionContent.Content; if (fpld.PostedFile.FileName != "") { if (_rpoObj._Obj.ImageFile != null) { DirectoryInfo di = new DirectoryInfo(Server.MapPath(ConfigurationManager.AppSettings["Pages"])); foreach (FileInfo fi in di.GetFiles()) { if (_rpoObj._Obj.ImageFile == fi.Name) { File.Delete(fi.Name); } } } FileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(fpld.PostedFile.FileName); string PathUrl = Server.MapPath(ConfigurationManager.AppSettings["Pages"].ToString()) + FileName; fpld.SaveAs(PathUrl); // DAL.ImagesFact.ResizeWithCropResizeImage("", FileName, "Section"); _rpoObj._Obj.ImageFile = FileName; } _rpoObj._Obj.ModifiedBy = new Guid(Request.Cookies["CooLoginUserId"].Value); if (_rpoObj.Edit()) { //lblMessge.Text = "Done, changes has been saved successfully!"; //msg.Attributes["class"] = "msg-success"; } else { //lblMessge.Text = "Error, Please try again later!"; //msg.Attributes["class"] = "msg-error"; } } #endregion }