public IEnumerable<OrgStructure> GetAll(Guid userId) { using (var ctx = new SkillSharingContext()) { return ctx.Users.Single(x => x.Id == userId).OrgStructures.ToList(); } }
public IEnumerable<PostState> GetByOrgStructure(Guid orgStructureId, Guid userId) { using (var ctx = new SkillSharingContext()) { return ctx.OrgStructures.Single(x => x.Id == orgStructureId).Channels.SelectMany(x => x.Posts).Select(x => GetPostState(x, userId)).ToList(); } }
public IEnumerable<PostState> GetAllTodo(Guid userId) { using (var ctx = new SkillSharingContext()) { return ctx.PostStates.Where(x => !x.IsHidden && x.IsTodo && x.User.Id == userId).Include(x => x.Post).ToList(); } }
public IEnumerable<PostState> GetByChannel(Guid channelId, Guid userId) { using (var ctx = new SkillSharingContext()) { return ctx.Channels.Single(x => x.Id == channelId).Posts.Select(x => GetPostState(x, userId)).ToList(); } }
public IEnumerable<PostState> GetAll(Guid userId) { using (var ctx = new SkillSharingContext()) { return ctx.Users.Single(x => x.Id == userId).Channels.SelectMany(x => x.Posts).Select(x => GetPostState(x, userId)).ToList(); } }
public PostState Create(string name, string content, bool isSticky, Guid userId, Guid channelId) { var post = new Post { Id = Guid.NewGuid(), Name = name, IsSticky = isSticky, Content = content, Timestamp = DateTime.Now, PublisherId = userId, ChannelId = channelId }; using (var ctx = new SkillSharingContext()) { ctx.Posts.Add(post); ctx.SaveChanges(); return new PostState { Id = Guid.NewGuid(), UserId = userId, Post = post, }; } }
public IEnumerable<Channel> GetAllSubscribed(Guid userId) { using (var ctx = new SkillSharingContext()) { return ctx.Users.Single(x => x.Id == userId).Channels.ToList(); } }
public IEnumerable<Channel> GetAll() { using (var ctx = new SkillSharingContext()) { return ctx.Channels.ToList(); } }
public void Unsubscribe(Guid channelId, Guid userId) { using (var ctx = new SkillSharingContext()) { var user = ctx.Users.Single(x => x.Id == userId); var channel = user.Channels.SingleOrDefault(x => x.Id == channelId); user.Channels.Remove(channel); ctx.SaveChanges(); } }
public UserDto GetCurrent() { using (var ctx = new SkillSharingContext()) { var user = ctx.Users.Single(); var dto = new UserDto { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, Mail = user.Mail }; UserSession.UserId = dto.Id; return dto; } }
public void UpdateState(PostState postState) { using (var ctx = new SkillSharingContext()) { var state = ctx.PostStates.SingleOrDefault(x => x.Id == postState.Id && x.UserId == postState.UserId); if (state == null) { state = new PostState { Id = Guid.NewGuid(), PostId = postState.PostId, UserId = postState.UserId }; ctx.PostStates.Add(state); } state.IsTodo = postState.IsTodo; state.IsDone = postState.IsDone; state.IsHidden = postState.IsHidden; ctx.SaveChanges(); } }