Esempio n. 1
0
        public async Task <OperationResult> DeleteUser(string factory_ID, string user_Account)
        {
            if (!await IsUserExists(factory_ID, user_Account))
            {
                operationResult = new OperationResult {
                    Success = false, Message = "User not found."
                };
                return(operationResult);
            }

            // Remove user's roles
            var userRoles = _roleUserRepository.FindAll(r => r.user_account == user_Account).ToList();

            if (userRoles.Count > 0)
            {
                _roleUserRepository.RemoveMultiple(userRoles);
                try
                {
                    await _roleUserRepository.Save();
                }
                catch (System.Exception)
                {
                    operationResult = new OperationResult {
                        Success = false, Message = "Cannot delete user's roles"
                    };
                }
            }

            // Remove user
            var user = await _userRepository.FindSingle(x => x.Factory_ID == factory_ID && x.User_Account == user_Account);

            _userRepository.Remove(user);
            try
            {
                await _userRepository.Save();

                operationResult = new OperationResult {
                    Success = true, Message = "User was successfully deleted."
                };
            }
            catch (System.Exception)
            {
                operationResult = new OperationResult {
                    Success = false, Message = "Deleting user failed on save."
                };
            }

            return(operationResult);
        }
Esempio n. 2
0
        public async Task <User_Logged_Dto> Login(string username, string password)
        {
            // Authorize user
            var user = await _UserRepository
                       .FindAll(x => x.User_Account.Trim() == username.Trim() && x.Password.Trim() == password)
                       .ProjectTo <User_Dto>(_mapperConfiguration)
                       .FirstOrDefaultAsync();

            if (user == null)
            {
                return(null);
            }

            // Get user roles
            var userRoles = await _roleUserRepository.FindAll(r => r.user_account == username).Select(r => r.role_unique).ToListAsync();

            var userToReturn = new User_Logged_Dto
            {
                Email        = user.Email,
                Factory_ID   = user.Factory_ID,
                User_Account = user.User_Account,
                User_Name    = user.User_Name,
                Role         = userRoles,
                Image        = user.Image
            };

            return(userToReturn);
        }
Esempio n. 3
0
        public async Task <UserForLogged_Dto> GetUser(string username)
        {
            var user = _repoUsers.FindSingle(x => x.Username.Trim() == username.Trim());

            // kiểm tra xem username đó có ko
            if (user == null)
            {
                return(null);
            }

            var roleUser = _repoRoleUser.FindAll(x => x.UserId == user.Id);
            var role     = _repoRoles.FindAll(x => x.WH_Type == "B");
            var roleName = await roleUser.Join(role, x => x.RoleId, y => y.Id, (x, y) => new Role_Dto { Name = y.RoleUnique, Position = y.RoleSeq }).ToListAsync();

            var result = new UserForLogged_Dto
            {
                Id       = user.Id,
                Email    = user.Email,
                Username = user.Username,
                Name     = user.Name,
                Nik      = user.Nik,
                Role     = roleName.OrderBy(x => x.Position).Select(x => x.Name).ToList()
            };

            return(result);
        }
Esempio n. 4
0
        public async Task <bool> CheckLoginByUser(int userid)
        {
            var model = await _repoRoleUser.FindAll().AnyAsync(x => x.UserID == userid && x.Status == true);

            return(model);
        }