/// <summary> /// NOT creates new pattern itself /// Add new test objects /// </summary> private CRUDResult _AddTests(CRUDPattern data) { try { var patternEV = new Entity_View <Pattern, PatternView>() { View = data.Pattern, Entity = _cx.Patterns.Find(data.Pattern.Id) }; var questionsEV = _AddToDatabase <Question, QuestionView, Pattern, PatternView> (data.Tests.Questions.Select(x => x.Question).ToList(), _GetIdProperties <QuestionView>(), new List <Entity_View <Pattern, PatternView> >() { patternEV }); var answerView = new List <AnswerView>(); foreach (var item in data.Tests.Questions) { answerView.AddRange(item.Variants); } var answersEV = _AddToDatabase <Answer, AnswerView, Question, QuestionView> (answerView, _GetIdProperties <AnswerView>(), questionsEV); } catch (Exception e) { return(new CRUDResult() { IsSuccess = false, Message = e.Message }); } return(new CRUDResult() { IsSuccess = true, Message = "OK", Pattern = Mapper.Map <Pattern, PatternView> (_cx.Patterns.Where(x => x.Name == data.Pattern.Name).Single()) }); }
/// <summary> /// NOT creates new pattern itself /// Adds new diagram objects /// </summary> private CRUDResult _AddDiagram(CRUDPattern data, Entity_View <Pattern, PatternView> patternEV) { try { //var patternEV = new Entity_View<Pattern, PatternView>() //{ // View = data.Pattern, // Entity = _cx.Patterns.Find(data.Pattern.Id) //}; var subjectsEV = _AddToDatabase <Subject, SubjectView, Pattern, PatternView> (data.Diagram.Subjects, _GetIdProperties <SubjectView>(), new List <Entity_View <Pattern, PatternView> >() { patternEV }).ToList(); subjectsEV.AddRange(_GetBasic()); var referencesEV = _AddToDatabase <SubjectReference, SubjectReferenceView, Subject, SubjectView> (data.Diagram.SubjectReferences, _GetIdProperties <SubjectReferenceView>(), subjectsEV); var propertiesEV = _AddToDatabase <SubjectProperty, SubjectPropertyView, Subject, SubjectView> (data.Diagram.SubjectProperties, _GetIdProperties <SubjectPropertyView>(), subjectsEV); var methodsEV = _AddToDatabase <SubjectMethod, SubjectMethodView, Subject, SubjectView> (data.Diagram.SubjectMethods, _GetIdProperties <SubjectMethodView>(), subjectsEV); //------parameters set property "type_id"--------------- var paramProperties = _GetIdProperties <MethodParameterView>().ToList(); var subjectProperty = paramProperties.Where(x => x.Name == "type_id").ToList(); foreach (var item in data.Diagram.MethodParameters) { _SetIds(item, subjectProperty, subjectsEV); } var methodProperty = paramProperties.Where(x => x.Name == "method_id").ToList(); //----------------------------------------------------- var parametersEV = _AddToDatabase <MethodParameter, MethodParameterView, SubjectMethod, SubjectMethodView> (data.Diagram.MethodParameters, methodProperty, methodsEV); _cx.SaveChanges(); } catch (Exception e) { return(new CRUDResult() { IsSuccess = false, Message = e.Message }); } return(new CRUDResult() { IsSuccess = true, Message = "OK", Pattern = Mapper.Map <Pattern, PatternView> (_cx.Patterns.Where(x => x.Name == data.Pattern.Name).Single()) }); }