private int SaveTestData(LusherTestResult result, int userId) { var lusherTest = new LusherTestEntity { CreateDate = DateTime.UtcNow, Intensity = result.Intensity, LusherChoices = result.ColorSet.Select((set, setIndex) => new LusherChoiceEntity { ChoiceNumber = setIndex, LusherChoices = set.Select((color, index) => new LusherChoiceColorEntity { Color = color.Color, Group = color.Group.ToString(), Anxiety = color.Anxiety, Intensity = color.Intensity, Position = index }) .ToList() }) .ToList(), LusherResults = result.Groups.Select((resultGroup, groupIndex) => new LusherResultEntity { FirstColor = resultGroup.FirstColor, SecondColor = resultGroup.SecondColor, Group = resultGroup.SecondGroup.ToString(), Anxiety = resultGroup.SecondAnxiety, Position = groupIndex, LusherInterpretationId = GetInterpretationKey(resultGroup) }) .ToList() }; var entity = new TestEntity { CreateDate = DateTime.UtcNow, TestType = TestType.Lusher.ToString(), UserId = userId, LusherTest = lusherTest }; _testRepository.SaveTest(entity); return(lusherTest.LusherTestId); }
private static LusherTestResult ResultsPreparation(LusherTest test) { var result = new LusherTestResult() { Intensity = test.FirstChoice.Sum(item => item.Intensity) + test.SecondChoice.Sum(item => item.Intensity), ColorSet = new List <List <LusherChoice> > { test.FirstChoice, test.SecondChoice }, Groups = new List <LusherResultGroup>() }; var groups = new List <LusherResultGroup>(); for (var i = 0; i < test.FirstChoice.Count; i++) { groups.Add(new LusherResultGroup { FirstColor = test.FirstChoice[i].Color, SecondAnxiety = test.SecondChoice[i].Anxiety, SecondGroup = test.SecondChoice[i].Group, SecondColor = test.SecondChoice[i].Color, Position = i }); } LusherResultGroup previousLusherResultGroup = null; foreach (var lusherResultGroup in groups) { if (!(previousLusherResultGroup != null && lusherResultGroup.FirstColor == previousLusherResultGroup.SecondColor && lusherResultGroup.SecondColor == previousLusherResultGroup.FirstColor)) { result.Groups.Add(lusherResultGroup); } previousLusherResultGroup = lusherResultGroup; } return(result); }