コード例 #1
0
ファイル: DatabaseController.cs プロジェクト: kkonczak/TeaMan
        public static async Task AddTaskTypeAsync(Models.TaskType taskType)
        {
            using (var dbContext = new DatabaseContext())
            {
                var orderOfLastTaskType = await dbContext.TaskTypes
                                          .Select(e => (int?)e.Order)
                                          .MaxAsync();

                taskType.Order = orderOfLastTaskType ?? 0 + 1;
                dbContext.TaskTypes.Add(taskType);
                await dbContext.SaveChangesAsync();
            }
        }
コード例 #2
0
ファイル: DatabaseController.cs プロジェクト: kkonczak/TeaMan
        public static async Task InitializeDatabaseAsync()
        {
            using (var dbContext = new DatabaseContext())
            {
                await dbContext.Database.MigrateAsync();

                // Create default calendars
                if (dbContext.Calendars.AsQueryable().Count() == 0)
                {
                    var todoStatus       = new Models.TaskStatus("To do", 1);
                    var inProgressStatus = new Models.TaskStatus("In progress", 2);
                    var doneStatus       = new Models.TaskStatus("Done", 3);

                    var bugType     = new Models.TaskType("Bug", 1);
                    var backlogType = new Models.TaskType("Backlog", 2);
                    var featureType = new Models.TaskType("Feature", 3);

                    var calendar = new Models.Calendar("Your first calendar", 1)
                    {
                        TaskStatuses = { todoStatus, inProgressStatus, doneStatus },
                        TaskTypes    = { bugType, backlogType, featureType },
                        UserTasks    =
                        {
                            new Models.UserTask
                            {
                                Name         = "This is the test task. You can add new Task using button \"Add Task\"",
                                TaskStatus   = todoStatus,
                                TaskType     = bugType,
                                PlannedStart = DateTime.Now,
                                PlannedEnd   = DateTime.Now.AddHours(8)
                            },
                            new Models.UserTask
                            {
                                Name         = "This is the second test task. You can add new Task using button \"Add Task\"",
                                TaskStatus   = todoStatus,
                                TaskType     = bugType,
                                PlannedStart = DateTime.Now.AddHours(10),
                                PlannedEnd   = DateTime.Now.AddHours(12)
                            }
                        }
                    };

                    var todoStatus2       = new Models.TaskStatus("To do", 1);
                    var inProgressStatus2 = new Models.TaskStatus("In progress", 2);
                    var doneStatus2       = new Models.TaskStatus("Done", 3);

                    var homeType    = new Models.TaskType("Home", 1);
                    var companyType = new Models.TaskType("Company", 2);

                    var calendar2 = new Models.Calendar("Your second calendar", 1)
                    {
                        TaskStatuses = { todoStatus2, inProgressStatus2, doneStatus2 },
                        TaskTypes    = { homeType, companyType },
                        UserTasks    =
                        {
                            new Models.UserTask
                            {
                                Name         = "This is the test task in second calendar. You can add new Task using button \"Add Task\"",
                                TaskStatus   = todoStatus2,
                                TaskType     = homeType,
                                PlannedStart = DateTime.Now,
                                PlannedEnd   = DateTime.Now.AddHours(2)
                            },
                            new Models.UserTask
                            {
                                Name         = "This is the second test task in second calendar. You can add new Task using button \"Add Task\"",
                                TaskStatus   = todoStatus2,
                                TaskType     = companyType,
                                PlannedStart = DateTime.Now.AddHours(2),
                                PlannedEnd   = DateTime.Now.AddHours(1)
                            }
                        }
                    };

                    dbContext.Calendars.Add(calendar);
                    dbContext.Calendars.Add(calendar2);
                    await dbContext.SaveChangesAsync();
                }
            }
        }