Пример #1
0
        public void UpdateDatabase()
        {
            foreach (var item in this.dbTaskToGanttTaskDict)
            {
                var ganttTask = item.Value;
                var dbModel   = UpdateTaskDbModel(item.Key, item.Value);

                foreach (Dependency dependency in ganttTask.Dependencies)
                {
                    RelationDbModel dbRelation = CreateOrUpdateRelationDbModel(dbModel, dependency);
                    this.context.Entry(dbRelation).State = EntityState.Modified;
                }
                this.context.Entry(dbModel).State = EntityState.Modified;
            }

            context.SaveChanges();
        }
Пример #2
0
        private RelationDbModel CreateOrUpdateRelationDbModel(TaskDbModel dbTask, Dependency ganttDependency)
        {
            RelationDbModel dbRelation = this.ganttDependencyToDbRelationDict[ganttDependency];

            if (dbRelation == null)
            {
                dbRelation       = new RelationDbModel();
                dbRelation.Id    = this.context.Relations.Max(r => r.Id) + 1;
                dbRelation.Tasks = new List <TaskDbModel>()
                {
                    null, null
                };
                this.context.Relations.Add(dbRelation);
            }
            dbRelation.Tasks[0] = this.dbTaskToGanttTaskDict.FirstOrDefault(t => t.Value == (CustomGanttTask)ganttDependency.FromTask).Key;
            dbRelation.Tasks[1] = dbTask;
            dbRelation.Type     = (int)ganttDependency.Type;

            return(dbRelation);
        }