Пример #1
0
        public async Task Clone(Exam item)
        {
            var newItem = new Exam
            {
                Id              = 0,
                Active          = true,
                DurationMinutes = item.DurationMinutes,
                Login           = item.Login,
                MaxStart        = item.MaxStart,
                MinStart        = item.MinStart,
                Name            = $"{item.Name} ({DateTime.Now})",
                Questions       = null,
                Users           = null
            };

            newItem.Code = await GetNewGiud();

            var examId = await ExamRepo.AddAsync(newItem);

            foreach (var q in item.Questions)
            {
                var answers = q.Answers;
                q.ExamId  = examId;
                q.Id      = 0;
                q.Answers = null;
                var qId = await QuestionRepo.AddAsync(q);

                foreach (var a in answers)
                {
                    a.QuestionId = qId;
                    a.Id         = 0;
                    await AnswersRepo.AddAsync(a);
                }
            }
            await ExamRepo.SaveChangesAsync();
        }