Adding the Full Name property is pretty easy. First, of course, you have to add a FullName property to the Data Transfer Object (DTO):
public class User { [Key] public Guid UserId { get; set; } public string UserName { get; set; } public string FullName { get; set; } }
Next, we have to populate the FullName value from the profile properties. This part involves working with the ASP.Net Profile interface, which is more obscure that the main Membership interface:
var userList = Membership.GetAllUsers(); foreach (MembershipUser user in userList) { var returnUser = new User { UserId = (Guid)user.ProviderUserKey, UserName = user.UserName }; //create a profile object to query var profile = ProfileBase.Create(user.UserName); //look up the LightSwitch FullName property in the profile returnUser.FullName = profile.GetPropertyValue("FullName").ToString(); returnValue.Add(returnUser); }
In order to understand how this code fits in with the overall service, please refer to my earlier post.
Adding the FullName property will allow you to display the full user name that you entered using the LightSwitch user manager, so you won't have to remember user names to identify users of your application.