meco

ForumBLL.cs

Apr 7th, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data;
  6. using ForumTableAdapters;
  7.  
  8. /// <summary>
  9. /// Summary description for ForumCategoryBLL
  10. /// </summary>
  11. public class ForumBLL
  12. {
  13.     tblForumCategoriesTableAdapter ForumCategoriesTableAdapter = new tblForumCategoriesTableAdapter();
  14.     tblForumPostsTableAdapter ForumPostsTableAdapter = new tblForumPostsTableAdapter();
  15.     public ForumBLL()
  16.     {
  17.         // TODO: Add constructor logic here
  18.     }
  19.  
  20.     public DataTable GetForumCategories()
  21.     {
  22.         return ForumCategoriesTableAdapter.GetForumCategories();
  23.     }
  24.  
  25.     public void CategorySave(string _categoryName, string _categoryDescription)
  26.     {
  27.         DateTime Today = DateTime.Now;
  28.         ForumCategoriesTableAdapter.Insert(_categoryName, GenerateUrlName(_categoryName), _categoryDescription, Today, Today, 0);
  29.        
  30.     }
  31.  
  32.     private string GenerateUrlName(string _name)
  33.     {
  34.         string ReturnVal = _name.ToLower();
  35.  
  36.         ReturnVal = ReturnVal.TrimStart();
  37.         ReturnVal = ReturnVal.TrimEnd();
  38.         ReturnVal = ReturnVal.Replace("æ", "ae");
  39.         ReturnVal = ReturnVal.Replace("ø", "oe");
  40.         ReturnVal = ReturnVal.Replace("å", "aa");
  41.         ReturnVal = ReturnVal.Replace("#", "");
  42.         ReturnVal = ReturnVal.Replace("!", "");
  43.         ReturnVal = ReturnVal.Replace("%", "");
  44.         ReturnVal = ReturnVal.Replace("&", "");
  45.         ReturnVal = ReturnVal.Replace("/", "");
  46.         ReturnVal = ReturnVal.Replace(" ", "-");
  47.         ReturnVal = ReturnVal.Replace("+", "-");
  48.         ReturnVal = ReturnVal.Replace("?", "");
  49.         ReturnVal = ReturnVal.Replace("@", "");
  50.         ReturnVal = ReturnVal.Replace("*", "");
  51.         ReturnVal = ReturnVal.Replace("(", "");
  52.         ReturnVal = ReturnVal.Replace(")", "");
  53.         ReturnVal = ReturnVal.Replace("[", "");
  54.         ReturnVal = ReturnVal.Replace("]", "");
  55.         ReturnVal = ReturnVal.Replace("{", "");
  56.         ReturnVal = ReturnVal.Replace("}", "");
  57.         ReturnVal = ReturnVal.Replace("%", "");
  58.         ReturnVal = ReturnVal.Replace("€", "");
  59.         ReturnVal = ReturnVal.Replace("$", "");
  60.         ReturnVal = ReturnVal.Replace("§", "");
  61.         return ReturnVal;
  62.     }
  63.  
  64.     private string Check_PostUrlName(string _postUrlName)
  65.     {
  66.         return ForumPostsTableAdapter.Check_PostUrlName(_postUrlName);
  67.     }
  68.  
  69.     private string Find_PostUrlName(string _postUrlName)
  70.     {
  71.         string UrlName = _postUrlName;
  72.         string NewUrlName = Check_PostUrlName(_postUrlName);
  73.  
  74.         if (!string.IsNullOrEmpty(NewUrlName))
  75.         {
  76.             int counter = 0;
  77.  
  78.             bool FoundNewUrlName = false;
  79.             while (FoundNewUrlName == false)
  80.             {
  81.                 counter = counter += 1;
  82.  
  83.                 NewUrlName = Check_PostUrlName(UrlName + counter);
  84.                 if (string.IsNullOrEmpty(NewUrlName))
  85.                 {
  86.                     FoundNewUrlName = true;
  87.                     NewUrlName = ForumPostsTableAdapter.Check_PostUrlName(NewUrlName);
  88.                 }
  89.             }
  90.         }
  91.  
  92.         if (string.IsNullOrEmpty(NewUrlName))
  93.         {
  94.             return UrlName;
  95.         }
  96.         else
  97.         {
  98.  
  99.             return NewUrlName;
  100.            
  101.         }
  102.     }
  103.  
  104.     public DataTable GetForumPosts(string _postUrlName)
  105.     {
  106.       return ForumPostsTableAdapter.GetForumPosts(_postUrlName);
  107.     }
  108.  
  109.     public void PostSave(string _postSubject, string _postContent, string _postUserName, string _postUserEmail, string _forumUrlName)
  110.     {
  111.         DateTime Today = DateTime.Now;
  112.         string UrlName = GenerateUrlName(_postSubject);
  113.         string NewUrlName = Find_PostUrlName(UrlName);
  114.  
  115.         ForumPostsTableAdapter.Insert(_postSubject, NewUrlName, _postContent, Today, Today, 0, _postUserName, _postUserEmail, GetCategoryIdFromUrlName(_forumUrlName));
  116.     }
  117.  
  118.     public int GetCategoryIdFromUrlName(string _urlName)
  119.     {
  120.         return (int)ForumCategoriesTableAdapter.GetCategoryIdFromUrlName(_urlName);
  121.     }
  122.  
  123.     private void UpdateCategoryHits(string _urlName)
  124.     {
  125.        // ForumCategoriesTableAdapter.UpdateCategoryHits()
  126.     }
  127.  
  128.     public DataTable GetForumPost(string _postUrlName)
  129.     {
  130.         return ForumPostsTableAdapter.GetForumPost(_postUrlName);
  131.     }
  132.  
  133.  
  134.     private string Check_CategoryUrlName(string _categoryUrlName)
  135.     {
  136.      
  137.        return  ForumCategoriesTableAdapter.Check_CategoryUrlName(_categoryUrlName);
  138.            
  139.            
  140.     }
  141.  
  142.     private string Find_CategoryUrlName(string _categoryUrlName)
  143.     {
  144.         string UrlName = _categoryUrlName;
  145.         string NewUrlName = Check_CategoryUrlName(_categoryUrlName);
  146.  
  147.         if (!string.IsNullOrEmpty(NewUrlName))
  148.         {
  149.             int counter = 0;
  150.  
  151.             bool FoundNewUrlName = false;
  152.             while (FoundNewUrlName == false)
  153.             {
  154.                 counter = counter += 1;
  155.  
  156.                 NewUrlName = Check_CategoryUrlName(UrlName + counter);
  157.                 if (string.IsNullOrEmpty(NewUrlName))
  158.                 {
  159.                     FoundNewUrlName = true;
  160.                     NewUrlName = ForumCategoriesTableAdapter.Check_CategoryUrlName(NewUrlName);
  161.                 }
  162.             }
  163.         }
  164.  
  165.         if (string.IsNullOrEmpty(NewUrlName))
  166.         {
  167.             return UrlName;
  168.         }
  169.         else
  170.         {
  171.  
  172.             return NewUrlName;
  173.  
  174.         }
  175.     }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment