示例#1
0
        public static async Task AddRange(string creatorSid, DateTime planDate, int[] taskIds, int[] checkpointIds)
        {
            if (taskIds == null && checkpointIds == null)
            {
                throw new ArgumentException("Не указаны задачи и контрольные точки для сохранения");
            }

            TaskTrackerContext db = new TaskTrackerContext();
            var taskPlanList      = new List <TaskPlan>();

            if (taskIds != null && taskIds.Any())
            {
                foreach (int taskId in taskIds)
                {
                    var taskPlan = new TaskPlan()
                    {
                        PlanDate   = planDate,
                        TaskId     = taskId,
                        Enabled    = true,
                        CreatorSid = creatorSid,
                        DateCreate = DateTime.Now
                    };
                    taskPlanList.Add(taskPlan);
                }

                //taskPlanList = taskIds.Select(delegate(int taskId)
                //{



                //    return new TaskPlan()
                //    {
                //        PlanDate = planDate,
                //        TaskId = taskId,
                //        Enabled = true,
                //        CreatorSid = creatorSid,
                //        DateCreate = DateTime.Now
                //    };
                //}).ToList();
            }
            if (checkpointIds != null && checkpointIds.Any())
            {
                taskPlanList.AddRange(checkpointIds.Select(checkpointId => new TaskPlan()
                {
                    PlanDate         = planDate,
                    TaskId           = TaskCheckpoint.Get(checkpointId).TaskId,
                    TaskCheckpointId = checkpointId,
                    Enabled          = true,
                    CreatorSid       = creatorSid,
                    DateCreate       = DateTime.Now
                }));
            }


            db.TaskPlans.AddRange(taskPlanList);
            await db.SaveChangesAsync();
        }
示例#2
0
        public static async Task AddRange(string creatorSid,DateTime planDate, int[] taskIds, int[] checkpointIds)
        {
            if (taskIds == null && checkpointIds == null) throw new ArgumentException("Не указаны задачи и контрольные точки для сохранения");

            TaskTrackerContext db = new TaskTrackerContext();
            var taskPlanList = new List<TaskPlan>();
            if (taskIds != null && taskIds.Any())
            {
                foreach (int taskId in taskIds)
                {

                    var taskPlan = new TaskPlan()
                    {
                        PlanDate = planDate,
                        TaskId = taskId,
                        Enabled = true,
                        CreatorSid = creatorSid,
                        DateCreate = DateTime.Now
                    };
                    taskPlanList.Add(taskPlan);
                }

                //taskPlanList = taskIds.Select(delegate(int taskId)
                //{
                    

                    
                //    return new TaskPlan()
                //    {
                //        PlanDate = planDate,
                //        TaskId = taskId,
                //        Enabled = true,
                //        CreatorSid = creatorSid,
                //        DateCreate = DateTime.Now
                //    };
                //}).ToList();
            }
            if (checkpointIds != null && checkpointIds.Any())
            {
                taskPlanList.AddRange(checkpointIds.Select(checkpointId => new TaskPlan()
                {
                    PlanDate = planDate,
                    TaskId = TaskCheckpoint.Get(checkpointId).TaskId,
                    TaskCheckpointId = checkpointId,
                    Enabled = true,
                    CreatorSid = creatorSid,
                    DateCreate = DateTime.Now
                }));
            }


            db.TaskPlans.AddRange(taskPlanList);
            await db.SaveChangesAsync();
        }