Exemplo n.º 1
0
        public User GetUser(string userName, bool throwOnError = true)
        {
            Guard.ArgumentNotNullOrEmpty(userName, "userName");

            return(exManager.Process(() =>
            {
                var membershipUser = Membership.GetUser(userName);
                if (membershipUser == null)
                {
                    if (throwOnError)
                    {
                        throw new InvalidOperationException(Properties.Resources.MembershipUserNotFound);
                    }
                    return null;
                }

                var attributes = profileStore.GetAttributesFor(userName, new[] { "costCenter", "manager", "displayName" });

                var user = this.container.Resolve <User>();
                user.Roles = Roles.GetRolesForUser(userName);
                user.CostCenter = attributes["costCenter"];
                user.FullName = attributes["displayName"];
                user.Manager = attributes["manager"];
                // TracingBehavior should trigger here
                user.UserName = membershipUser.UserName;

                var profile = ProfileBase.Create(userName);
                user.PreferredReimbursementMethod = string.IsNullOrEmpty(profile.GetProperty <string>("PreferredReimbursementMethod")) ?
                                                    ReimbursementMethod.NotSet :
                                                    (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), profile.GetProperty <string>("PreferredReimbursementMethod"));
                return user;
            },
                                     Constants.NotifyPolicy));
        }