예제 #1
0
 public HomeController(UserByIdQuery userByIdQuery, 
                       IServiceFactory factory,
                       IProcess<ByUserIdParams, VisibleOrgOfficialDocListForUserViewModel> userVisibleDocProcess)
 {
     _userByIdQuery = userByIdQuery;
     _serviceFactory = factory;
     _unitOfWork = factory.GetService<IUnitOfWork>();
     _userVisibleDocsProcess = userVisibleDocProcess;
 }
예제 #2
0
 public MilestoneController(IProcess <ByOrganizationIdParams, MilestoneDisplayListViewModel> milestoneListQuery,
                            IProcess <MilestoneIdParams, MilestoneDisplayViewModel> milestoneQuery,
                            IProcess <SaveMilestoneParams, MilestoneIdViewModel> saveMilestoneProcess,
                            UserByIdQuery userByIdQuery)
 {
     _milestoneListQuery   = milestoneListQuery;
     _userByIdQuery        = userByIdQuery;
     _milestoneQuery       = milestoneQuery;
     _saveMilestoneProcess = saveMilestoneProcess;
 }
예제 #3
0
        public async Task <UserVm> Handle(UserByIdQuery query, CancellationToken cancellationToken)
        {
            var user = await _userRepository.FindAsync(x => x.Id == query.Id);

            if (user != null)
            {
                return(user.ToVm());
            }
            Notifications.Handle("Usuario Não encontrado");
            return(null);
        }
예제 #4
0
        public User GetUser(Guid userId)
        {
            var query = new UserByIdQuery(dbContext.Users);
            var user  = query.Execute(userId);

            if (user == null)
            {
                throw new EntityNotFoundException("User", userId);
            }

            return(new UserMapper().Map(query.Execute(userId)));
        }
예제 #5
0
 public CompanyController(IUnitOfWork unitOfWork, 
                          ISearchProvider searchProvider, 
                          IServiceFactory serviceFactory,
                          UserByIdQuery userByIdQuery,
                          IProcess<CompanyQueryAuthorizationParams, AuthorizationResultViewModel> compAuthProcess)
 {
     _unitOfWork = unitOfWork;
     _searchProvider = searchProvider;
     _serviceFactory = serviceFactory;
     _companyAuthProcess = compAuthProcess;
     _userByIdQuery = userByIdQuery;
 }
예제 #6
0
        public User GetUser(Guid id)
        {
            var query = new UserByIdQuery(dbContext.Users);
            var user  = query.Execute(id);

            if (user == null)
            {
                throw new EntityNotFoundException("User", id);
            }

            return(user);
        }
예제 #7
0
 public CompanyController(IUnitOfWork unitOfWork,
                          ISearchProvider searchProvider,
                          IServiceFactory serviceFactory,
                          UserByIdQuery userByIdQuery,
                          IProcess <CompanyQueryAuthorizationParams, AuthorizationResultViewModel> compAuthProcess)
 {
     _unitOfWork         = unitOfWork;
     _searchProvider     = searchProvider;
     _serviceFactory     = serviceFactory;
     _companyAuthProcess = compAuthProcess;
     _userByIdQuery      = userByIdQuery;
 }
예제 #8
0
        public void Execute_Returns_Null_User_When_UserId_Not_Found()
        {
            // Setup
            InitializeTestEntities();
            int id = _user.Id + 100;

            // Act
            User result = new UserByIdQuery(_unitOfWork).WithUserId(id).Execute();

            // Verify
            Assert.IsNull(result, "Query returned a non-null user");
        }
예제 #9
0
        public void Can_Retrieve_User_By_Id()
        {
            // Setup
            InitializeTestEntities();

            // Act
            User result = new UserByIdQuery(_unitOfWork).WithUserId(_user.Id).Execute();

            // Verify
            Assert.IsNotNull(result, "User returned was null");
            Assert.AreEqual(result.Id, _user.Id, "User returned had an incorrect id value");
        }
예제 #10
0
        public void Can_Retrieve_User_By_Id()
        {
            // Setup
            InitializeTestEntities();

            // Act
            User result = new UserByIdQuery(_unitOfWork).WithUserId(_user.Id).Execute();

            // Verify
            Assert.IsNotNull(result, "User returned was null");
            Assert.AreEqual(result.Id, _user.Id, "User returned had an incorrect id value");
        }
