Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BusinessLayerArcht
- {
- /// <summary>
- /// list of categories
- /// </summary>
- private List<CategoriesCtrlDto> _categories;
- /// <summary>
- /// call to urlstorage class
- /// </summary>
- private UrlStorage store = UrlStorage.instance;
- /// <summary>
- /// public constructor
- /// </summary>
- public BusinessLayerArcht() {
- }
- /// <summary>
- /// Load categories
- /// </summary>
- public void Load() {
- _categories = store.readXMLtoLIST();
- }
- /// <summary>
- /// browse the category and get the matched name
- /// </summary>
- /// <param name="name"></param>
- /// <returns></returns>
- private CategoriesCtrlDto GetCategWithName(string name) {
- CategoriesCtrlDto categ = null;
- foreach ( CategoriesCtrlDto ct in _categories ) {
- if ( ct.Name == name ) {
- categ = ct;
- break;
- }
- }
- return categ;
- }
- /// <summary>
- /// add link function, it has lists to sent to data layer for insert process
- /// </summary>
- /// <param name="source"></param>
- /// <param name="Categ"></param>
- /// <param name="lks"></param>
- /// <returns></returns>
- public bool add_link( string link_name, string link_url, string link_descr, string category_name ) {
- //bool if_exist = false;
- bool added_successfully = false;
- if ( string.IsNullOrEmpty( link_name ) )
- throw new ArgumentNullException( "add_link link_name BL" );
- if ( string.IsNullOrEmpty( category_name ) )
- throw new ArgumentNullException( "add_link category_name BL" );
- if ( string.IsNullOrEmpty( link_url ) )
- throw new ArgumentNullException( "add_link link_url BL" );
- if ( string.IsNullOrEmpty( link_descr ) )
- throw new ArgumentNullException( "add_link link_descr BL" );
- CategoriesCtrlDto categ = GetCategWithName(category_name);
- if(categ != null)
- {
- if ( categ.LinkExists( link_url ) ) {
- throw new ArgumentOutOfRangeException( "add link BL" );
- } else {
- List<LinksCtrlDto> lists = categ.AddLink( link_url, link_name, link_descr );
- _categories.Add( categ );
- added_successfully = store.add_link(category_name,link_url,link_name,link_descr);
- }
- }
- else
- {
- throw new ArgumentNullException( "find category BL" );
- }
- return added_successfully;
- }
- /// <summary>
- /// add a category and create a list of category and send to DL for insert process
- /// </summary>
- /// <param name="source"></param>
- /// <param name="category_name"></param>
- /// <returns></returns>
- public bool add_category( string category_name ) {
- //bool if_exist = false;
- bool added_successfully = false;
- if ( string.IsNullOrEmpty( category_name ) )
- throw new ArgumentNullException( "add_category link_descr BL" );
- CategoriesCtrlDto categ = GetCategWithName( category_name );
- if ( categ != null ) {
- throw new ArgumentOutOfRangeException( "add_category BL" );
- } else {
- _categories.Add( new CategoriesCtrlDto( category_name, null ) );
- added_successfully = store.add_category( category_name );
- }
- return added_successfully;
- }
- /// <summary>
- /// Delete a link and add to a list to be passed to DL for deletion process
- /// after if the deletion process returns true then we can remove that link from the list
- /// </summary>
- /// <param name="source"></param>
- /// <param name="link_url"></param>
- /// <param name="category_name"></param>
- /// <returns></returns>
- public bool delete_link(string link_url, string category_name) {
- bool removed_successfully = false;
- if ( string.IsNullOrEmpty( link_url ) )
- throw new ArgumentNullException( "delete_link link_url BL" );
- if ( string.IsNullOrEmpty( category_name ) )
- throw new ArgumentNullException( "delete_link link_url BL" );
- CategoriesCtrlDto categ = GetCategWithName( category_name );
- if ( categ != null ) {
- if ( categ.LinkExists( link_url ) ) {
- removed_successfully = store.delete_link( category_name, link_url );
- categ.DeleteLink( link_url );
- }
- } else {
- throw new ArgumentNullException( "delete_link BL" );
- }
- return removed_successfully;
- }
- /// <summary>
- /// delete a category (if it exists) and send parameter to DL
- /// for deletion process
- /// </summary>
- /// <param name="source"></param>
- /// <param name="category_name"></param>
- /// <returns></returns>
- public bool delete_category( string category_name ) {
- //bool if_exist = false;
- bool removed_successfully = false;
- if ( string.IsNullOrEmpty( category_name ) )
- throw new ArgumentNullException( "remove_category cat_name BL" );
- CategoriesCtrlDto categ = GetCategWithName( category_name );
- if ( categ == null ) {
- throw new ArgumentOutOfRangeException( "remove_category BL" );
- } else {
- removed_successfully = store.delete_category( category_name );
- _categories.Remove( categ );
- }
- return removed_successfully;
- }
- /// <summary>
- /// set List as readonly collection
- /// </summary>
- public ReadOnlyCollection<CategoriesCtrlDto> Categories {
- get {
- if ( this._categories == null )
- throw new ArgumentNullException( "ReadonlyCategory BL Exception" );
- else
- return _categories.AsReadOnly();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement