예제 #1
0
        /// <summary>
        /// Imports the module (IPortable interface)
        /// </summary>
        /// <param name="moduleID">The module ID.</param>
        /// <param name="content">The content.</param>
        /// <param name="version">The version.</param>
        /// <param name="userId">The user id.</param>
        public void ImportModule(int moduleID, string content, string version, int userId)
        {
            Version vers = new Version(version);
            if (vers > new Version("5.0.0"))
            {
                XElement xRoot = XElement.Parse(content);
                Dictionary<int, int> idTrans = new Dictionary<int, int>();

                // First we import the categories
                List<CategoryInfo> lstCategories = new List<CategoryInfo>();
                XElement xCategories = xRoot.Element("categories");
                foreach (var xCategory in xCategories.Elements())
                {
                    // translate the parentid's to new values
                    int oldParentId = Int32.Parse(xCategory.Element("categoryparentid").Value, CultureInfo.InvariantCulture);
                    int newParentId = 0;
                    if (oldParentId > 0 && idTrans.ContainsKey(oldParentId))
                        newParentId = idTrans[oldParentId];

                    // Fill category properties
                    CategoryInfo category = new CategoryInfo();
                    category.ModuleId = moduleID;
                    category.FaqCategoryParentId = newParentId;
                    category.FaqCategoryName = xCategory.Element("categoryname").Value;
                    category.FaqCategoryDescription = xCategory.Element("categorydescription").Value;
                    category.ViewOrder = Int32.Parse(xCategory.Element("vieworder").Value, CultureInfo.InvariantCulture);

                    // add category and save old and new id to translation dictionary
                    int oldCategoryId = Int32.Parse(xCategory.Element("categoryid").Value, CultureInfo.InvariantCulture);
                    int newCategoryId = AddCategory(category);
                    idTrans.Add(oldCategoryId, newCategoryId);
                }

                // Next import the faqs
                List<FAQsInfo> lstFaqs = new List<FAQsInfo>();
                XElement xFaqs = xRoot.Element("faqs");
                foreach (var xFaq in xFaqs.Elements())
                {
                    // translate id with help of translation dictionary build before
                    int oldCategoryId = Int32.Parse(xFaq.Element("categoryid").Value, CultureInfo.InvariantCulture);
                    int newCategoryId = -1;
                    if (idTrans.ContainsKey(oldCategoryId))
                        newCategoryId = idTrans[oldCategoryId];

                    // Fill FAQs properties
                    FAQsInfo faq = new FAQsInfo();
                    faq.ModuleID = moduleID;
                    faq.Question = xFaq.Element("question").Value;
                    faq.Answer = xFaq.Element("answer").Value;
                    faq.CategoryId = newCategoryId;
                    faq.CreatedDate = DateTime.Parse(xFaq.Element("creationdate").Value);
                    faq.DateModified = DateTime.Now;
                    faq.FaqHide = Boolean.Parse(xFaq.Element("faqhide").Value);

                    // These dates might be emtpy
                    try
                    {
                        faq.PublishDate = DateTime.Parse(xFaq.Element("publishdate").Value);
                    }
                    catch (Exception)
                    {
                        faq.PublishDate = null;
                    }

                    try
                    {
                        faq.ExpireDate = DateTime.Parse(xFaq.Element("expiredate").Value);
                    }
                    catch (Exception)
                    {
                        faq.ExpireDate = null;
                    }

                    // Add Faq to database
                    AddFAQ(faq);
                }
            }
            else
            {
                ArrayList catNames = new ArrayList();
                ArrayList Question = new ArrayList();
                XmlNode xmlFaq;
                XmlNode xmlFaqs = Globals.GetContent(content, "faqs");

                //' check if category exists. if not create category
                foreach (XmlNode tempLoopVar_xmlFAQ in xmlFaqs)
                {
                    xmlFaq = tempLoopVar_xmlFAQ;
                    if ((xmlFaq["catname"].InnerText != Null.NullString) && (!catNames.Contains(xmlFaq["catname"].InnerText)))
                    {
                        catNames.Add(xmlFaq["catname"].InnerText);

                        CategoryInfo objCat = new CategoryInfo();
                        objCat.ModuleId = moduleID;
                        objCat.FaqCategoryName = xmlFaq["catname"].InnerText;
                        objCat.FaqCategoryDescription = xmlFaq["catdescription"].InnerText;

                        AddCategory(objCat);
                    }
                }
                // check is question is empty. if empty is category.
                int loop = 0;
                foreach (XmlNode tempLoopVar_xmlFAQ in xmlFaqs)
                {
                    loop++;
                    xmlFaq = tempLoopVar_xmlFAQ;

                    if (xmlFaq["question"].InnerText != Null.NullString && xmlFaq["question"].InnerText != string.Empty)
                    {
                        FAQsInfo objFAQs = new FAQsInfo();
                        objFAQs.ModuleID = moduleID;
                        objFAQs.Question = xmlFaq["question"].InnerText;
                        objFAQs.Answer = xmlFaq["answer"].InnerText;
                        string faqCategoryName = xmlFaq["catname"].InnerText;

                        // Check if creationdate exists in export, if nothing set current date. else import
                        if (xmlFaq["creationdate"] == null)
                        {
                            objFAQs.CreatedDate = DateTime.Now;
                            objFAQs.DateModified = DateTime.Now;
                        }
                        else
                        {
                            objFAQs.CreatedDate = DateTime.Parse(xmlFaq["creationdate"].InnerText);
                            objFAQs.DateModified = DateTime.Parse(xmlFaq["datemodified"].InnerText);
                        }

                        if (xmlFaq["vieworder"] != null)
                        {
                            objFAQs.ViewOrder = int.Parse(xmlFaq["vieworder"].InnerText);
                        }
                        else
                        {
                            objFAQs.ViewOrder = loop;
                        }
                        objFAQs.CreatedByUser = userId.ToString();

                        bool foundCat = false;
                        foreach (CategoryInfo objCat in ListCategories(moduleID, false))
                        {
                            if (faqCategoryName == objCat.FaqCategoryName)
                            {
                                objFAQs.CategoryId = objCat.FaqCategoryId;
                                foundCat = true;
                                break;
                            }
                        }

                        if (!foundCat)
                        {
                            objFAQs.CategoryId = null;
                        }

                        AddFAQ(objFAQs);
                    }
                }
            }

        }
