public async Task InsertUserActionToDB(UserActionCreateDTO userAction)
 {
     // Map, add fields to customer entity
     UserAction userActionEntity = AMapper.Mapper.Map <UserActionCreateDTO, UserAction>(userAction);
     // Insert a customer into the database
     await UserActionRepository.Insert(userActionEntity);
 }
Esempio n. 2
0
        /// <summary>
        /// get UserLoginDTO by username and password
        /// </summary>
        /// <param name="userLogInDTO"></param>
        /// <returns></returns>
        public async Task <UserGetDetailDTO> LogIn(UserLogInDTO userLogInDTO)
        {
            // find users by UserName
            // delete after making ValidationService
            User userEntity = await UserRepository.GetByUserName(userLogInDTO.UserName);

            var userGetDetailDTO = AMapper.Mapper.Map <User, UserGetDetailDTO>(userEntity);

            // add record about signing in the user
            var userAction = new UserActionCreateDTO(userGetDetailDTO.UserID, UserActionType.LogIn);
            await UserActionService.InsertUserActionToDB(userAction);

            return(userGetDetailDTO);
        }
Esempio n. 3
0
        public async Task <int> SignUp(UserCreateDTO user)
        {
            string dynamicSalt    = HashHelper.GetDynamicSalt(user.UserName);
            string hashedPassword = HashHelper.GetPasswordHash(user.Password, dynamicSalt);

            // Map, add fields to customer entity
            User userEntity = AMapper.Mapper.Map <UserCreateDTO, User>(user);

            userEntity.DynamicSalt    = dynamicSalt;
            userEntity.HashedPassword = hashedPassword;

            // Insert the user into the database
            int newUserID = await UserRepository.Insert(userEntity);

            // add record about registration of the user
            var userAction = new UserActionCreateDTO(newUserID, UserActionType.SignUp);
            await UserActionService.InsertUserActionToDB(userAction);

            return(newUserID);
        }
Esempio n. 4
0
        public async Task UpdateUser(UserUpdateDTO user)
        {
            // Map, add fields to customer entity
            User userEntity = AMapper.Mapper.Map <UserUpdateDTO, User>(user);

            var outdatedUser = await UserRepository.GetById(user.UserID);

            if (user.Password == null || user.Password.Length < 1)
            {
                userEntity.HashedPassword = outdatedUser.HashedPassword;
            }
            else
            {
                string hashedPassword = HashHelper.GetPasswordHash(user.Password, outdatedUser.DynamicSalt);
                userEntity.HashedPassword = hashedPassword;
            }

            // Update the customer in the database
            await UserRepository.Update(userEntity);

            // add record about editing of the user
            var userAction = new UserActionCreateDTO(userEntity.UserID, UserActionType.Edit);
            await UserActionService.InsertUserActionToDB(userAction);
        }
Esempio n. 5
0
 public async Task LogOut(int userID)
 {
     var userAction = new UserActionCreateDTO(userID, UserActionType.LogOut);
     await UserActionService.InsertUserActionToDB(userAction);
 }