コード例 #1
0
 private static void SetPropertyValues(SettingsPropertyValueCollection ppvc, Profile profile)
 {
     foreach (SettingsPropertyValue pv in ppvc)
     {
         switch (pv.Property.Name)
         {
             case "IsAnonymous":
                 profile.IsAnonymous = (bool)pv.PropertyValue;
                 break;
             case "LastActivityDate":
                 profile.LastActivityDate = (DateTime)pv.PropertyValue;
                 break;
             case "LastUpdatedDate":
                 profile.LastUpdatedDate = (DateTime)pv.PropertyValue;
                 break;
             case "Subscription":
                 profile.Subscription = pv.PropertyValue.ToString();
                 break;
             case "Language":
                 profile.Language = pv.PropertyValue.ToString();
                 break;
             case "FirstName":
                 profile.FirstName = pv.PropertyValue.ToString();
                 break;
             case "LastName":
                 profile.LastName = pv.PropertyValue.ToString();
                 break;
             case "Gender":
                 profile.Gender = pv.PropertyValue.ToString();
                 break;
             case "BirthDate":
                 profile.BirthDate = (DateTime)pv.PropertyValue;
                 break;
             case "Occupation":
                 profile.Occupation = pv.PropertyValue.ToString();
                 break;
             case "Website":
                 profile.Website = pv.PropertyValue.ToString();
                 break;
             case "Street":
                 profile.Street = pv.PropertyValue.ToString();
                 break;
             case "City":
                 profile.City = pv.PropertyValue.ToString();
                 break;
             case "State":
                 profile.Province = pv.PropertyValue.ToString();
                 break;
             case "Zip":
                 profile.Zip = pv.PropertyValue.ToString();
                 break;
             case "Country":
                 profile.Country = pv.PropertyValue.ToString();
                 break;
             default:
                 throw new ProviderException("Unsupported property.");
         }
     }
 }
コード例 #2
0
        private Profile GetProfile(string username, bool isAnonymous, IRepository<Profile> profiles)
        {
            var profile = profiles
                .FirstOrDefault(p =>
                          p.User.UserName == username
                          && p.ApplicationName == ApplicationName
                          && p.IsAnonymous == isAnonymous);

            if (profile == null)
            {
                var membershipUser = UnitOfWork.Current.CreateRepository<User>()
                    .FirstOrDefault(p => p.UserName == username
                    && p.ApplicationName == ApplicationName);

                if (membershipUser == null)
                    throw new ProviderException("Profile cannot be created. There is no membership user");

                profile = new Profile();
                profile.IsAnonymous = isAnonymous;
                profile.LastUpdatedDate = System.DateTime.Now;
                profile.LastActivityDate = System.DateTime.Now;
                profile.ApplicationName = this.ApplicationName;
                profile.UserId = membershipUser.Id;

                profiles.Insert(profile);
            }
            return profile;
        }
コード例 #3
0
        private static SettingsPropertyValueCollection GetPropertyValues(SettingsPropertyCollection ppc, Profile profile)
        {
            var svc = new SettingsPropertyValueCollection();
            foreach (SettingsProperty prop in ppc)
            {
                SettingsPropertyValue pv = new SettingsPropertyValue(prop);
                switch (prop.Name)
                {
                    case "IsAnonymous":
                        pv.PropertyValue = profile.IsAnonymous;
                        break;
                    case "LastActivityDate":
                        pv.PropertyValue = profile.LastActivityDate;
                        break;
                    case "LastUpdatedDate":
                        pv.PropertyValue = profile.LastUpdatedDate;
                        break;
                    case "Subscription":
                        pv.PropertyValue = profile.Subscription;
                        break;
                    case "Language":
                        pv.PropertyValue = profile.Language;
                        break;
                    case "FirstName":
                        pv.PropertyValue = profile.FirstName;
                        break;
                    case "LastName":
                        pv.PropertyValue = profile.LastName;
                        break;
                    case "Gender":
                        pv.PropertyValue = profile.Gender;
                        break;
                    case "BirthDate":
                        pv.PropertyValue = profile.BirthDate;
                        break;
                    case "Occupation":
                        pv.PropertyValue = profile.Occupation;
                        break;
                    case "Website":
                        pv.PropertyValue = profile.Website;
                        break;
                    case "Street":
                        pv.PropertyValue = profile.Street;
                        break;
                    case "City":
                        pv.PropertyValue = profile.City;
                        break;
                    case "State":
                        pv.PropertyValue = profile.Province;
                        break;
                    case "Zip":
                        pv.PropertyValue = profile.Zip;
                        break;
                    case "Country":
                        pv.PropertyValue = profile.Country;
                        break;

                    default:
                        throw new ProviderException("Unsupported property.");
                }

                svc.Add(pv);
            }
            return svc;
        }