public void CompleteResponse(ResponseVM response) { if (!response.IsTypeChoices) { return; } CodeSchemeVM codeScheme = response.CodeScheme; if (!codeForm.CodeSchemes.Contains(codeScheme)) { //If newly added in the question window //Set the title(if the code is not added and the title of response is blank, "Untitled" or "Unnamed" title will be set by adding null codeScheme.Title = string.IsNullOrEmpty(response.Title) ? CodeVM.JoinLabels(codeScheme.Codes) : response.Title; //Add CodeScheme codeForm.CodeSchemes.Add(codeScheme); } List <CodeVM> orphanCodes = new List <CodeVM>(); foreach (CodeVM code in codeScheme.Codes) { if (!categoryForm.Contains(code.CategoryId)) { //remember the code isolated if the category scheme corresponding to the question does not exist orphanCodes.Add(code); } } if (orphanCodes.Count > 0) { //isolated code(Category is not included in the existent category set) //Create Category scheme and then add Category in it CategorySchemeVM categoryScheme = categoryForm.FindCategorySchemeByResponseId(response.Id); if (categoryScheme == null) { categoryScheme = new CategorySchemeVM(); categoryScheme.ResponseId = response.Id; categoryScheme.Title = string.IsNullOrEmpty(response.Title) ? CodeVM.JoinLabels(orphanCodes) : response.Title; //Create from isolated code categoryForm.CategorySchemes.Add(categoryScheme); } //Add Category here(since categories are not added automatically, while the code is added automatically) foreach (CodeVM code in orphanCodes) { //Add CategoryVM included in CodeVM to CategoryScheme categoryScheme.Categories.Add(code.Category); } } }
public bool IsBinaryCategoryScheme(CategorySchemeVM categoryScheme) { return(studyUnit.BinaryCategorySchemeId == categoryScheme.Id); }