extending MembershipUser, need help!

Discussion in 'ASP .Net' started by Jeff, Mar 28, 2007.

  1. Jeff

    Jeff Guest

    Hey

    ASP.NET 2.0

    I'm trying to extend the MembershipUser class, and have encounter a problem:

    << See in the middle of this post for info about why I do this >>
    << See below of this post for the source code of Contact class >>

    public class Contact : MembershipUser
    {
    public Contact(string username)
    {
    this.UserName = username;
    }
    }

    UserName is readonly so "this.UserName = username;" gives an error.

    Anybody have a suggestion on how to this???

    *********************************************
    Why am I extending MembershipUser class:

    I do this because I'm developing a networking website and this code should
    return a members friends. This MembershipUserCollection should display the
    friends in a GridView

    public static MembershipUserCollection GetContacts(string user)
    {
    MembershipUserCollection contacts = null;
    List<ContactDetail> recordset =
    SiteProvider.Networking.GetContacts(user);
    contacts = GetContactListFromContactDetailsList(recordset);

    return contacts;
    }


    It's 3 reasons why I do it:
    - It is part of N-tier design, this is in the BLL layer. the DAL layer has
    sent a collection of objects (each object holding info about a username). An
    the task for GetContacts is to convert that list of objects into a
    MembershipUserCollection
    - The result of GetContacts will be used in a GridView, which already are
    showing data based on MembershipUserCollection
    - It's the best solution I know of... but please, please if you think my
    approach sucks then please give me some tips about how you think this should
    be done. I love to learn you things and believe many developers have better
    approach on this

    Any suggestions??

    ***************************************************
    Entire source code of Contact:
    using System;
    using System.Data;
    using System.Web.Security;
    using System.Collections.Generic;
    using AH.MyNetwork.DAL;


    /// <summary>
    /// Summary description for Contact
    /// </summary>
    public class Contact : MembershipUser
    {

    public Contact(string username)
    {
    this.UserName = username;
    }

    public static MembershipUserCollection GetContacts(string user)
    {
    MembershipUserCollection contacts = null;
    List<ContactDetail> recordset =
    SiteProvider.Networking.GetContacts(user);
    contacts = GetContactListFromContactDetailsList(recordset);

    return contacts;
    }

    private static MembershipUserCollection
    GetContactListFromContactDetailsList(List<ContactDetail> recordset)
    {
    MembershipUserCollection contacts = null;
    foreach (ContactDetail record in recordset)
    contacts.Add(GetContactFromContactDetails(record));
    return contacts;
    }

    private static Contact GetContactFromContactDetails(ContactDetail
    record)
    {
    if (record == null)
    return null;
    else
    {
    return new Contact(record.USERNAME);
    }
    }

    }


    Jeff
    Jeff, Mar 28, 2007
    #1
    1. Advertising

  2. Jeff

    bruce barker Guest

    MembershipUser's constructor allows passing the username (along with
    several other values). just call it from your constructor.


    -- bruce (sqlwork.com)


    Jeff wrote:
    > Hey
    >
    > ASP.NET 2.0
    >
    > I'm trying to extend the MembershipUser class, and have encounter a problem:
    >
    > << See in the middle of this post for info about why I do this >>
    > << See below of this post for the source code of Contact class >>
    >
    > public class Contact : MembershipUser
    > {
    > public Contact(string username)
    > {
    > this.UserName = username;
    > }
    > }
    >
    > UserName is readonly so "this.UserName = username;" gives an error.
    >
    > Anybody have a suggestion on how to this???
    >
    > *********************************************
    > Why am I extending MembershipUser class:
    >
    > I do this because I'm developing a networking website and this code should
    > return a members friends. This MembershipUserCollection should display the
    > friends in a GridView
    >
    > public static MembershipUserCollection GetContacts(string user)
    > {
    > MembershipUserCollection contacts = null;
    > List<ContactDetail> recordset =
    > SiteProvider.Networking.GetContacts(user);
    > contacts = GetContactListFromContactDetailsList(recordset);
    >
    > return contacts;
    > }
    >
    >
    > It's 3 reasons why I do it:
    > - It is part of N-tier design, this is in the BLL layer. the DAL layer has
    > sent a collection of objects (each object holding info about a username). An
    > the task for GetContacts is to convert that list of objects into a
    > MembershipUserCollection
    > - The result of GetContacts will be used in a GridView, which already are
    > showing data based on MembershipUserCollection
    > - It's the best solution I know of... but please, please if you think my
    > approach sucks then please give me some tips about how you think this should
    > be done. I love to learn you things and believe many developers have better
    > approach on this
    >
    > Any suggestions??
    >
    > ***************************************************
    > Entire source code of Contact:
    > using System;
    > using System.Data;
    > using System.Web.Security;
    > using System.Collections.Generic;
    > using AH.MyNetwork.DAL;
    >
    >
    > /// <summary>
    > /// Summary description for Contact
    > /// </summary>
    > public class Contact : MembershipUser
    > {
    >
    > public Contact(string username)
    > {
    > this.UserName = username;
    > }
    >
    > public static MembershipUserCollection GetContacts(string user)
    > {
    > MembershipUserCollection contacts = null;
    > List<ContactDetail> recordset =
    > SiteProvider.Networking.GetContacts(user);
    > contacts = GetContactListFromContactDetailsList(recordset);
    >
    > return contacts;
    > }
    >
    > private static MembershipUserCollection
    > GetContactListFromContactDetailsList(List<ContactDetail> recordset)
    > {
    > MembershipUserCollection contacts = null;
    > foreach (ContactDetail record in recordset)
    > contacts.Add(GetContactFromContactDetails(record));
    > return contacts;
    > }
    >
    > private static Contact GetContactFromContactDetails(ContactDetail
    > record)
    > {
    > if (record == null)
    > return null;
    > else
    > {
    > return new Contact(record.USERNAME);
    > }
    > }
    >
    > }
    >
    >
    > Jeff
    >
    >
    bruce barker, Mar 28, 2007
    #2
    1. Advertising

  3. Jeff

    Jeff Guest

    yeah, I know. But I have only the username and then I would need to set the
    other values to NULL... I could try to do that... maybe somebody here has a
    better approach:

    In DAL a method returns a collection of objects (each object holding a
    user's name - username). The task of BLL is to convert this collection of
    objects into a MembershipUserCollection.... But hey what if the DAL instead
    returned a MembershipUserCollection... I'll try that instead....

    Any suggestion/opinions about this??

    Jeff



    "bruce barker" <> wrote in message
    news:eCX%...
    > MembershipUser's constructor allows passing the username (along with
    > several other values). just call it from your constructor.
    >
    >
    > -- bruce (sqlwork.com)
    >
    >
    > Jeff wrote:
    >> Hey
    >>
    >> ASP.NET 2.0
    >>
    >> I'm trying to extend the MembershipUser class, and have encounter a
    >> problem:
    >>
    >> << See in the middle of this post for info about why I do this >>
    >> << See below of this post for the source code of Contact class >>
    >>
    >> public class Contact : MembershipUser
    >> {
    >> public Contact(string username)
    >> {
    >> this.UserName = username;
    >> }
    >> }
    >>
    >> UserName is readonly so "this.UserName = username;" gives an error.
    >>
    >> Anybody have a suggestion on how to this???
    >>
    >> *********************************************
    >> Why am I extending MembershipUser class:
    >>
    >> I do this because I'm developing a networking website and this code
    >> should return a members friends. This MembershipUserCollection should
    >> display the friends in a GridView
    >>
    >> public static MembershipUserCollection GetContacts(string user)
    >> {
    >> MembershipUserCollection contacts = null;
    >> List<ContactDetail> recordset =
    >> SiteProvider.Networking.GetContacts(user);
    >> contacts = GetContactListFromContactDetailsList(recordset);
    >>
    >> return contacts;
    >> }
    >>
    >>
    >> It's 3 reasons why I do it:
    >> - It is part of N-tier design, this is in the BLL layer. the DAL layer
    >> has sent a collection of objects (each object holding info about a
    >> username). An the task for GetContacts is to convert that list of objects
    >> into a MembershipUserCollection
    >> - The result of GetContacts will be used in a GridView, which already are
    >> showing data based on MembershipUserCollection
    >> - It's the best solution I know of... but please, please if you think my
    >> approach sucks then please give me some tips about how you think this
    >> should be done. I love to learn you things and believe many developers
    >> have better approach on this
    >>
    >> Any suggestions??
    >>
    >> ***************************************************
    >> Entire source code of Contact:
    >> using System;
    >> using System.Data;
    >> using System.Web.Security;
    >> using System.Collections.Generic;
    >> using AH.MyNetwork.DAL;
    >>
    >>
    >> /// <summary>
    >> /// Summary description for Contact
    >> /// </summary>
    >> public class Contact : MembershipUser
    >> {
    >>
    >> public Contact(string username)
    >> {
    >> this.UserName = username;
    >> }
    >>
    >> public static MembershipUserCollection GetContacts(string user)
    >> {
    >> MembershipUserCollection contacts = null;
    >> List<ContactDetail> recordset =
    >> SiteProvider.Networking.GetContacts(user);
    >> contacts = GetContactListFromContactDetailsList(recordset);
    >>
    >> return contacts;
    >> }
    >>
    >> private static MembershipUserCollection
    >> GetContactListFromContactDetailsList(List<ContactDetail> recordset)
    >> {
    >> MembershipUserCollection contacts = null;
    >> foreach (ContactDetail record in recordset)
    >> contacts.Add(GetContactFromContactDetails(record));
    >> return contacts;
    >> }
    >>
    >> private static Contact GetContactFromContactDetails(ContactDetail
    >> record)
    >> {
    >> if (record == null)
    >> return null;
    >> else
    >> {
    >> return new Contact(record.USERNAME);
    >> }
    >> }
    >>
    >> }
    >>
    >>
    >> Jeff
    Jeff, Mar 29, 2007
    #3
  4. This is interesting. I've had it on my mind myself.

    I'm reading the way you put it and what does it say to me?
    It says "I do this because I'm developing a networking website and this code
    should return a members friends" which says to relational model that uses a
    "foreign key" used to relate to table(s) of his or her friends. So why not
    store a key in the Profile object?

    <%= Clinton Gallagher
    NET csgallagher AT metromilwaukee.com
    URL http://clintongallagher.metromilwaukee.com/




    "Jeff" <> wrote in message
    news:%...
    > yeah, I know. But I have only the username and then I would need to set
    > the other values to NULL... I could try to do that... maybe somebody here
    > has a better approach:
    >
    > In DAL a method returns a collection of objects (each object holding a
    > user's name - username). The task of BLL is to convert this collection of
    > objects into a MembershipUserCollection.... But hey what if the DAL
    > instead returned a MembershipUserCollection... I'll try that instead....
    >
    > Any suggestion/opinions about this??
    >
    > Jeff
    >
    >
    >
    > "bruce barker" <> wrote in message
    > news:eCX%...
    >> MembershipUser's constructor allows passing the username (along with
    >> several other values). just call it from your constructor.
    >>
    >>
    >> -- bruce (sqlwork.com)
    >>
    >>
    >> Jeff wrote:
    >>> Hey
    >>>
    >>> ASP.NET 2.0
    >>>
    >>> I'm trying to extend the MembershipUser class, and have encounter a
    >>> problem:
    >>>
    >>> << See in the middle of this post for info about why I do this >>
    >>> << See below of this post for the source code of Contact class >>
    >>>
    >>> public class Contact : MembershipUser
    >>> {
    >>> public Contact(string username)
    >>> {
    >>> this.UserName = username;
    >>> }
    >>> }
    >>>
    >>> UserName is readonly so "this.UserName = username;" gives an error.
    >>>
    >>> Anybody have a suggestion on how to this???
    >>>
    >>> *********************************************
    >>> Why am I extending MembershipUser class:
    >>>
    >>> I do this because I'm developing a networking website and this code
    >>> should return a members friends. This MembershipUserCollection should
    >>> display the friends in a GridView
    >>>
    >>> public static MembershipUserCollection GetContacts(string user)
    >>> {
    >>> MembershipUserCollection contacts = null;
    >>> List<ContactDetail> recordset =
    >>> SiteProvider.Networking.GetContacts(user);
    >>> contacts = GetContactListFromContactDetailsList(recordset);
    >>>
    >>> return contacts;
    >>> }
    >>>
    >>>
    >>> It's 3 reasons why I do it:
    >>> - It is part of N-tier design, this is in the BLL layer. the DAL layer
    >>> has sent a collection of objects (each object holding info about a
    >>> username). An the task for GetContacts is to convert that list of
    >>> objects into a MembershipUserCollection
    >>> - The result of GetContacts will be used in a GridView, which already
    >>> are showing data based on MembershipUserCollection
    >>> - It's the best solution I know of... but please, please if you think my
    >>> approach sucks then please give me some tips about how you think this
    >>> should be done. I love to learn you things and believe many developers
    >>> have better approach on this
    >>>
    >>> Any suggestions??
    >>>
    >>> ***************************************************
    >>> Entire source code of Contact:
    >>> using System;
    >>> using System.Data;
    >>> using System.Web.Security;
    >>> using System.Collections.Generic;
    >>> using AH.MyNetwork.DAL;
    >>>
    >>>
    >>> /// <summary>
    >>> /// Summary description for Contact
    >>> /// </summary>
    >>> public class Contact : MembershipUser
    >>> {
    >>>
    >>> public Contact(string username)
    >>> {
    >>> this.UserName = username;
    >>> }
    >>>
    >>> public static MembershipUserCollection GetContacts(string user)
    >>> {
    >>> MembershipUserCollection contacts = null;
    >>> List<ContactDetail> recordset =
    >>> SiteProvider.Networking.GetContacts(user);
    >>> contacts = GetContactListFromContactDetailsList(recordset);
    >>>
    >>> return contacts;
    >>> }
    >>>
    >>> private static MembershipUserCollection
    >>> GetContactListFromContactDetailsList(List<ContactDetail> recordset)
    >>> {
    >>> MembershipUserCollection contacts = null;
    >>> foreach (ContactDetail record in recordset)
    >>> contacts.Add(GetContactFromContactDetails(record));
    >>> return contacts;
    >>> }
    >>>
    >>> private static Contact GetContactFromContactDetails(ContactDetail
    >>> record)
    >>> {
    >>> if (record == null)
    >>> return null;
    >>> else
    >>> {
    >>> return new Contact(record.USERNAME);
    >>> }
    >>> }
    >>>
    >>> }
    >>>
    >>>
    >>> Jeff

    >
    >
    9-11 Was An Inside Job, Mar 29, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. brett_fyisystems

    MembershipUser implementation

    brett_fyisystems, Nov 2, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    676
    brett_fyisystems
    Nov 2, 2005
  2. Mark Olbert

    Extending MembershipUser

    Mark Olbert, Jan 10, 2006, in forum: ASP .Net
    Replies:
    8
    Views:
    5,502
    Steven Cheng[MSFT]
    Jan 12, 2006
  3. mark d.
    Replies:
    0
    Views:
    865
    mark d.
    Feb 6, 2006
  4. pbd22
    Replies:
    0
    Views:
    415
    pbd22
    Feb 13, 2010
  5. CSharpner
    Replies:
    1
    Views:
    834
Loading...

Share This Page