public static bool Insert(SpellVM Spelling) { if (Spellings.Any(s => s.Text == Spelling.Text)) { var old_Spell = Spellings.First(s => s.Text == Spelling.Text); var old_score = ScoreHelper.GetScoreFromImportance(old_Spell.Importance); var new_score = ScoreHelper.GetScoreFromImportance(Spelling.Importance); if (new_score > old_score) { var to_update = new SpellVM(old_Spell.Id, old_Spell.Text, Spelling.Importance, old_Spell.IsActive); return(Update(to_update)); } else { return(Errors.ThrowErrorMsg(ErrorType.AlreadyInserted, Spelling.Text)); } } if (!ValidWordsAndAnswerSize(Spelling.Text)) { return(false); } if (!InsertSpelling(Spelling.ToModel())) { return(false); } Spelling.LoadCrossData(); return(true); }
public static bool Update(SpellVM Spelling) { if (!ValidWordsAndAnswerSize(Spelling.Text)) { return(false); } if (!UpdateSpelling(Spelling.ToModel())) { return(false); } var oldVM = Spellings.FindIndex(x => x.Id == Spelling.Id); Spellings.Insert(oldVM, Spelling); return(true); }