コード例 #1
0
ファイル: RepositoryBase.cs プロジェクト: hanuoc/tenatms
        public IEnumerable <T> GetAll(string[] includes = null)
        {
            //HANDLE INCLUDES FOR ASSOCIATED OBJECTS IF APPLICABLE
            if (includes != null && includes.Count() > 0)
            {
                var query = dataContext.Set <T>().Include(includes.First());
                foreach (var include in includes.Skip(1))
                {
                    query = query.Include(include);
                }
                return(query.AsQueryable());
            }

            return(dataContext.Set <T>().AsQueryable());
        }
コード例 #2
0
        public void Update(Task item)
        {
            db.Update(item);

            var ModeratorsDbSet = context.Set <TaskModerator_User>();
            var ViewersDbSet    = context.Set <TaskViewer_User>();
            var LabelsDbSets    = context.Set <Task_Label_User>();

            var newModerators = item.Moderators.ToArray();
            var newViewers    = item.Viewers.ToArray();
            var newLabels     = item.Labels.ToArray();

            var toRemoveModerators = ModeratorsDbSet
                                     .Where(id => id.TaskId == item.Id)
                                     .Except(newModerators);
            var toAddModerators = newModerators
                                  .Except(ModeratorsDbSet);

            var toRemoveViewers = ViewersDbSet
                                  .Where(id => id.TaskId == item.Id)
                                  .Except(newViewers);
            var toAddViewers = newViewers
                               .Except(ViewersDbSet);

            var toRemoveLabels = LabelsDbSets
                                 .Where(i => i.TaskId == item.Id && i.UserId == item.CurrentUserId);

            ModeratorsDbSet.RemoveRange(toRemoveModerators);
            ModeratorsDbSet.AddRange(toAddModerators);

            ViewersDbSet.RemoveRange(toRemoveViewers);
            ViewersDbSet.AddRange(toAddViewers);

            LabelsDbSets.RemoveRange(toRemoveLabels);
            LabelsDbSets.AddRange(newLabels);
        }