Exemple #1
0
        public void Add(UserDto dto)
        {
            if (!dto.IsValid())
            {
                NotifyValidationError(dto);
                return;
            }

            var currentUser = _requestScope.GetUser();

            if (currentUser.Profile == ProfileType.Standard)
            {
                NotifyError(DomainError.StandardProfileUserDoesNotHavePermission);
                return;
            }

            if (!ValidadePassword(dto))
            {
                return;
            }

            var user = new User(dto.Name, dto.Password.Encrypt(), dto.Email, dto.Profile.Value);

            _userRepository.Add(user);
            Commit();
        }
Exemple #2
0
        public void Add(FavoriteBookModel model)
        {
            var dto = _mapper.Map <FavoriteBookDto>(model);

            dto.User = _requestScope.GetUser();
            _favoriteBookService.Add(dto);
        }
        public override (int totalItems, IList <FavoriteBook> entities) Get(Filter filter)
        {
            var user       = _requestScope.GetUser();
            var query      = GetAll();
            var totalItems = 0;

            if (filter.Search.HasValue())
            {
                query = query.Where(x => x.Title.ToLower().Contains(filter.Search.ToLower()));
            }

            if (user != null)
            {
                query = query.Where(x => x.UserId == user.Id);
            }

            if (filter.TotalItems.HasValue)
            {
                totalItems = filter.TotalItems.Value;
            }
            else
            {
                totalItems = query.Count();
            }

            query = query.Paginate(filter.CurrentPage, filter.ItemsPerPage);

            query = query.Include(x => x.User);

            var entities = query.ToList();

            return(totalItems : totalItems, entities : entities);
        }