private void UpdateModel() { IsLoadingAnim(true); using (IDatabaseContext context = DatabaseManager.CreateContext()) { if (!IsStatic && Guild != null) { //Если не статическое, получаем рандомного дигимона из базы данных Brush MedalColor = null; Digimon d = null; Tamer tamer = null; if (TamerName != null) { if (!string.IsNullOrEmpty(TamerName.Trim())) { tamer = context.FindTamerByGuildAndName(Guild, TamerName.Trim()); } } if (tamer != null) { d = context.FindRandomDigimon(tamer, MIN_LVL); } if (d == null) { d = context.FindRandomDigimon(Guild, MIN_LVL); } if (d == null) { // если у нас нет вообще такого дигимона, тогда переключаемся на статику IsStatic = true; UpdateModel(); return; } //Устанавливаем медали в зависимости от уровня if (d.Level < 75) { MedalColor = medalBronze; } else if (d.Level >= 75 && d.Level < 80) { MedalColor = medalSilver; } else if (d.Level >= 80) { MedalColor = medalGold; } this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new UpdateInfo((DType_, Level_, TName_, TLevel_, Image_, Medal_) => { RotationElement vmodel = null; if (this.Content != null && !this.Content.GetType().IsAssignableFrom(typeof(HaguruLoader))) { vmodel = tempRotationElement; tempRotationElement = (RotationElement)this.Content; } if (vmodel == null) { vmodel = new RotationElement(); } vmodel.DType = DType_; vmodel.Level = Level_; vmodel.TName = string.Format(TAMER_NAME_FORMAT, LanguageManager.Model.RotationTamer, TName_, TLevel_); vmodel.TLevel = TLevel_; vmodel.Image = Image_; vmodel.Medal = Medal_; vmodel.ShowInfo = true; this.Content = vmodel; }), d.Name, d.Level, d.Tamer.Name, d.Tamer.Level, GetDigimonImage(d.Type.Code), MedalColor); } else { DigimonType dType = context.FindRandomDigimonType(); this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new UpdateInfo((DType_, Level_, TName_, TLevel_, Image_, Medal_) => { RotationElement vmodel = null; if (this.Content != null && !this.Content.GetType().IsAssignableFrom(typeof(HaguruLoader))) { vmodel = tempRotationElement; tempRotationElement = (RotationElement)this.Content; } if (vmodel == null) { vmodel = new RotationElement(); } vmodel.Image = Image_; vmodel.ShowInfo = false; this.Content = vmodel; }), string.Empty, 0, string.Empty, 0, GetDigimonImage(dType.Code), null); } } IsLoadingAnim(false); }
private void UpdateModel() { IsLoadingAnim(true); using (IDatabaseContext context = DatabaseManager.CreateContext()) { if (!IsStatic && Guild != null) { //Если не статическое, получаем рандомного дигимона из базы данных Brush MedalColor = null; Digimon d = null; Tamer tamer = null; if (TamerName != null) { if (!string.IsNullOrEmpty(TamerName.Trim())) { tamer = context.FindTamerByGuildAndName(Guild, TamerName.Trim()); } } if (tamer != null) { d = context.FindRandomDigimon(tamer, MIN_LVL); } if (d == null) { d = context.FindRandomDigimon(Guild, MIN_LVL); } if (d == null) { // если у нас нет вообще такого дигимона, тогда переключаемся на статику IsStatic = true; UpdateModel(); return; } //Устанавливаем медали в зависимости от уровня if (d.Level < 75) { MedalColor = medalBronze; } else if (d.Level >= 75 && d.Level < 80) { MedalColor = medalSilver; } else if (d.Level >= 80) { MedalColor = medalGold; } this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new UpdateInfo((DType_, Level_, TName_, TLevel_, Image_, Medal_) => { RotationElement vmodel = null; if (this.Content != null && !this.Content.GetType().IsAssignableFrom(typeof(HaguruLoader))) { vmodel = tempRotationElement; tempRotationElement = (RotationElement)this.Content; } if (vmodel == null) { vmodel = new RotationElement(); } vmodel.DType = DType_; vmodel.Level = Level_; vmodel.TName = string.Format(TAMER_NAME_FORMAT, LanguageManager.Model.RotationTamer, TName_, TLevel_); vmodel.TLevel = TLevel_; vmodel.Image = Image_; vmodel.Medal = Medal_; vmodel.ShowInfo = true; this.Content = vmodel; }), d.Name, d.Level, d.Tamer.Name, d.Tamer.Level, GetDigimonImage(d.Type.Code), MedalColor); } else { DigimonType dType = context.FindRandomDigimonType(); this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new UpdateInfo((DType_, Level_, TName_, TLevel_, Image_, Medal_) => { RotationElement vmodel = null; if (this.Content != null && !this.Content.GetType().IsAssignableFrom(typeof(HaguruLoader))) { vmodel = tempRotationElement; tempRotationElement = (RotationElement)this.Content; } if (vmodel == null) { vmodel = new RotationElement(); } vmodel.Image = Image_; vmodel.ShowInfo = false; this.Content = vmodel; }), string.Empty, 0, string.Empty, 0, GetDigimonImage(dType.Code), null); } } IsLoadingAnim(false); }