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