Example #1
0
        /// <summary>
        /// Saves the user extra information
        /// </summary>
        /// <param name="u"></param>
        /// <returns></returns>
        public static UserInfo Save(UserInfo u)
        {
            using (EntityContext ctx = new EntityContext())
            {
                u.ValidateAndRaise();

                UserInfo existing = ctx.UserInfos.Where(ui => ui.UserId == u.UserId).FirstOrDefault();
                if (existing == null)
                {
                    ctx.UserInfos.AddObject(u);
                }
                else
                {
                    existing.ContactEmail = u.ContactEmail;
                    existing.PhoneCel = u.PhoneCel;
                    existing.PhoneHome = u.PhoneHome;
                    existing.PhoneOffice = u.PhoneOffice;
                    existing.PhoneOfficeExtension = u.PhoneOfficeExtension;
                    existing.FirstName = u.FirstName;
                    existing.LastName = u.LastName;
                    existing.Gender = u.Gender;
                    existing.NotificationsAvailability = u.NotificationsAvailability;
                    existing.Locale = u.Locale;
                }
                ctx.SaveChanges();

                // Notify connected endpoints.
                PubnubFactory.GetInstance().Publish(PubnubFactory.Channels.Users, u);

                return u;
            }
        }
Example #2
0
 partial void DeleteUserInfo(UserInfo instance);
Example #3
0
 partial void UpdateUserInfo(UserInfo instance);
Example #4
0
 partial void InsertUserInfo(UserInfo instance);
Example #5
0
        /// <summary>
        /// Creates a user from AD
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private static User CreateUserFromAD(string username, string password)
        {
            username = username.Split('@').First();

            using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "SIEENA", "daniel.ramirez", "xrZ40uye"))
            {
                UserPrincipal up = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username);

                using (EntityContext ctx = new EntityContext())
                {
                    User u = new User()
                    {
                        Email = up.EmailAddress,
                        CreatedAt = DateTime.Now.ToCommonTime(),
                        IsActive = true,
                        Password = password
                    };

                    ctx.Users.AddObject(u);
                    ctx.SaveChanges();

                    UserInfo ui = new UserInfo()
                    {
                        UserId = u.UserId,
                        FirstName = up.Name,
                        LastName = up.Surname
                    };

                    ctx.UserInfos.AddObject(ui);
                    ctx.SaveChanges();

                    User.AddRoles(u, new List<Role>() { Role.GetAll().OrderByDescending(r => r.RoleLevel).First() });

                    return u;
                }
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the UserInfos EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUserInfos(UserInfo userInfo)
 {
     base.AddObject("UserInfos", userInfo);
 }
 /// <summary>
 /// Create a new UserInfo object.
 /// </summary>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 public static UserInfo CreateUserInfo(global::System.Int32 userId, global::System.String firstName)
 {
     UserInfo userInfo = new UserInfo();
     userInfo.UserId = userId;
     userInfo.FirstName = firstName;
     return userInfo;
 }