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);
        }
Пример #2
0
        public static void AddIntoThis(SpellVM Spell, StackPanel item_line)
        {
            var row1 = MyGrids.GetRowItem(new List <int>()
            {
                4, 4, 2, 2, 2, 2, 2, 3, 1, 1, 1
            }, item_line);

            var row3 = new StackPanel();

            row3.Margin = new Thickness(1, 2, 1, 2);
            item_line.Children.Add(row3);

            var wpf = new SpellWpfItem();

            MyTxts.Get(wpf.Words, 0, 0, row1, Spell.Text);
            wpf.Words.ToolTip = "Id " + Spell.Id;
            MyCbBxs.Importance(wpf.Imp, 0, 1, row1, Spell.Importance, false);

            MyLbls.AvgScore(wpf.Avg_w, 0, 2, row1, Spell, 7);
            MyLbls.AvgScore(wpf.Avg_m, 0, 3, row1, Spell, 30);
            MyLbls.AvgScore(wpf.Avg_all, 0, 4, row1, Spell, 2000);
            MyLbls.Tries(wpf.Tries, 0, 5, row1, Spell);
            MyLbls.LastTry(wpf.Last_try, 0, 6, row1, Spell);
            MyLbls.Chance(wpf.Chance, 0, 7, row1, Spell);

            MyBtns.Is_active(wpf.IsActive, 0, 8, row1, Spell.IsActive);
            MyBtns.Quest_Edit(wpf.Edit, 0, 9, row1, Spell, wpf, item_line);
            MyBtns.Remove_quest(wpf.Remove, 0, 10, row1, Spell, item_line);
        }
        public static bool Remove(SpellVM Spelling)
        {
            if (!RemoveSpelling(Spelling))
            {
                return(false);
            }

            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);
        }
Пример #5
0
        public static void AddIntoItems(StackPanel stack_items, SpellVM Spell, bool isNew)
        {
            var item_line = MyStacks.GetItemLine(stack_items, isNew);

            AddIntoThis(Spell, item_line);
        }