public async Task <StoryEntity> UpdateStory(StoryEntity storyEntity) { try { var db_story = await _storyRepository.GetAll(m => m.Id == storyEntity.Id).FirstOrDefaultAsync(); db_story.Title = storyEntity.Title; db_story.Content = storyEntity.Content; db_story.Description = storyEntity.Description; foreach (var sg in db_story.StoryGroups.ToList()) { db_story.StoryGroups.Remove(sg); } db_story.StoryGroups = storyEntity.Groups.Select(g => new StoryGroup { GroupId = g.Id }).ToList(); if (!(await _storiesUoW.CommitAsync())) { return(null); } var storyAssembler = new StoryAssembler(); return(storyAssembler.DomainEntityToDto(db_story)); } catch (Exception ex) { return(null); } }
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 <StoryEntity> > GetStories() { var stories = await _storyRepository .GetAll() .Include(s => s.StoryGroups) .Include(s => s.StoryGroups.Select(sg => sg.Group)) .Include(s => s.User) .ToListAsync(); var storyAssembler = new StoryAssembler(); var storyEntities = storyAssembler.DomainEntitiesToDtos(stories); return(storyEntities); }
public async Task <StoryEntity> CreateStory(StoryEntity storyEntity) { var storyAssembler = new StoryAssembler(); var de = storyAssembler.DtoToDomainEntity(storyEntity); _storyRepository.Create(de); if (!(await _storiesUoW.CommitAsync())) { return(null); } return(storyAssembler.DomainEntityToDto(de)); }
public async Task <List <StoryEntity> > GetUserStories(int userId) { var user = await _userRepository .GetAll(u => u.Id == userId) .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 <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 <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); }