public UserInformation()
        {
            try
            {
                var basicAuthenticationIdentity = Thread.CurrentPrincipal.Identity as BasicAuthenticationIdentity;

                if (basicAuthenticationIdentity == null)
                    _userInfo= null;

                var claimsInformation = basicAuthenticationIdentity.Claims;
                var information = claimsInformation as Claim[] ?? claimsInformation.ToArray();
                _userInfo= new UserModel
                {
                    UserId = Convert.ToInt32(information.FirstOrDefault(m => m.Type == "UserId").Value),
                    Email = information.FirstOrDefault(m => m.Type == "Email").Value,
                    UserName = information.FirstOrDefault(m => m.Type == "UserName").Value,
                    Role = (UserRole)Convert.ToInt32(information.FirstOrDefault(m => m.Type == "RoleId").Value),

                };
            }
            catch (Exception ex)
            {
                _userInfo= null;
            }
        }
Пример #2
0
 /// <summary>
 /// Used to modify user Information also the role
 /// </summary>
 /// <returns></returns>
 public bool ModifyUserInformationAdmin(UserModel userInformation)
 {
     if (!string.IsNullOrEmpty(userInformation.Password))
     {
         userInformation.Password = new EncryptionHelper().Encrypt(userInformation.Password);
     }
     userInformation.Email = userInformation.Email.ToLower();
     return new Data.UserMethods().ModifyUserInformationAdmin(userInformation);
 }
 public UserInformation(UserModel userInfo)
 {
     _testUserData = userInfo;
 }
        public bool ModifyUserInformationAdmin(UserModel userInfo)
        {
            try
            {
                var loggedUserInfo = new UserInformation().GetCurrentUserInformation();
                var userInformation = new UserMethods().GetUserInformationBasedOnId(userInfo.UserId);
                //Checking Role Privilege
                if ((new Business.UserMethods().IsEmailExist(userInfo.Email) && userInformation.Email != userInfo.Email))
                    throw new HttpResponseException(HttpStatusCode.BadRequest);

                return new Business.UserMethods().ModifyUserInformationAdmin(userInfo);
            }
            catch (HttpResponseException ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(string.Format("Email ID already exist")),
                    ReasonPhrase = "Bad Request"
                });
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
                {
                    Content = new StringContent(string.Format("Service is currently unavailable.")),
                    ReasonPhrase = "Service Unavailable "
                });
            }
        }
Пример #5
0
        /// <summary>
        /// Used to modify user Information
        /// </summary>
        /// <returns></returns>
        public bool ModifyUserInformationAdmin(UserModel userInformation)
        {
            try
            {

                using (var tde = new TimeDifferenceEntities())
                {

                    var userInfo = tde.Users.FirstOrDefault(m => m.IsActive && m.Id == userInformation.UserId);
                    if (userInfo == null)
                        return false;
                    userInfo.Email = userInformation.Email;
                    userInfo.UserName = userInformation.UserName;
                    userInfo.RoleId = Convert.ToInt32(userInformation.Role);
                    if (!string.IsNullOrEmpty(userInformation.Password))
                    {
                        userInfo.Password = userInformation.Password;
                    }
                    tde.SaveChanges();
                    return true;

                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception Occured", ex.InnerException);
            }
        }
        public bool ModifyUserInformation(UserModel userInfo)
        {
            try
            {
                var userInfoSession = new UserInformation().GetCurrentUserInformation();
                if (IsEmailExist(userInfo.Email) && userInfoSession.Email != userInfo.Email)
                    throw new HttpResponseException(HttpStatusCode.BadRequest);

                userInfo.UserId = userInfoSession.UserId;
                return new Business.UserMethods().ModifyUserInformation(userInfo);
            }
            catch (HttpResponseException ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(string.Format("Email ID already exist.")),
                    ReasonPhrase = "Bad Request"
                });
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
                {
                    Content = new StringContent(string.Format("Service is currently unavailable.")),
                    ReasonPhrase = "Service Unavailable "
                });
            }
        }