예제 #1
0
        private CustomGanttTask CreateGanttTaskFromDbModel(TaskDbModel dbTask)
        {
            var ganttTask = new CustomGanttTask()
            {
                Id          = dbTask.Id,
                ParentId    = dbTask.ParentId,
                Title       = dbTask.Title,
                Description = dbTask.Description,
                Start       = dbTask.Start,
                End         = dbTask.Start.AddTicks(dbTask.Duration),
                Duration    = TimeSpan.FromTicks(dbTask.Duration),
                IsMilestone = dbTask.IsMilestone,
                Deadline    = dbTask.Deadline,
                Progress    = dbTask.Progress,
            };

            this.dbTaskToGanttTaskDict.Add(dbTask, ganttTask);

            if (dbTask.Children != null && dbTask.Children.Count > 0)
            {
                foreach (var item in dbTask.Children)
                {
                    var childGanttTask = CreateGanttTaskFromDbModel(item);
                    ganttTask.Children.Add(childGanttTask);
                }
            }

            return(ganttTask);
        }
예제 #2
0
 private TaskDbModel UpdateTaskDbModel(TaskDbModel dbTask, CustomGanttTask ganttTask)
 {
     dbTask.Id          = ganttTask.Id;
     dbTask.Title       = ganttTask.Title;
     dbTask.Description = ganttTask.Description;
     dbTask.Start       = ganttTask.Start;
     dbTask.Duration    = ganttTask.Duration.Ticks;
     dbTask.ParentId    = ganttTask.ParentId;
     dbTask.Progress    = ganttTask.Progress;
     dbTask.Deadline    = ganttTask.Deadline;
     dbTask.IsMilestone = ganttTask.IsMilestone;
     return(dbTask);
 }
예제 #3
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);
        }
예제 #4
0
        public static void PopuplateData(TasksDbContext context)
        {
            string[] descriptions = loremImpsum.Split('.').Select(x => x.Trim()).ToArray();

            int taskId     = 0;
            int relationId = 0;

            for (int i = 0; i < 5; i++)
            {
                var start = DateTime.Today;

                var rootTask = new TaskDbModel()
                {
                    Id          = taskId++,
                    Title       = "Root element " + i,
                    Start       = start,
                    Duration    = TimeSpan.FromDays(1).Ticks,
                    Description = descriptions[randomNumberGenerator.Next(0, descriptions.Length - 1)],
                    Children    = new List <TaskDbModel>(),
                };

                for (int k = 0; k < 3; k++)
                {
                    var childTask = new TaskDbModel()
                    {
                        Id          = taskId++,
                        ParentId    = rootTask.Id,
                        Title       = "Element " + i + "." + k,
                        Start       = rootTask.Start.AddHours(2),
                        Duration    = TimeSpan.FromHours(8).Ticks,
                        Children    = new List <TaskDbModel>(),
                        Description = descriptions[randomNumberGenerator.Next(0, descriptions.Length - 1)],
                        Progress    = randomNumberGenerator.Next(0, 100),
                    };

                    for (int j = 0; j < 2; j++)
                    {
                        childTask.Children.Add(new TaskDbModel()
                        {
                            Id          = taskId++,
                            ParentId    = childTask.Id,
                            Title       = "Element " + i + "." + k + "." + j,
                            Start       = childTask.Start.AddHours(2),
                            Description = descriptions[randomNumberGenerator.Next(0, descriptions.Length - 1)],
                            Duration    = TimeSpan.FromHours(8).Ticks,
                        });
                    }

                    rootTask.Children.Add(childTask);
                }

                context.Relations.Add(new RelationDbModel()
                {
                    Id    = relationId++,
                    Type  = 0,
                    Tasks = new List <TaskDbModel>()
                    {
                        rootTask.Children.ElementAt(0),
                        rootTask.Children.ElementAt(1),
                    },
                });

                context.Relations.Add(new RelationDbModel()
                {
                    Id    = relationId++,
                    Type  = 0,
                    Tasks = new List <TaskDbModel>()
                    {
                        rootTask.Children.ElementAt(1),
                        rootTask.Children.ElementAt(2),
                    },
                });

                context.Tasks.Add(rootTask);
            }
        }