예제 #11
0
        public void Execute_Returns_Null_User_When_UserId_Not_Found()
        {
            // Setup
            InitializeTestEntities();
            int id = _user.Id + 100;

            // Act
            User result = new UserByIdQuery(_unitOfWork).WithUserId(id).Execute();

            // Verify
            Assert.IsNull(result, "Query returned a non-null user");
        }
예제 #12
0
        public async Task<IActionResult> Get(UserModel userModel)
        {
            var identifier = User.FindFirstValue(ClaimTypes.NameIdentifier);
            if (string.IsNullOrEmpty(identifier))
            {
                return BadRequest();
            }

            var query = new UserByIdQuery(Guid.Parse(identifier));
            var user = await _messageDispatcher.Execute(query);

            return Json(user);
        }
예제 #13
0
        public async Task <IActionResult> Get(UserModel userModel)
        {
            var identifier = User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (string.IsNullOrEmpty(identifier))
            {
                return(HttpBadRequest());
            }

            var query = new UserByIdQuery(Guid.Parse(identifier));
            var user  = await _messageDispatcher.Execute(query);

            return(Json(user));
        }
예제 #14
0
        public IActionResult GetUserAsync()
        {
            try
            {
                var query = new UserByIdQuery(17);
                var user  = _queryProcessor.Process(query);

                return(new OkObjectResult(user));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #15
0
        public async Task <RequestResult <UserResponse> > Handle(UserByIdQuery request, CancellationToken cancellationToken)
        {
            try
            {
                var user = await _ctx.Users.FirstOrDefaultAsync(x => x.Id == request.Id);

                if (user == null)
                {
                    return(RequestResult.Error <UserResponse>());
                }
                var response = _mapper.Map <UserResponse>(user);
                return(RequestResult.Success(response));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error getting user", ex);
                return(RequestResult.Error <UserResponse>());
            }
        }
예제 #16
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <returns></returns>
        /// <exception cref="MJLEntityNotFoundException">Thrown when the specified user isn't found</exception>
        public virtual User Execute()
        {
            // Retrieve the user
            var user = new UserByIdQuery(_unitOfWork).WithUserId(_userId).Execute();

            if (user == null)
            {
                throw new MJLEntityNotFoundException(typeof(User), _userId);
            }

            // Only check the current password if the user is only changing the last visited job search
            if (!string.IsNullOrWhiteSpace(_newPassword) || !string.IsNullOrWhiteSpace(_newName))
            {
                // Verify the user's current password is correct
                if (new UserByCredentialsQuery(_unitOfWork).WithEmail(user.Email).WithPassword(_oldPassword).Execute() == null)
                {
                    throw new MJLIncorrectPasswordException(_userId);
                }
            }

            // Edit the properties
            if (!string.IsNullOrWhiteSpace(_newPassword))
            {
                user.Password = PasswordUtils.CreatePasswordHash(user.Email, _newPassword);
            }

            if (_newName != null)
            {
                user.FullName = _newName.Trim();
            }
            if (_updateLastJobSearch)
            {
                user.LastVisitedJobSearchId = _lastJobSearchId;
            }

            // Save
            _unitOfWork.Commit();
            return(user);
        }
예제 #17
0
 public JobSearchController(JobSearchesByUserIdQuery jobSearchesByIdQuery,
                            JobSearchByIdQuery jobSearchByIdQuery,
                            CreateJobSearchForUserCommand createJobSearchCommand,
                            EditJobSearchCommand editJobSearchCommand,
                            OpenTasksByJobSearchQuery openTasksByJobSearchQuery,
                            EditUserCommand editUserCommand,
                            EntitySearchQuery entitySearchQuery,
                            UserByIdQuery userByIdQuery,
                            StartNextJobSearchMilestoneCommand startNextMilestoneCmd,
                            IProcess <ByJobSearchParams, JobsearchExportViewModel> exportProcess,
                            IServiceFactory serviceFactory)
 {
     _jobSearchByIdQuery        = jobSearchByIdQuery;
     _jobSearchesByUserIdQuery  = jobSearchesByIdQuery;
     _createJobSearchCommand    = createJobSearchCommand;
     _editJobSearchCommand      = editJobSearchCommand;
     _openTasksByJobSearchQuery = openTasksByJobSearchQuery;
     _editUserCommand           = editUserCommand;
     _entitySearchQuery         = entitySearchQuery;
     _serviceFactory            = serviceFactory;
     _userByIdQuery             = userByIdQuery;
     _startNextMilestoneCmd     = startNextMilestoneCmd;
     _exportProcess             = exportProcess;
 }
예제 #18
0
 public JobSearchController(JobSearchesByUserIdQuery jobSearchesByIdQuery,
                             JobSearchByIdQuery jobSearchByIdQuery,
                             CreateJobSearchForUserCommand createJobSearchCommand,
                             EditJobSearchCommand editJobSearchCommand,
                             OpenTasksByJobSearchQuery openTasksByJobSearchQuery,
                             EditUserCommand editUserCommand,
                             EntitySearchQuery entitySearchQuery,
                             UserByIdQuery userByIdQuery,
                             StartNextJobSearchMilestoneCommand startNextMilestoneCmd,
                             IProcess<ByJobSearchParams, JobsearchExportViewModel> exportProcess,
                             IServiceFactory serviceFactory)
 {
     _jobSearchByIdQuery = jobSearchByIdQuery;
     _jobSearchesByUserIdQuery = jobSearchesByIdQuery;
     _createJobSearchCommand = createJobSearchCommand;
     _editJobSearchCommand = editJobSearchCommand;
     _openTasksByJobSearchQuery = openTasksByJobSearchQuery;
     _editUserCommand = editUserCommand;
     _entitySearchQuery = entitySearchQuery;
     _serviceFactory = serviceFactory;
     _userByIdQuery = userByIdQuery;
     _startNextMilestoneCmd = startNextMilestoneCmd;
     _exportProcess = exportProcess;
 }
예제 #19
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <returns></returns>
        /// <exception cref="MJLEntityNotFoundException">Thrown when the specified user isn't found</exception>
        public virtual User Execute()
        {
            // Retrieve the user
            var user = new UserByIdQuery(_unitOfWork).WithUserId(_userId).Execute();
            if (user == null)
                throw new MJLEntityNotFoundException(typeof(User), _userId);

            // Only check the current password if the user is only changing the last visited job search
            if (!string.IsNullOrWhiteSpace(_newPassword) || !string.IsNullOrWhiteSpace(_newName))
            {
                // Verify the user's current password is correct
                if (new UserByCredentialsQuery(_unitOfWork).WithEmail(user.Email).WithPassword(_oldPassword).Execute() == null)
                    throw new MJLIncorrectPasswordException(_userId);
            }

            // Edit the properties
            if (!string.IsNullOrWhiteSpace(_newPassword))
                user.Password = PasswordUtils.CreatePasswordHash(user.Email, _newPassword);

            if (_newName != null) { user.FullName = _newName.Trim(); }
            if (_updateLastJobSearch) { user.LastVisitedJobSearchId = _lastJobSearchId; }

            // Save
            _unitOfWork.Commit();
            return user;
        }
예제 #20
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <returns></returns>
        /// <exception cref="MJLEntityNotFoundException">Thrown when the specified job search is not found</exception>
        public virtual JobSearch Execute()
        {
            // Retrieve the job search
            var search = new JobSearchByIdQuery(_unitOfWork).WithJobSearchId(_jobSearchId).Execute();
            if (search == null)
                throw new MJLEntityNotFoundException(typeof(JobSearch), _jobSearchId);

            // Retrieve the calling user
            var user = new UserByIdQuery(_unitOfWork).WithUserId(_userId).Execute();
            if (user == null)
                throw new MJLEntityNotFoundException(typeof(User), _userId);

            // Only edit the properties that were requested
            if (_newName != null)
                search.Name = _newName;

            if (_newDesc != null)
                search.Description = _newDesc;

            if (_resetHiddenStatusList)
                search.HiddenCompanyStatuses = string.Empty;

            // Append to the hidden company status list
            if (_hiddenStatuses.Count > 0)
                foreach (string status in _hiddenStatuses)
                    search.HiddenCompanyStatuses += status + ";";

            // Create the history record
            search.History.Add(new JobSearchHistory
            {
                HistoryAction = MJLConstants.HistoryUpdate,
                DateModified = DateTime.Now,
                AuthoringUser = user,
                Name = search.Name,
                Description = search.Description,
                HiddenCompanyStatuses = search.HiddenCompanyStatuses
            });

            // Commit
            _unitOfWork.Commit();
            return search;
        }
 public Task <IActionResult> GetUserById(UserByIdQuery query) => ExecuteQuery(query);
예제 #22
0
 public async Task <Optional <User> > RunAsync(UserByIdQuery query, CancellationToken ct)
 => Optional.FromNullable(await _db.Set <User>().FindAsync(new object[] { query.UserId }, ct));