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); }
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); }
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); }
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); }
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); }