示例#1
0
        private async Task TratarPlanTasks(string idPlano)
        {
            var tasks = await _plannetService.RecuperarPlanTasks(idPlano);

            if (tasks.Count > 0)
            {
                foreach (var task in tasks.ToList())
                {
                    var objModel = PlannerTasks.FromModel(task);
                    objModel.PlanId = idPlano;

                    var bucket = _context.PlannerBuckets.FirstOrDefault(p => p.Id == objModel.BucketId);
                    if (bucket != null)
                    {
                        objModel.BucketName = bucket.Name;
                    }

                    var detalhes = _plannetService.RecuperarDetalheTarefaPorId(task.Id).Result;

                    if (detalhes != null)
                    {
                        if (task.HasDescription.HasValue && task.HasDescription.Value)
                        {
                            objModel.Description = detalhes.Description;
                        }
                    }

                    _context.PlannerTasks.Add(objModel);
                    _context.SaveChanges();

                    TratarAtribuicoes(task, objModel);

                    if (detalhes == null || !detalhes.Checklist.ToList().Any())
                    {
                        continue;
                    }

                    foreach (var checklist in detalhes.Checklist.ToList())
                    {
                        var checkModel = PlannerChecklistItems.FromModel(checklist.Value);
                        checkModel.Id     = checklist.Key;
                        checkModel.TaskId = task.Id;

                        if (_context.PlannerChecklistsItems.FirstOrDefault(p => p.Id == checkModel.Id) == null)
                        {
                            _context.PlannerChecklistsItems.Add(checkModel);
                            _context.SaveChanges();
                        }
                    }
                }
            }
        }