public ActionResult ProphecyForm(List <Prophecy> newList) { if (ModelState.IsValid) { // Get existing Conclave using (ISession _S = MvcApplication.SF.GetCurrentSession()) { Prophecy phy = null; var oldList = _S.QueryOver(() => phy) .SelectList(l => l .Select(x => x.Tippk).WithAlias(() => phy.Tippk) ) .TransformUsing(Transformers.AliasToBean <Prophecy>()) .List <Prophecy>(); foreach (var q in newList) { //updates if (oldList.Any(p => p.Tippk == q.Tippk)) { var persistentType = _S.Load <Prophecy>(q.Tippk); persistentType.Tipid = q.Tipid; persistentType.Text = q.Text; persistentType.Conclave = q.Conclave; persistentType.Customflg = q.Customflg; _S.Save(persistentType); _S.Flush(); _S.Clear(); } //inserts else if (q.Tippk == -1) { var persistentType = new Prophecy(); persistentType.Tipid = q.Tipid; persistentType.Text = q.Text; persistentType.Conclave = q.Conclave; persistentType.Customflg = q.Customflg; _S.Save(persistentType); _S.Flush(); _S.Clear(); } } //deletions foreach (var x in oldList) { if (!newList.Any(p => p.Tippk == x.Tippk)) { var persistentType = _S.Load <Prophecy>(x.Tippk); _S.Delete(persistentType); _S.Flush(); _S.Clear(); } } } ViewBag.onSuccess_Message = "Tips updated successfully."; return(View("Index")); } else { return(View("Index")); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Gear gear = value as Gear; double opacity = 1; if (parameter != null) { opacity = double.Parse(parameter.ToString(), CultureInfo.InvariantCulture); } if (gear != null) { switch (gear.Rarity) { case Rarity.Normal: return(new SolidColorBrush(NormalItemColor) { Opacity = opacity }); case Rarity.Magic: return(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8888F1")) { Opacity = opacity }); case Rarity.Rare: return(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F1FF77")) { Opacity = opacity }); case Rarity.Unique: return(new SolidColorBrush(Colors.Orange) { Opacity = opacity }); } } Currency currency = value as Currency; if (currency != null) { return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFDF8E")) { Opacity = opacity } } ; Gem gem = value as Gem; if (gem != null) { return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1BA29B")) { Opacity = opacity } } ; Map map = value as Map; if (map != null) { return new SolidColorBrush(Colors.PaleGreen) { Opacity = opacity } } ; Prophecy prophecy = value as Prophecy; if (prophecy != null) { return new SolidColorBrush(Colors.Purple) { Opacity = 1 } } ; //This was throwing an exception and killing the application - this is not ideal - I will default to normal item color when handle=ing new types return(new SolidColorBrush(NormalItemColor) { Opacity = opacity }); }