Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   extending MembershipUser, need help! (http://www.velocityreviews.com/forums/t494712-extending-membershipuser-need-help.html)

Jeff 03-28-2007 09:34 PM

extending MembershipUser, need help!
 
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<ContactD etail> 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 03-28-2007 10:01 PM

Re: extending MembershipUser, need help!
 
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<ContactD etail> 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 03-28-2007 11:03 PM

Re: extending MembershipUser, need help!
 
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" <nospam@nospam.com> wrote in message
news:eCX%23mTYcHHA.4368@TK2MSFTNGP02.phx.gbl...
> 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<ContactD etail> 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 03-29-2007 12:46 AM

Re: extending MembershipUser, need help!
 
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" <it_consultant1@hotmail.com.NOSPAM> wrote in message
news:%23vmCe1YcHHA.5052@TK2MSFTNGP06.phx.gbl...
> 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" <nospam@nospam.com> wrote in message
> news:eCX%23mTYcHHA.4368@TK2MSFTNGP02.phx.gbl...
>> 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<ContactD etail> 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

>
>





All times are GMT. The time now is 03:09 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.