extending MembershipUser, need help!

J

Jeff

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
 
B

bruce barker

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


-- bruce (sqlwork.com)
 
J

Jeff

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
 
9

9-11 Was An Inside Job

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/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top