public Guid CreateUser(ConModels.User profile)
        {
            // the recovery email is required.
            if (string.IsNullOrWhiteSpace(profile.RecoveryEmail))
            {
                throw new Exception("Recovery Email is required.");
            }

            // unique user name is required. Hint: use RecoveryEmail.
            if (string.IsNullOrWhiteSpace(profile.UserName))
            {
                throw new Exception("UserName is required.");
            }

            // GUID must be, ummm, unique
            if (profile.Id.Equals(Guid.Empty))
            {
                profile.Id = Guid.NewGuid();
            }

            // use providers to create a user
            var password = "******";
            MembershipCreateStatus membershipStatus;
            Membership.CreateUser(profile.UserName, password, profile.RecoveryEmail,
                null, null, true, profile.Id, out membershipStatus);
            if (membershipStatus != MembershipCreateStatus.Success)
            {

                throw new Exception("Membership Creation failed: " + membershipStatus.ToString());
            }

            if (!Membership.ValidateUser(profile.UserName, password))
            {
                Logger.Warn("Cannot validate user " + profile.UserName);
            }

            // save extra properties
            using (var db = new TRIPS_UserEntities())
            {
                // get the aspnet_User that was just created
                var user = db.aspnet_Users.Single(u => u.UserName == profile.UserName);
                SavePropertyValues(db, user, profile);
                db.SaveChanges();
            }

            // give the new user roles
            string[] roles = { "Contact Manager", "Contact", "Viewer", "SponsorRoleManager" };
            Roles.AddUserToRoles(profile.UserName, roles);

            // return ID of new user
            return profile.Id;
        }
Beispiel #2
0
        /// <summary>
        /// Add a user.
        /// </summary>
        /// <param name="profile"></param>
        public void AddUser(ConModels.User profile)
        {
            lock (SyncObject)
            {
                var old = AllUsers.FirstOrDefault(p => p.Id == profile.Id);
                if (old != null)
                {
                    throw new Exception("User is already in cache");
                }

                var addit = new ConModels.User() { Id = profile.Id };
                CopyProperties(addit, profile);
                AllUsers.Add(addit);
            }
        }
 public int CreateContactList(ConModels.ContactList list)
 {
     using (var db = new TRIPS_UserEntities())
     {
         var cl = new ContactList()
         {
             DateCreated = DateTime.UtcNow,
             LastModified = DateTime.UtcNow,
             IsActive = true,
             IsPrivate = list.IsPrivate,
             Name = list.Name
         };
         db.AddToContactLists(cl);
         db.SaveChanges();
         return cl.Id;
     }
 }
Beispiel #4
0
 private void CopyProperties(ConModels.User addit, ConModels.User profile)
 {
     addit.UserName = profile.UserName ?? string.Empty;
     addit.LastName = profile.LastName ?? string.Empty;
     addit.FirstName = profile.FirstName ?? string.Empty;
     addit.Organization = profile.Organization ?? string.Empty;
     addit.Title = profile.Title ?? string.Empty;
     addit.Phone = profile.Phone ?? string.Empty;
     addit.BusinessEmail = profile.BusinessEmail ?? string.Empty;
     addit.RecoveryEmail = profile.RecoveryEmail ?? string.Empty;
 }
Beispiel #5
0
 /// <summary>
 /// Update the user in the cache. The PersonGUID is used as the key.
 /// </summary>
 /// <param name="profile">new profile data</param>
 public void UpdateUser(ConModels.User profile)
 {
     lock (SyncObject)
     {
         var old = AllUsers.FirstOrDefault(p => p.Id == profile.Id);
         if (old != null)
         {
             CopyProperties(old, profile);
         }
     }
 }
 private void SavePropertyValues(TRIPS_UserEntities db, aspnet_Users user, ConModels.User profile)
 {
     SavePropertyValue(db, user, "LastName", profile.LastName);
     SavePropertyValue(db, user, "FirstName", profile.FirstName);
     SavePropertyValue(db, user, "BusinessEmailAddress", profile.BusinessEmail);
     SavePropertyValue(db, user, "HomeEmailAddress", profile.HomeEmail);
     SavePropertyValue(db, user, "AlternateEmailAddress", profile.AlternateEmail);
     SavePropertyValue(db, user, "Comment", profile.Comment);
     SavePropertyValue(db, user, "PrimaryContact", profile.Phone);
     SavePropertyValue(db, user, "Organization", profile.Organization);
     SavePropertyValue(db, user, "Title", profile.Title);
 }
 private void GetPropertyValues(TRIPS_UserEntities db, aspnet_Users user, ConModels.User profile)
 {
     profile.LastName = GetPropertyValue(db, user, "LastName");
     profile.FirstName = GetPropertyValue(db, user, "FirstName");
     profile.BusinessEmail = GetPropertyValue(db, user, "BusinessEmailAddress");
     profile.HomeEmail = GetPropertyValue(db, user, "HomeEmailAddress");
     profile.AlternateEmail = GetPropertyValue(db, user, "AlternateEmailAddress");
     profile.Comment = GetPropertyValue(db, user, "Comment");
     profile.Phone = GetPropertyValue(db, user, "PrimaryContact");
     profile.Organization = GetPropertyValue(db, user, "Organization");
     profile.Title = GetPropertyValue(db, user, "Title");
 }
        public void UpdateUser(ConModels.User profile)
        {
            using (var db = new TRIPS_UserEntities())
            {
                var member = db.aspnet_Membership.Single(m => m.UserId == profile.Id);
                member.Email = profile.RecoveryEmail;
                member.LoweredEmail = profile.RecoveryEmail.ToLower();

                // get the aspnet_User by ID
                var user = db.aspnet_Users.Single(u => u.UserId == profile.Id);

                // nothing in the aspnet_User can be updated

                // save extended properties
                SavePropertyValues(db, user, profile);
                db.SaveChanges();
            }
        }
 // PUT api/user/5
 public void Put(Guid id, ConModels.User value)
 {
     Users.UpdateUser(value);
     UserCache.UpdateUser(value);
 }
 // POST api/user
 public void Post(ConModels.User value)
 {
     Users.CreateUser(value);
     UserCache.AddUser(value);
 }