Exemplo n.º 1
0
        public IList<User> GetUsersAll(UserFilter filterData, IUsersRepository repository)
        {
            ValidateRepositoryInstance(repository);

            var users = repository.GetUsers(filterData, int.MaxValue, 0);
            return users;
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 4
0
        public void Delete(IUsersRepository repository)
        {
            ValidateRepositoryInstance(repository);

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

            this.Delete(filterData, repository);
        }
Exemplo n.º 5
0
        public void Delete(UserFilter filterData, IUsersRepository repository)
        {
            ValidateRepositoryInstance(repository);

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

            repository.Delete(filterData);
        }
Exemplo n.º 6
0
        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");
        }