简体   繁体   中英

Connect other models with user in Silverlight Business Application

I'm having a real trouble with what I need to do. Here's the thing:

I'm creating Silverlight Business Application. I want users to be able to define their own "reminders" and "templates". It seems very simple, just 3 models, 2 one-to-many relations and that's all. But I have no idea how I can connect the existing User model to other models.

I tried to create my own "membership" provider - I've created db with all 3 models and it seemed to be ok, I created EntityModel, but now I have 2 different places where User class is defined, and in the first one it inherits UserBase class and in another EntityObject (in the file Model.Designer.cs, which is generated automatically.

I'm totally confused - can I stick with the EntityObject solution, delete other definitions of classes? If so, how can I still be able to use all the features that come with silverlight business application? (Authentication/Registering etc. is already provided).

We have implemented this scenario in our LOB app.

Firstly add the appropriate properties to the user class like so.

public partial class User : UserBase
{
    public Guid UserId { get; set; }
    public int PeopleId { get; set; }
    public int EpothecaryUserId { get; set; }
    public string PersonFullName { get; set; }
    public SearchGroups SearchGroups { get; set; }
    public string SearchHistoryString { get; set; }
    public int SearchRowsReturnedPerGroup { get; set; }
}

Then create a class derived from AuthenticationBase

public class AuthenticationService : AuthenticationBase<User>
{

    protected override User GetAuthenticatedUser(IPrincipal principal)
    {
        return base.GetAuthenticatedUser(principal).WithProfile();
    }

    [Invoke]
    public void SaveMyUser(User user)
    {
        if (user.UserId == Guid.Empty)
        {
            ClientLogger.Error("SaveMyUser failed because the UserId is invalid");
            return;                
        }

        using (var db = new Pharma360Model())
        {
            var userProfile = db.UserProfiles.Single(p => p.EpothecaryUserId == user.EpothecaryUserId);
            userProfile.SearchGroups = (int)user.SearchGroups;
            userProfile.SearchHistory = user.SearchHistoryString;
            userProfile.SearchRowsReturnedPerGroup = user.SearchRowsReturnedPerGroup;
            db.SaveChanges();
        }
    }

}

And this will take care of the loading and saving of the custom User class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM