public static Result <QuestionDraft> Create( ObjectId questionId, ObjectId draftId, string text, int level, int duration, List <Concept> concepts, List <Answer> answers, ObjectId moduleId, ObjectId subjectId ) { var newObject = new QuestionDraft() { Id = ObjectId.GenerateNewId(), QuestionId = questionId, Text = text, Level = level, Duration = duration, SubjectId = subjectId, ModuleId = moduleId, CreatedAt = DateTimeOffset.UtcNow, Answers = new List <Answer>(), Concepts = new List <Concept>(), DraftId = draftId, DraftPublished = false, DraftPlubishedAt = DateTimeOffset.MinValue }; newObject.Concepts = concepts; newObject.Answers = answers; return(Result.Ok(newObject)); }
public static Result <QuestionDraft> Create( ObjectId questionId, ObjectId draftId, string text, int level, int duration, string[] concepts, List <Answer> answers, ObjectId moduleId, ObjectId subjectId ) { var newObject = new QuestionDraft() { Id = ObjectId.GenerateNewId(), QuestionId = questionId, Text = text, Level = level, Duration = duration, SubjectId = subjectId, ModuleId = moduleId, CreatedAt = DateTimeOffset.UtcNow, Answers = new List <Answer>(), Concepts = new List <Concept>(), DraftId = draftId, DraftPublished = false, DraftPlubishedAt = DateTimeOffset.MinValue }; var resultList = concepts.Select(Concept.Create).ToArray(); var results = Result.Combine(resultList); if (results.IsFailure) { return(Result.Fail <QuestionDraft>(results.Error)); } newObject.Concepts = resultList.Select(x => x.Data).ToList(); var outOfOrderConcepts = answers.SelectMany(x => x.Concepts).Where(x => !concepts.Contains(x.Concept)); if (outOfOrderConcepts.Any()) { return(Result.Fail <QuestionDraft>( "Existem conceitos presentes nas respostas que não estão contidos na pergunta")); } newObject.Answers = answers; return(Result.Ok(newObject)); }