Example #1
0
        public override bool UpdateUserProfile()
        {
            bool result = false;

            if (userId > 0)
            {
                using (var userUnitOfWork = new UserUnitOfWork(new AyudaContext()))
                {
                    var userProfile = userUnitOfWork.UserProfiles.GetUserProfileByUserId(userId);
                    if (userProfile.UserProfileId > 0)
                    {
                        userProfile.FirstName   = firstName;
                        userProfile.MiddleName  = middleName;
                        userProfile.LastName    = lastName;
                        userProfile.Gender      = gender;
                        userProfile.BirthDate   = birthDate;
                        userProfile.DateUpdated = DateTime.Now;

                        userUnitOfWork.UserProfiles.Update(userProfile);
                        result = userUnitOfWork.Complete() > 0;
                        userUnitOfWork.Dispose();
                    }
                }
            }
            return(result);
        }
        public override bool UpdateUserLogoutTime()
        {
            bool result = false;

            if (loginKey.ToString().Length == 36)
            {
                using (var userUnitOfWork = new UserUnitOfWork(new AyudaContext()))
                {
                    var userLogins = userUnitOfWork.UserLogins.GetUserLoginByLoginKey(loginKey);
                    userLogins.DateUpdated = DateTime.Now;
                    userLogins.LogoutTime  = DateTime.Now;
                    userUnitOfWork.UserLogins.Update(userLogins);
                    result = userUnitOfWork.Complete() > 0;
                    userUnitOfWork.Dispose();
                }
            }
            return(result);
        }
        public override bool InsertUserLogin()
        {
            bool result = false;

            if (userId > 0)
            {
                using (var userUnitOfWork = new UserUnitOfWork(new AyudaContext()))
                {
                    userUnitOfWork.UserLogins.Add(new UserLogin
                    {
                        UserId         = userId,
                        ExpirationDate = DateTime.Now.AddMinutes(Convert.ToInt32(JsonHelper.GetJsonValue("Token:ExpirationMinutes")))
                    });
                    userUnitOfWork.Complete();
                    userUnitOfWork.Dispose();
                }
            }
            return(result);
        }
Example #4
0
        public override bool UpdateUserTokenDateUpdated()
        {
            bool result = false;

            if (!string.IsNullOrEmpty(token))
            {
                using (var userUnitOfWork = new UserUnitOfWork(new AyudaContext()))
                {
                    var userToken = userUnitOfWork.UserTokens.GetUserTokenByToken(token);
                    if (userToken.UserTokenId > 0)
                    {
                        userToken.DateUpdated    = DateTime.Now;
                        userToken.ExpirationDate = DateTime.Now;
                        userUnitOfWork.UserTokens.Update(userToken);
                        result = userUnitOfWork.Complete() > 0;
                        userUnitOfWork.Dispose();
                    }
                }
            }
            return(result);
        }
Example #5
0
        public override UserToken InsertUserTokenAndRetrieveInsertedId()
        {
            var userToken = new UserToken();

            if (!string.IsNullOrEmpty(token))
            {
                using (var userUnitOfWork = new UserUnitOfWork(new AyudaContext()))
                {
                    userToken = new UserToken
                    {
                        UserId         = userId,
                        UserLoginId    = userLoginId,
                        Token          = token,
                        ExpirationDate = DateTime.Now.AddMinutes(Convert.ToInt32(JsonHelper.GetJsonValue("Token:ExpirationMinutes")))
                    };
                    userUnitOfWork.UserTokens.Add(userToken);
                    userUnitOfWork.Complete();
                    userUnitOfWork.Dispose();
                }
            }
            return(userToken);
        }
Example #6
0
        public override bool InsertUserToken()
        {
            bool result = false;

            if (!string.IsNullOrEmpty(token))
            {
                using (var userUnitOfWork = new UserUnitOfWork(new AyudaContext()))
                {
                    userUnitOfWork.UserTokens.Add(new UserToken
                    {
                        Token          = token,
                        ExpirationDate = DateTime.Now.AddMinutes(Convert.ToInt32(JsonHelper.GetJsonValue("Token:ExpirationMinutes"))),
                        UserId         = userId,
                        UserLoginId    = userLoginId
                    });
                    userUnitOfWork.Complete();
                    userUnitOfWork.Dispose();
                    result = true;
                }
            }
            return(result);
        }
Example #7
0
        public override bool UpdateUserPassword()
        {
            bool result = false;

            if (userKey.ToString().Length == 36 && !string.IsNullOrEmpty(oldPassword) && !string.IsNullOrEmpty(newPassword))
            {
                using (var userUnitOfWork = new UserUnitOfWork(new AyudaContext()))
                {
                    var user = userUnitOfWork.Users.GetUserByUserKey(userKey);
                    if (user.UserId > 0)
                    {
                        if (SecurePasswordHelper.Verify(oldPassword, user.Password))
                        {
                            user.Password = SecurePasswordHelper.Hash(newPassword);
                            userUnitOfWork.Users.Update(user);
                            result = userUnitOfWork.Complete() > 0;
                            userUnitOfWork.Dispose();
                        }
                    }
                }
            }
            return(result);
        }
Example #8
0
        public override int UpdateUserAndRetrieveUserId()
        {
            int userId = 0;

            if (userKey.ToString().Length == 36)
            {
                using (var userUnitOfWork = new UserUnitOfWork(new AyudaContext()))
                {
                    var user = userUnitOfWork.Users.GetUserByUserKey(userKey);
                    if (user.UserId > 0)
                    {
                        user.EmailAddress  = emailAddress;
                        user.ContactNumber = contactNumber;
                        user.DateUpdated   = DateTime.Now;

                        userUnitOfWork.Users.Update(user);
                        userUnitOfWork.Complete();
                        userUnitOfWork.Dispose();
                        userId = user.UserId;
                    }
                }
            }
            return(userId);
        }
Example #9
0
        public override int CreateUserAndRetrieveUserId()
        {
            int userId = 0;

            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
            {
                using (var userUnitOfWOrk = new UserUnitOfWork(new AyudaContext()))
                {
                    var user = new User
                    {
                        Username      = username,
                        Password      = SecurePasswordHelper.Hash(password),
                        EmailAddress  = emailAddress,
                        ContactNumber = contactNumber
                    };
                    userUnitOfWOrk.Users.Add(user);
                    userUnitOfWOrk.Complete();

                    userId = user.UserId;
                    userUnitOfWOrk.Dispose();
                }
            }
            return(userId);
        }
Example #10
0
        public override bool CreateUserProfile()
        {
            bool result = false;

            if (userId > 0 && !string.IsNullOrEmpty(firstName) && !string.IsNullOrEmpty(lastName))
            {
                using (var userUnitOfWork = new UserUnitOfWork(new AyudaContext()))
                {
                    var userProfile = new UserProfile
                    {
                        UserId     = userId,
                        FirstName  = firstName,
                        MiddleName = middleName,
                        LastName   = lastName,
                        Gender     = gender,
                        BirthDate  = birthDate
                    };
                    userUnitOfWork.UserProfiles.Add(userProfile);
                    result = userUnitOfWork.Complete() > 0;
                    userUnitOfWork.Dispose();
                }
            }
            return(result);
        }