I've been trying to add a custom ProfileProvider class to my MVC 3 app with entity framework.I noticed its calling GetPropertyValues everytime I try and do something like:
profile.FirstName = viewModel.FirstName;
For some reason I can't see to update the values in the database here is what I have setup so far.I've been following roughly this tutorial: http://www.davidhayden.com/blog/dave/archive/2007/10/30/CreateCustomProfileProviderASPNET2UsingLINQToSQL.aspx
<profile enabled="true" defaultProvider="EfProfileProvider" inherits="Data.BOHProfile" automaticSaveEnabled="true">
<providers>
<clear />
<add name="EfProfileProvider" type="Data.Providers.EfProfileProvider" connectionStringName="BOHEntities" applicationName="BOH" />
</providers>
</profile>
Profile class:
public class BOHProfile : ProfileBase, IBOHProfile
{
public virtual string FirstName
{
get { return base["FirstName"] as string; }
set { base["FirstName"] = value; }
}
public virtual string LastName
{
get { return base["LastName"] as string; }
set { base["LastName"] = value; }
}
public virtual string City
{
get { return base["City"] as string; }
set { base["City"] = value; }
}
public static BOHProfile CurrentUser()
{
return (BOHProfile)(ProfileBase.Create(Membership.GetUser().UserName));
}
public static BOHProfile CurrentUser(string userName)
{
return (BOHProfile)(ProfileBase.Create(userName));
}
}
Heres the code in the actual provider:
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
{
var uow = new EfUnitOfWork();
var profileRepo = new ProfileRepository(new EfRepository<Profile>(), uow);
var data = profileRepo.FetchProfileData(context["UserName"].ToString(), ApplicationName);
return data != null ? ProviderUtility.ConvertToSettingsPropertyValueCollection(data) : null;
}
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
{
var data = ProviderUtility.ConvertFromSettingsPropertyValueCollection(collection);
var uow = new EfUnitOfWork();
var profileRepo = new ProfileRepository(new EfRepository<Profile>(), uow);
profileRepo.SaveProfileData(context["UserName"].ToString(), ApplicationName, data);
profileRepo.Save();
}
Maybe I'm not getting what the point of the profile provider is but it seems like I could just make a class that gets and sets the data in my profile table, or is there something I'm not seeing that I can perhaps use in the controllers when I have this profile information setup?