예제 #2
0
 /// <summary>
 /// Adds the category.
 /// </summary>
 /// <param name="category">category info object to be inserted in the category table.</param>
 /// <returns>new category id</returns>
 public int AddCategory(CategoryInfo category)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<CategoryInfo>();
         if (category.FaqCategoryParentId == 0)
             category.FaqCategoryParentId = null;
         rep.Insert(category);
         return category.FaqCategoryId;
     }
 }
예제 #3
0
 /// <summary>
 /// Updates a category.
 /// </summary>
 /// <param name="category">category info object to be inserted in the category table.</param>
 public void UpdateCategory(CategoryInfo category)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<CategoryInfo>();
         if (category.FaqCategoryParentId == 0)
             category.FaqCategoryParentId = null;
         rep.Update(category);
     }
 }
예제 #4
0
		/// <summary>
		/// Handles the Click event of the cmdUpdate control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
		protected void cmdUpdate_Click(Object sender, EventArgs e)
		{

			FAQsController faqsController = new FAQsController();
			CategoryInfo categoryItem = new CategoryInfo();
			PortalSecurity objSecurity = new PortalSecurity();

			int parentCategoryId = Convert.ToInt32(drpParentCategory.SelectedValue);
			if (parentCategoryId < 0) 
				parentCategoryId = 0;

			// We do not allow for script or markup
			categoryItem.FaqCategoryParentId = parentCategoryId;
			categoryItem.FaqCategoryName = objSecurity.InputFilter(txtCategoryName.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);
			categoryItem.FaqCategoryDescription = objSecurity.InputFilter(txtCategoryDescription.Text, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
			categoryItem.ModuleId = ModuleId;

			try
			{
				RadTreeNode node = treeCategories.SelectedNode;
				if (node != null)
				{
					categoryItem.FaqCategoryId = Convert.ToInt32(node.Value);
					CategoryInfo originalCategoryItem = faqsController.GetCategory(categoryItem.FaqCategoryId);
					categoryItem.ViewOrder = originalCategoryItem.ViewOrder;
					faqsController.UpdateCategory(categoryItem);
				}
				else
				{
					categoryItem.ViewOrder = 999;
					faqsController.AddCategory(categoryItem);
				}
				faqsController.ReorderCategory(categoryItem.FaqCategoryParentId, ModuleId);
				Response.Redirect(Request.RawUrl);
			}
			catch (Exception exc) //Module failed to load
			{
				Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
예제 #5
0
		/// <summary>
		/// Binds the categories.
		/// </summary>
		private void BindCategories()
		{
			//Show the categories ?
			if (ShowCategories)
			{
				// Do we have unassigned categories ?
				bool noCat = false;
				foreach (FAQsInfo faq in FaqData)
				{
					if (faq.CategoryId == null)
					{
						noCat = true;
						break;
					}
				}
				pnlShowCategories.Visible = true;

				//Build the Catagories List.
				FAQsController FAQsController = new FAQsController();
				ArrayList categories = new ArrayList();

				//Empty Category
				CategoryInfo emptyCategory = new CategoryInfo();
				emptyCategory.FaqCategoryId = -1;
				emptyCategory.FaqCategoryName = Localization.GetString("EmptyCategory", LocalResourceFile);

				//All Categories
				CategoryInfo allCategories = new CategoryInfo();
				allCategories.FaqCategoryId = -2;
				allCategories.FaqCategoryName = Localization.GetString("AllCategory", LocalResourceFile);

			    IEnumerable<CategoryInfo> cats = FAQsController.ListCategoriesHierarchical(ModuleId, !ShowEmptyCategories);

				switch (ShowCategoryType)
				{
					case 0:
						if (noCat)
							categories.Add(emptyCategory);
				        foreach (CategoryInfo cat in cats)
				        {
				            categories.Add(cat);
				        }
						listCategories.DataSource = categories;
						listCategories.DataBind();
						mvShowCategoryType.SetActiveView(vShowCategoryTypeList);
						pnlShowCategoryTypeDropdown.Visible = false;
						break;

					case 1:
						categories.Add(allCategories);
						if (noCat)
							categories.Add(emptyCategory);
                        foreach (CategoryInfo cat in cats)
                        {
                            categories.Add(cat);
                        }
						List<CategoryInfo> lst = new List<CategoryInfo>();
						foreach (CategoryInfo cat in categories)
						{
							lst.Add(cat);
						}
						treeCategories.DataTextField = "FaqCategoryName";
						treeCategories.DataFieldID = "FaqCategoryId";
						treeCategories.DataFieldParentID = "FaqCategoryParentId";
						treeCategories.DataSource = lst;
						treeCategories.DataBind();
						if (!IsPostBack)
							treeCategories.Nodes[0].Selected = true;
						mvShowCategoryType.SetActiveView(vShowCategoryTypeTree);
						pnlShowCategoryTypeDropdown.Visible = false;
						break;
					case 2:
						categories.Add(allCategories);
						if (noCat)
							categories.Add(emptyCategory);
                        foreach (CategoryInfo cat in cats)
                        {
                            categories.Add(cat);
                        }
						foreach (CategoryInfo cat in categories)
						{
							drpCategories.Items.Add(new ListItem(new string('.',cat.Level * 3) + cat.FaqCategoryName,cat.FaqCategoryId.ToString()));
						}
						if (!IsPostBack)
							drpCategories.SelectedIndex = 0;
						pnlShowCategoryTypeDropdown.Visible = true;
						pnlShowCategories.Visible = false;
						pnlSortbox.Style.Add("float", "right");
						pnlSortbox.Style.Add("text-align", "right");
						break;
				}
			}
			else
			{
				pnlShowCategories.Visible = false;
			}
		}
예제 #6
0
        /// <summary>
        /// Imports the module (IPortable interface)
        /// </summary>
        /// <param name="moduleID">The module ID.</param>
        /// <param name="content">The content.</param>
        /// <param name="version">The version.</param>
        /// <param name="userId">The user id.</param>
        public void ImportModule(int moduleID, string content, string version, int userId)
        {
            Version vers = new Version(version);

            if (vers > new Version("5.0.0"))
            {
                XElement xRoot = XElement.Parse(content);
                Dictionary <int, int> idTrans = new Dictionary <int, int>();

                // First we import the categories
                List <CategoryInfo> lstCategories = new List <CategoryInfo>();
                XElement            xCategories   = xRoot.Element("categories");
                foreach (var xCategory in xCategories.Elements())
                {
                    // translate the parentid's to new values
                    int oldParentId = Int32.Parse(xCategory.Element("categoryparentid").Value, CultureInfo.InvariantCulture);
                    int newParentId = 0;
                    if (oldParentId > 0 && idTrans.ContainsKey(oldParentId))
                    {
                        newParentId = idTrans[oldParentId];
                    }

                    // Fill category properties
                    CategoryInfo category = new CategoryInfo();
                    category.ModuleId               = moduleID;
                    category.FaqCategoryParentId    = newParentId;
                    category.FaqCategoryName        = xCategory.Element("categoryname").Value;
                    category.FaqCategoryDescription = xCategory.Element("categorydescription").Value;
                    category.ViewOrder              = Int32.Parse(xCategory.Element("vieworder").Value, CultureInfo.InvariantCulture);

                    // add category and save old and new id to translation dictionary
                    int oldCategoryId = Int32.Parse(xCategory.Element("categoryid").Value, CultureInfo.InvariantCulture);
                    int newCategoryId = AddCategory(category);
                    idTrans.Add(oldCategoryId, newCategoryId);
                }

                // Next import the faqs
                List <FAQsInfo> lstFaqs = new List <FAQsInfo>();
                XElement        xFaqs   = xRoot.Element("faqs");
                foreach (var xFaq in xFaqs.Elements())
                {
                    // translate id with help of translation dictionary build before
                    int oldCategoryId = Int32.Parse(xFaq.Element("categoryid").Value, CultureInfo.InvariantCulture);
                    int newCategoryId = -1;
                    if (idTrans.ContainsKey(oldCategoryId))
                    {
                        newCategoryId = idTrans[oldCategoryId];
                    }

                    // Fill FAQs properties
                    FAQsInfo faq = new FAQsInfo();
                    faq.ModuleID     = moduleID;
                    faq.Question     = xFaq.Element("question").Value;
                    faq.Answer       = xFaq.Element("answer").Value;
                    faq.CategoryId   = newCategoryId;
                    faq.CreatedDate  = DateTime.Parse(xFaq.Element("creationdate").Value);
                    faq.DateModified = DateTime.Now;
                    faq.FaqHide      = Boolean.Parse(xFaq.Element("faqhide").Value);

                    // These dates might be emtpy
                    try
                    {
                        faq.PublishDate = DateTime.Parse(xFaq.Element("publishdate").Value);
                    }
                    catch (Exception)
                    {
                        faq.PublishDate = null;
                    }

                    try
                    {
                        faq.ExpireDate = DateTime.Parse(xFaq.Element("expiredate").Value);
                    }
                    catch (Exception)
                    {
                        faq.ExpireDate = null;
                    }

                    // Add Faq to database
                    AddFAQ(faq);
                }
            }
            else
            {
                ArrayList catNames = new ArrayList();
                ArrayList Question = new ArrayList();
                XmlNode   xmlFaq;
                XmlNode   xmlFaqs = Globals.GetContent(content, "faqs");

                //' check if category exists. if not create category
                foreach (XmlNode tempLoopVar_xmlFAQ in xmlFaqs)
                {
                    xmlFaq = tempLoopVar_xmlFAQ;
                    if ((xmlFaq["catname"].InnerText != Null.NullString) && (!catNames.Contains(xmlFaq["catname"].InnerText)))
                    {
                        catNames.Add(xmlFaq["catname"].InnerText);

                        CategoryInfo objCat = new CategoryInfo();
                        objCat.ModuleId               = moduleID;
                        objCat.FaqCategoryName        = xmlFaq["catname"].InnerText;
                        objCat.FaqCategoryDescription = xmlFaq["catdescription"].InnerText;

                        AddCategory(objCat);
                    }
                }
                // check is question is empty. if empty is category.
                int loop = 0;
                foreach (XmlNode tempLoopVar_xmlFAQ in xmlFaqs)
                {
                    loop++;
                    xmlFaq = tempLoopVar_xmlFAQ;

                    if (xmlFaq["question"].InnerText != Null.NullString && xmlFaq["question"].InnerText != string.Empty)
                    {
                        FAQsInfo objFAQs = new FAQsInfo();
                        objFAQs.ModuleID = moduleID;
                        objFAQs.Question = xmlFaq["question"].InnerText;
                        objFAQs.Answer   = xmlFaq["answer"].InnerText;
                        string faqCategoryName = xmlFaq["catname"].InnerText;

                        // Check if creationdate exists in export, if nothing set current date. else import
                        if (xmlFaq["creationdate"] == null)
                        {
                            objFAQs.CreatedDate  = DateTime.Now;
                            objFAQs.DateModified = DateTime.Now;
                        }
                        else
                        {
                            objFAQs.CreatedDate  = DateTime.Parse(xmlFaq["creationdate"].InnerText);
                            objFAQs.DateModified = DateTime.Parse(xmlFaq["datemodified"].InnerText);
                        }

                        if (xmlFaq["vieworder"] != null)
                        {
                            objFAQs.ViewOrder = int.Parse(xmlFaq["vieworder"].InnerText);
                        }
                        else
                        {
                            objFAQs.ViewOrder = loop;
                        }
                        objFAQs.CreatedByUser = userId.ToString();

                        bool foundCat = false;
                        foreach (CategoryInfo objCat in ListCategories(moduleID, false))
                        {
                            if (faqCategoryName == objCat.FaqCategoryName)
                            {
                                objFAQs.CategoryId = objCat.FaqCategoryId;
                                foundCat           = true;
                                break;
                            }
                        }

                        if (!foundCat)
                        {
                            objFAQs.CategoryId = null;
                        }

                        AddFAQ(objFAQs);
                    }
                }
            }
        }
예제 #7
0
        private List <CategoryInfo> GetChildrenCategories(IEnumerable <CategoryInfo> categories, CategoryInfo category)
        {
            var childrens = new List <CategoryInfo>();

            foreach (var subCategory in categories.Where(c => c.FaqCategoryParentId == category.FaqCategoryId))
            {
                childrens.Add(subCategory);
                childrens.AddRange(GetChildrenCategories(categories, subCategory));
            }
            return(childrens);
        }
예제 #8
0
        /// <summary>
        /// Binds the categories.
        /// </summary>
        private void BindCategories()
        {
            //Show the categories ?
            if (ShowCategories)
            {
                // Do we have unassigned categories ?
                bool noCat = false;
                foreach (FAQsInfo faq in FaqData)
                {
                    if (faq.CategoryId == null)
                    {
                        noCat = true;
                        break;
                    }
                }
                pnlShowCategories.Visible = true;

                //Build the Catagories List.
                FAQsController FAQsController = new FAQsController();
                ArrayList      categories     = new ArrayList();

                //Empty Category
                CategoryInfo emptyCategory = new CategoryInfo();
                emptyCategory.FaqCategoryId   = -1;
                emptyCategory.FaqCategoryName = Localization.GetString("EmptyCategory", LocalResourceFile);
                emptyCategory.ModuleId        = ModuleId;
                emptyCategory.Level           = 0;
                emptyCategory.ViewOrder       = 998;

                //All Categories
                CategoryInfo allCategories = new CategoryInfo();
                allCategories.FaqCategoryId   = -2;
                allCategories.FaqCategoryName = Localization.GetString("AllCategory", LocalResourceFile);
                allCategories.ModuleId        = ModuleId;
                allCategories.Level           = 0;
                allCategories.ViewOrder       = 999;

                IEnumerable <CategoryInfo> cats = FAQsController.ListCategoriesHierarchical(ModuleId, !ShowEmptyCategories);

                switch (ShowCategoryType)
                {
                case 0:
                    if (noCat)
                    {
                        categories.Add(emptyCategory);
                    }
                    foreach (CategoryInfo cat in cats)
                    {
                        categories.Add(cat);
                    }
                    listCategories.DataSource = categories;
                    listCategories.DataBind();
                    mvShowCategoryType.SetActiveView(vShowCategoryTypeList);
                    pnlShowCategoryTypeDropdown.Visible = false;
                    break;

                case 1:
                    categories.Add(allCategories);
                    if (noCat)
                    {
                        categories.Add(emptyCategory);
                    }
                    foreach (CategoryInfo cat in cats)
                    {
                        categories.Add(cat);
                    }
                    // treeCategories fails with int? FaqCategoryParentId
                    // define a temp class that has no nullables
                    // set null ints to Null.NullInt
                    ArrayList lst = new ArrayList();
                    foreach (CategoryInfo cat in categories)
                    {
                        lst.Add(cat.ToTreeNode());
                    }
                    treeCategories.DataTextField     = "FaqCategoryName";
                    treeCategories.DataFieldID       = "FaqCategoryId";
                    treeCategories.DataFieldParentID = "FaqCategoryParentId";
                    treeCategories.DataSource        = lst;
                    treeCategories.DataBind();
                    if (!IsPostBack)
                    {
                        treeCategories.Nodes[0].Selected = true;
                    }
                    mvShowCategoryType.SetActiveView(vShowCategoryTypeTree);
                    pnlShowCategoryTypeDropdown.Visible = false;
                    break;

                case 2:
                    categories.Add(allCategories);
                    if (noCat)
                    {
                        categories.Add(emptyCategory);
                    }
                    foreach (CategoryInfo cat in cats)
                    {
                        categories.Add(cat);
                    }
                    foreach (CategoryInfo cat in categories)
                    {
                        drpCategories.Items.Add(new ListItem(new string('.', cat.Level * 3) + cat.FaqCategoryName, cat.FaqCategoryId.ToString()));
                    }
                    if (!IsPostBack)
                    {
                        drpCategories.SelectedIndex = 0;
                    }
                    pnlShowCategoryTypeDropdown.Visible = true;
                    pnlShowCategories.Visible           = false;
                    pnlSortbox.Style.Add("float", "right");
                    pnlSortbox.Style.Add("text-align", "right");
                    break;
                }
            }
            else
            {
                pnlShowCategories.Visible = false;
            }
        }