Exemple #1
0
        public async Task <StoryEntity> GetStoryById(int Id)
        {
            var story = await _storyRepository
                        .GetAll(m => m.Id == Id)
                        .Include(s => s.StoryGroups)
                        .Include(s => s.User)
                        .FirstOrDefaultAsync();

            var storyAssembler = new StoryAssembler();
            var storyEntity    = storyAssembler.DomainEntityToDto(story);

            return(storyEntity);
        }
Exemple #2
0
        public async Task <List <GroupEntity> > GetGroups(string include = "")
        {
            var _groups = _groupRepository.GetAll();


            if (include.Split(';').Any(i => i.ToLower() == "stories"))
            {
                _groups.Include(m => m.StoryGroups);
                _groups.Include(m => m.StoryGroups.Select(sg => sg.Story));
            }

            var groups = await _groups.ToListAsync();

            var groupAssembler = new GroupAssembler();
            var groupEntities  = groupAssembler.DomainEntitiesToDtos(groups);

            if (include.Split(';').Any(i => i.ToLower() == "users"))
            {
                var groupUsersCount = await _userRepository.GetAll().GroupBy(u => u.GroupId).Select(g => new { GroupId = g.FirstOrDefault().GroupId, Count = g.Count() }).ToListAsync();

                foreach (var guc in groupUsersCount)
                {
                    groupEntities.FirstOrDefault(m => m.Id == guc.GroupId).UsersCount = guc.Count;
                }
            }

            return(groupEntities);
        }
Exemple #3
0
        public async Task <List <StoryEntity> > GetStoriesByUserName(string username)
        {
            var user = await _userRepository
                       .GetAll(m => m.Name == username)
                       .Include(s => s.Stories)
                       .FirstOrDefaultAsync();

            if (user == null)
            {
                return(null);
            }

            var storyAssembler = new StoryAssembler();
            var storyEntities  = storyAssembler.DomainEntitiesToDtos(user.Stories);

            return(storyEntities);
        }
Exemple #4
0
        public async Task <bool> CheckUserCredentials(UserEntity user)
        {
            var _userDto = await _userRepository.GetAll(u => u.Password == user.Password && u.Name == u.Name).FirstOrDefaultAsync();

            if (_userDto != null)
            {
                return(true);
            }
            return(false);
        }
Exemple #5
0
        public async Task <List <StoryEntity> > GetGroupStories(int groupId)
        {
            var group = await _groupRepository
                        .GetAll(u => u.Id == groupId)
                        .Include(s => s.StoryGroups)
                        .Include(s => s.StoryGroups.Select(sg => sg.Story))
                        .FirstOrDefaultAsync();

            if (group == null)
            {
                return(null);
            }

            var storyAssembler = new StoryAssembler();
            var storyEntities  = storyAssembler.DomainEntitiesToDtos(group.StoryGroups.Select(sg => sg.Story));

            return(storyEntities);
        }