public void GetUserProfile()
        {
            User user;

            using (SMPSEntities objectContext = new SMPSEntities())
            {
                IQueryable <User> users = objectContext.Users;
                user = users.FirstOrDefault();
            }

            IUserAccount obj         = this.container.Resolve <IUserAccount>();
            UserProfile  profileuser = obj.GetUserProfile(user.UserLoginId);

            Assert.AreEqual(true, profileuser != null);
        }
        public void CheckValidUser()
        {
            User user;

            using (SMPSEntities objectContext = new SMPSEntities())
            {
                IQueryable <User> users = objectContext.Users;
                user = users.FirstOrDefault();
            }

            IUserAccount obj         = this.container.Resolve <IUserAccount>();
            UserProfile  userProfile = obj.ValidateUser(user.UserLoginId, user.UserLoginPassword);

            Assert.AreEqual(true, userProfile != null);
        }
예제 #3
0
        /// <summary>
        /// Validates the user and returns profile
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="password">The password.</param>
        /// <returns>The user profile.</returns>
        public UserProfile ValidateUser(string userId, string password)
        {
            //The User Profile Object.
            UserProfile userProfile = null;

            try
            {
                using (SMPSEntities objectContext = new SMPSEntities())
                {
                    //Using IQueryable for better performance.
                    IQueryable <User> users = objectContext.Users;
                    //Getting the user model.
                    var user = users.Where(u => u.UserLoginId == userId && u.UserLoginPassword == password).FirstOrDefault();
                    //Checks if user is not null.
                    if (user != null)
                    {
                        // Getting the user prfile from user model.
                        //Maps the properties from user model to user profile
                        //And return the same.
                        userProfile = MapProperties(user);
                    }
                    else
                    {
                        //throw the exception
                        //With an error message.
                        throw new NoDataFoundException(ErrorMessages.ApplicationErrorMessage);
                    }
                }

                //return user profile
                return(userProfile);
            }
            catch (Exception)
            {
                //throw the exception
                //This is a generic exception
                throw;
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the user profile
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns>The user profile.</returns>
        public UserProfile GetUserProfile(string userId)
        {
            try
            {
                //The User Profile Object.
                UserProfile userProfile;
                using (SMPSEntities objectContext = new SMPSEntities())
                {
                    //Using IQueryable for better performance.
                    IQueryable <User> users = objectContext.Users;
                    //Getting the user model.
                    var user = users.Where(u => u.UserLoginId == userId).FirstOrDefault();
                    if (user != null)
                    {
                        //Getting the user prfile from user model.
                        userProfile = MapProperties(user);
                    }
                    else
                    {
                        //Exception if user not found
                        throw new NoDataFoundException(ErrorMessages.ApplicationErrorMessage);
                    }
                }

                //return user profile
                return(userProfile);
            }
            catch (NoDataFoundException)
            {
                //throw the exception
                throw;
            }
            catch (Exception)
            {
                //throw the exception
                throw;
            }
        }