Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > extending MembershipUser, need help!

Reply
Thread Tools

extending MembershipUser, need help!

 
 
Jeff
Guest
Posts: n/a
 
      03-28-2007
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


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      03-28-2007
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
>
>

 
Reply With Quote
 
 
 
 
Jeff
Guest
Posts: n/a
 
      03-28-2007
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" <(E-Mail Removed)> wrote in message
news:eCX%(E-Mail Removed)...
> 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



 
Reply With Quote
 
9-11 Was An Inside Job
Guest
Posts: n/a
 
      03-29-2007
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:eCX%(E-Mail Removed)...
>> 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

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help extending AjaxFileUpload Plugin with JQuery Big Moxy Javascript 1 12-22-2007 12:42 AM
Need help extending stl list. JustSomeGuy C++ 6 06-01-2004 05:29 PM
Need help extending stl list. Brian O'Brien C++ 0 05-28-2004 05:35 PM
need help for extending and embedding Ing Giuseppe Monteleone Python 1 02-29-2004 03:48 PM
'Decorator' pattern implemented by extending objects with mixins- need guidance. Asfand Yar Qazi Ruby 0 12-01-2003 02:01 PM



Advertisments