示例#1
0
        public async Task <bool> Handle(ReadUserRequest message, IOutputPort <ReadUserResponse> outputPort)
        {
            if (message.UserId.ToString() != Guid.Empty.ToString())
            {
                DomainEntities.User user = await _userRepository.FindById(message.UserId);

                if (user == null)
                {
                    outputPort.Handle(new ReadUserResponse(new[] { new Error(Error.Codes.ENTITY_NOT_FOUND, Error.Messages.ENTITY_NOT_FOUND) }));
                }
                else
                {
                    outputPort.Handle(new ReadUserResponse(user));
                }
            }
            else
            {
                IPagedCollection <DomainEntities.User> users = _userRepository.FindAll();
                var filterStr = message.FilterString;
                if (filterStr.Contains(",") && filterStr.Contains(":") || filterStr.Contains(":"))
                {
                    var filterCriteria = filterStr.Split(",");
                    foreach (var crit in filterCriteria)
                    {
                        var keyVal = crit.Split(":");

                        users.FilterBy(keyVal[0], keyVal[1]);
                    }
                }
                else
                {
                    users.FilterBy(u => u.FirstName.Contains(filterStr) || u.LastName.Contains(filterStr) || u.Email.Contains(filterStr) || u.Account.Username.Contains(filterStr));
                }
                users.FilterBy(u => u.Id != _currentUser.Id);
                if (message.SortedBy == "Username")
                {
                    users.SortBy(u => u.Account.Username, message.SortOrder);
                }
                else
                {
                    users.SortBy(message.SortedBy, message.SortOrder);
                }
                var items = await users.GetItemsForPage(message.Page, message.PageSize);

                var pagination = new Pagination <DomainEntities.User>
                {
                    Items      = items,
                    TotalItems = users.TotalItems(),
                    TotalPages = users.TotalPages(),
                    Page       = message.Page
                };

                outputPort.Handle(new ReadUserResponse(pagination));
            }

            return(true);
        }
示例#2
0
 public ReadUserResponse(DomainEntities.User user, bool success = true, string message = null) : base(success, message)
 {
     User = user;
 }
 public ChangeUsersStatusUseCase(IUserRepository userRepository, IAuthService authService)
 {
     _userRepository = userRepository;
     _currentUser    = authService.GetCurrentUser();
 }