Exemplo n.º 1
0
        public async Task AddAsync(KnowledgesModel model)
        {
            var knowledge = KnowledgeToKnowledgeModel.ToKnowledge(model);

            List <Question> qr = new List <Question>();
            List <Answer>   ar;

            foreach (var i in knowledge.Questions)
            {
                ar = new List <Answer>();
                foreach (var j in i.Answers)
                {
                    ar.Add(new Answer {
                        AnswerString = j.AnswerString, CorrectAnswer = j.CorrectAnswer
                    });
                }

                qr.Add(new Question {
                    QuestionString = i.QuestionString, Answers = ar
                });
            }

            await UnitOfWork.KnowledgeRepository.AddAsync(new Knowledge { KnowledgeName = knowledge.KnowledgeName, Questions = qr });

            await UnitOfWork.SaveAsync();
        }
Exemplo n.º 2
0
        public async Task UpdateAsync(KnowledgesModel model)
        {
            var knowledge = KnowledgeToKnowledgeModel.ToKnowledge(model);
            var questions = Mapper.Map <IEnumerable <QuestionsModel>, List <Question> >(model.Questions.ToList());

            foreach (var i in questions)
            {
                foreach (var j in i.Answers)
                {
                    await Task.Run(() => UnitOfWork.AnswersRepository.Update(j));
                }
                await Task.Run(() => UnitOfWork.QuestionRepository.Update(i));
            }

            UnitOfWork.KnowledgeRepository.Update(knowledge);
            await UnitOfWork.SaveAsync();

            /*
             * return Task.Run(() => {
             *  UnitOfWork.KnowledgeRepository.Update(book);
             *  UnitOfWork.SaveAsync();
             * });*/
        }