Advertisement
Sonic3R

BusinessLayer

Oct 21st, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.13 KB | None | 0 0
  1.  
  2.    public class BusinessLayerArcht
  3.    {
  4.       /// <summary>
  5.       /// list of categories
  6.       /// </summary>
  7.       private List<CategoriesCtrlDto> _categories;
  8.  
  9.       /// <summary>
  10.       /// call to urlstorage class
  11.       /// </summary>
  12.       private UrlStorage store = UrlStorage.instance;
  13.      
  14.       /// <summary>
  15.       /// public constructor
  16.       /// </summary>
  17.       public BusinessLayerArcht() {
  18.       }
  19.  
  20.       /// <summary>
  21.       /// Load categories
  22.       /// </summary>
  23.       public void Load() {
  24.          _categories = store.readXMLtoLIST();
  25.       }
  26.  
  27.       /// <summary>
  28.       /// browse the category and get the matched name
  29.       /// </summary>
  30.       /// <param name="name"></param>
  31.       /// <returns></returns>
  32.       private CategoriesCtrlDto GetCategWithName(string name) {
  33.          CategoriesCtrlDto categ = null;
  34.  
  35.          foreach ( CategoriesCtrlDto ct in _categories ) {
  36.             if ( ct.Name == name ) {
  37.                categ = ct;
  38.                break;
  39.             }
  40.          }
  41.  
  42.          return categ;
  43.       }
  44.  
  45.       /// <summary>
  46.       /// add link function, it has lists to sent to data layer for insert process
  47.       /// </summary>
  48.       /// <param name="source"></param>
  49.       /// <param name="Categ"></param>
  50.       /// <param name="lks"></param>
  51.       /// <returns></returns>
  52.       public bool add_link( string link_name, string link_url, string link_descr, string category_name ) {
  53.  
  54.          //bool if_exist = false;
  55.          bool added_successfully = false;
  56.  
  57.          if ( string.IsNullOrEmpty( link_name ) )
  58.             throw new ArgumentNullException( "add_link link_name BL" );
  59.          if ( string.IsNullOrEmpty( category_name ) )
  60.             throw new ArgumentNullException( "add_link category_name BL" );
  61.          if ( string.IsNullOrEmpty( link_url ) )
  62.             throw new ArgumentNullException( "add_link link_url BL" );
  63.          if ( string.IsNullOrEmpty( link_descr ) )
  64.             throw new ArgumentNullException( "add_link link_descr BL" );
  65.  
  66.          CategoriesCtrlDto categ = GetCategWithName(category_name);
  67.          
  68.          if(categ != null)
  69.          {
  70.             if ( categ.LinkExists( link_url ) ) {
  71.                throw new ArgumentOutOfRangeException( "add link BL" );
  72.             } else {
  73.                List<LinksCtrlDto> lists = categ.AddLink( link_url, link_name, link_descr );
  74.                _categories.Add( categ );
  75.  
  76.                added_successfully = store.add_link(category_name,link_url,link_name,link_descr);
  77.             }
  78.          }
  79.          else
  80.          {
  81.             throw new ArgumentNullException( "find category BL" );
  82.          }          
  83.  
  84.          return added_successfully;
  85.       }
  86.  
  87.  
  88.       /// <summary>
  89.       /// add a category and create a list of category and send to DL for insert process
  90.       /// </summary>
  91.       /// <param name="source"></param>
  92.       /// <param name="category_name"></param>
  93.       /// <returns></returns>
  94.       public bool add_category( string category_name ) {
  95.  
  96.          //bool if_exist = false;
  97.          bool added_successfully = false;
  98.  
  99.          if ( string.IsNullOrEmpty( category_name ) )
  100.             throw new ArgumentNullException( "add_category link_descr BL" );
  101.  
  102.          CategoriesCtrlDto categ = GetCategWithName( category_name );
  103.  
  104.          if ( categ != null ) {
  105.             throw new ArgumentOutOfRangeException( "add_category BL" );
  106.          } else {
  107.             _categories.Add( new CategoriesCtrlDto( category_name, null ) );
  108.             added_successfully = store.add_category( category_name );
  109.          }
  110.  
  111.          return added_successfully;
  112.       }
  113.  
  114.  
  115.       /// <summary>
  116.       /// Delete a link and add to a list to be passed to DL for deletion process
  117.       /// after if the deletion process returns true then we can remove that link from the list
  118.       /// </summary>
  119.       /// <param name="source"></param>
  120.       /// <param name="link_url"></param>
  121.       /// <param name="category_name"></param>
  122.       /// <returns></returns>
  123.       public bool delete_link(string link_url, string category_name) {
  124.        
  125.          bool removed_successfully = false;
  126.        
  127.  
  128.          if ( string.IsNullOrEmpty( link_url ) )
  129.             throw new ArgumentNullException( "delete_link link_url BL" );
  130.          if ( string.IsNullOrEmpty( category_name ) )
  131.             throw new ArgumentNullException( "delete_link link_url BL" );
  132.          
  133.          CategoriesCtrlDto categ = GetCategWithName( category_name );
  134.  
  135.          if ( categ != null ) {
  136.             if ( categ.LinkExists( link_url ) ) {            
  137.                removed_successfully = store.delete_link( category_name, link_url );
  138.                categ.DeleteLink( link_url );
  139.             }
  140.          } else {
  141.             throw new ArgumentNullException( "delete_link BL" );
  142.          }      
  143.  
  144.             return removed_successfully;  
  145.       }
  146.  
  147.  
  148.       /// <summary>
  149.       /// delete a category (if it exists) and send parameter to DL
  150.       /// for deletion process
  151.       /// </summary>
  152.       /// <param name="source"></param>
  153.       /// <param name="category_name"></param>
  154.       /// <returns></returns>
  155.       public bool delete_category( string category_name ) {
  156.          //bool if_exist = false;
  157.          bool removed_successfully = false;
  158.  
  159.          if ( string.IsNullOrEmpty( category_name ) )
  160.             throw new ArgumentNullException( "remove_category cat_name BL" );
  161.  
  162.          CategoriesCtrlDto categ = GetCategWithName( category_name );
  163.  
  164.          if ( categ == null ) {
  165.             throw new ArgumentOutOfRangeException( "remove_category BL" );
  166.          } else {
  167.             removed_successfully = store.delete_category( category_name );
  168.             _categories.Remove( categ );
  169.          }
  170.  
  171.          return removed_successfully;
  172.       }
  173.  
  174.  
  175.       /// <summary>
  176.       /// set List as readonly collection
  177.       /// </summary>
  178.       public ReadOnlyCollection<CategoriesCtrlDto> Categories {
  179.          get {
  180.             if ( this._categories == null )
  181.                throw new ArgumentNullException( "ReadonlyCategory BL Exception" );
  182.             else
  183.             return _categories.AsReadOnly();
  184.          }
  185.  
  186.       }
  187.    }
  188.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement