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
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