コード例 #1
0
        public IList<User> GetUsersAll(UserFilter filterData, IUsersRepository repository)
        {
            ValidateRepositoryInstance(repository);

            var users = repository.GetUsers(filterData, int.MaxValue, 0);
            return users;
        }
コード例 #2
0
ファイル: User.cs プロジェクト: jornfilho/services-monitoring
        public User Get(UserFilter filterData, IUsersRepository repository)
        {
            ValidateRepositoryInstance(repository);
            this.CleanModel();

            var users = repository.GetUsers(filterData, 1, 0);
            if (users == null || !users.Any())
                return this;

            var user = users.FirstOrDefault();
            if (user == null)
                return this;

            this.Id = user.Id;
            this.Name = user.Name;
            this.Email = user.Email;
            this.ServicesList = user.ServicesList;
            this.Status = user.Status;

            return this;
        }
コード例 #3
0
        public Users GetUsersPaginated(UserFilter filterData, Pagination pagination, IUsersRepository repository)
        {
            ValidateRepositoryInstance(repository);

            if(pagination == null)
                pagination = new Pagination().SetRequestData(int.MaxValue, 0);

            this.Pagination = pagination;

            var usersCount = repository.GetUsersCount(filterData);
            this.Pagination.SetResponseData(0);
            if (usersCount == 0)
            {
                this.Pagination.SetResponseData(0);
                return this;
            }

            var users = repository.GetUsers(filterData, pagination.PageSize, this.Pagination.CurrentPage * this.Pagination.PageSize);
            this.UsersList = users;
            
            return this;
        }
コード例 #4
0
ファイル: User.cs プロジェクト: jornfilho/services-monitoring
        public void Delete(IUsersRepository repository)
        {
            ValidateRepositoryInstance(repository);

            var filterData = new UserFilter().SetIds(new[] { this.Id });

            this.Delete(filterData, repository);
        }
コード例 #5
0
ファイル: User.cs プロジェクト: jornfilho/services-monitoring
        public void Delete(UserFilter filterData, IUsersRepository repository)
        {
            ValidateRepositoryInstance(repository);

            if(filterData == null || !filterData.HasFilter())
                throw new ArgumentException("Invalid filter data");

            repository.Delete(filterData);
        }
コード例 #6
0
ファイル: User.cs プロジェクト: jornfilho/services-monitoring
        private void ValidateExistentEmail(IUsersRepository repository)
        {
            var filter = new UserFilter().SetEmail(this.Email);

            if (string.IsNullOrEmpty(this.Id))
            {
                var count = repository.GetUsersCount(filter);
                if(count > 0)
                    throw new ArgumentException("There is another user with the same email");

                return;
            }

            var users = repository.GetUsers(filter, 2, 0);
            if (users == null || !users.Any())
                return;

            if (users.All(u => u.Id == this.Id))
                return;

            throw new ArgumentException("There is another user with the same email");
        }