Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LinksCtrlDto
- {
- /// <summary>
- /// url link
- /// </summary>
- private string _url;
- /// <summary>
- /// name of link
- /// </summary>
- private string _name;
- /// <summary>
- /// description of string
- /// </summary>
- private string _description;
- /// <summary>
- /// constructor for LinksCtrlDto
- /// </summary>
- /// <param name="url"></param>
- /// <param name="name"></param>
- /// <param name="description"></param>
- public LinksCtrlDto( string url, string name, string description ) {
- //only if url si not null/empty, name is not null/empty, and description is not null/empty
- if ( string.IsNullOrEmpty( url ) )
- throw new ArgumentNullException( "url" );
- else
- this._url = url;
- if ( string.IsNullOrEmpty( name ) )
- throw new ArgumentNullException( "name" );
- else
- this._name = name;
- if ( string.IsNullOrEmpty( description ) )
- throw new ArgumentNullException( "description" );
- else
- this._description = description;
- }
- /// <summary>
- /// Url property as getter
- /// </summary>
- public string Url {
- get {
- if ( string.IsNullOrEmpty( Url ) )
- throw new ArgumentNullException( "Url" );
- else
- return this._url;
- }
- }
- /// <summary>
- /// Name property as getter
- /// </summary>
- public string Name {
- get {
- if ( string.IsNullOrEmpty( Name ) )
- throw new ArgumentNullException( "Name" );
- else
- return this._name;
- }
- }
- /// <summary>
- /// Description property as getter
- /// </summary>
- public string Description {
- get {
- if ( string.IsNullOrEmpty( Description ) )
- throw new ArgumentNullException( "Description" );
- else
- return this._description;
- }
- }
- }
- public class CategoriesCtrlDto
- {
- /// <summary>
- /// Name of category
- /// </summary>
- private string _name;
- /// <summary>
- /// List of links
- /// </summary>
- private List<LinksCtrlDto> _ListLink;
- /// <summary>
- /// constructor
- /// </summary>
- /// <param name="name"></param>
- /// <param name="Link"></param>
- public CategoriesCtrlDto( string name, List<LinksCtrlDto> Link) {
- if ( string.IsNullOrEmpty( name ) )
- throw new ArgumentNullException( "name" );
- else
- this._name = name;
- if ( _ListLink == null )
- throw new ArgumentNullException( "_ListLink" );
- else
- this._ListLink = Link;
- }
- /// <summary>
- /// add link in List
- /// </summary>
- /// <param name="url"></param>
- /// <param name="name"></param>
- /// <param name="description"></param>
- public List<LinksCtrlDto> AddLink( string url, string name ,string description ) {
- if ( string.IsNullOrEmpty( url ) )
- throw new ArgumentNullException( "AddLink TL Categories - url" );
- if ( string.IsNullOrEmpty( name ) )
- throw new ArgumentNullException( "Addlink TL Categories - name" );
- if ( string.IsNullOrEmpty( description ) )
- throw new ArgumentNullException( "Addlink TL Categories - description" );
- _ListLink.Add( new LinksCtrlDto( url, name, description ) );
- return _ListLink;
- }
- /// <summary>
- /// delete a link from list if URL name is matched
- /// </summary>
- /// <param name="url"></param>
- /// <param name="name"></param>
- /// <param name="description"></param>
- public void DeleteLink( string url ) {
- if ( string.IsNullOrEmpty( url ) )
- throw new ArgumentNullException( "deletelink TL url" );
- foreach ( LinksCtrlDto lk in _ListLink ) {
- if ( lk.Url == url ) {
- _ListLink.Remove( lk );
- break;
- }
- }
- }
- /// <summary>
- /// Verify that link already exists in specified category
- /// </summary>
- /// <param name="url"></param>
- /// <returns></returns>
- public bool LinkExists(string url){
- bool result = false;
- if ( string.IsNullOrEmpty( url ) )
- throw new ArgumentNullException( "LinkExists name TL Categories" );
- foreach ( LinksCtrlDto lk in Links ) {
- if ( lk.Url == url ) {
- result = true;
- break;
- }
- }
- return result;
- }
- /// <summary>
- /// Name property as getter
- /// </summary>
- public string Name {
- get {
- return this._name;
- }
- }
- /// <summary>
- /// List property as getter
- /// </summary>
- public ReadOnlyCollection<LinksCtrlDto> Links {
- get {
- return this._ListLink.AsReadOnly();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement