Example #1
0
        /// <summary>
        /// Проверить номер джампера на корректность
        /// </summary>
        /// <param name="number">Номер джампера</param>
        /// <returns></returns>
        public (bool status, string reason) CheckJumperNumber(int?number)
        {
            if (number == null)
            {
                return(false, "недопустимый номер");
            }

            if (Jumpers.Any(j => j.Number == number))
            {
                var dvm = new DialogViewModel("Номер уже существует, хотите ли вы поменять их местами?", DialogType.Question);

                WinMan.ShowDialog(dvm);

                switch (dvm.DialogResult)
                {
                case DialogResult.YesAction:
                    var jumper = Jumpers.First(j => j.Number == number);
                    jumper.Number = SelectedJumper.Number;
                    DbMethods.UpdateDbCollection(jumper);
                    return(true, "Операция успешно завершена");

                case DialogResult.NoAction:
                    return(false, "Данный номер уже существует");

                default:
                    return(false, "Операция отменена");
                }
            }

            return(number > Jumpers.Count
                                ? (false, "Все номера должны быть по порядку без пропусков")
                                : (true, "Операция успешно завершена"));
        }
        /// <summary>
        /// Импорт настроек опции
        /// </summary>
        public void ImportOptionData()
        {
            if (CanImportOptionData is false)
            {
                return;
            }

            using (var ctx = new CVDbContext(AppDataPath))
            {
                var option = ctx.EpisodeOptions
                             .Include(eo => eo.Jumpers)
                             .First(eo => eo.EpisodeOptionId == SelectedEpisodeOption.EpisodeOptionId);
                if (option == null)
                {
                    throw new Exception("Опция не существует");
                }

                foreach (var jumper in option.Jumpers.ToList())
                {
                    ctx.Jumpers.Remove(jumper);
                    ctx.SaveChanges();
                }


                Jumpers.Clear();
                SelectedEpisodeOption.Jumpers.Clear();

                var count = 1;
                foreach (var j in ImportingEpisodeOption.Jumpers)
                {
                    var jumper = new Jumper
                    {
                        EpisodeOptionId = SelectedEpisodeOption.EpisodeOptionId,
                        StartTime       = j.StartTime,
                        SkipCount       = j.SkipCount,
                        Number          = count++
                    };

                    option.Jumpers.Add(jumper);
                    ctx.SaveChanges();
                    jumper = ctx.Jumpers.ToList().Last();
                    Jumpers.Add(jumper);
                    SelectedEpisodeOption.Jumpers.Add(jumper);
                }

                option.CreditsStart = ImportingEpisodeOption.CreditsStart;
                SelectedEpisodeOption.CreditsStart = ImportingEpisodeOption.CreditsStart;

                option.Duration = CalculatingDuration(option);
                SelectedEpisodeOption.Duration = CalculatingDuration(option);
                SelectedJumper      = Jumpers.First();
                EditableEpisodeTime = ConvertToEpisodeTime(SelectedEpisodeOption, SelectedJumper);
                ctx.SaveChanges();

                TempEpisodeOptionSnapshot = JsonConvert.SerializeObject(SelectedEpisodeOption);
                NotifyOfPropertyChange(() => SelectedEpisodeOption);
                NotifyOfPropertyChange(() => Jumpers);
                NotifyOfPropertyChange(() => CanImportOptionData);
                NotifyEditingButtons();
                NotifyTimeProperties();
            }
        }