//Update public Chore UpdateChore(int Id, Chore NewChore) { try { var OldChore = db.Chores.SingleOrDefault(x => x.Id == Id); //iterate through all properties //except Id //and except sort order foreach (var property in NewChore .GetType() .GetProperties() .Where(x => x.Name != "Id" && x.Name != "SortOrder")) { //get the value of the iterated property var value = property.GetValue(NewChore); if (value != null) { Type type = NewChore.GetType(); PropertyInfo propertyInfo = type.GetProperty(property.Name); propertyInfo.SetValue(OldChore, value, null); } } db.SaveChanges(); return(OldChore); } catch (Exception ex) { throw Utility.ThrowException(ex); } }
public void SetChore(Chore.Precondition.Context context) { Chore currentChore = base.smi.GetCurrentChore(); if (currentChore != context.chore) { StopChore(); if (context.chore.IsValid()) { context.chore.PrepareChore(ref context); this.context = context; base.smi.sm.nextChore.Set(context.chore, base.smi); } else { string text = "Null"; string text2 = "Null"; if (currentChore != null) { text = currentChore.GetType().Name; } if (context.chore != null) { text2 = context.chore.GetType().Name; } string obj = "Stopping chore " + text + " to start " + text2 + " but stopping the first chore cancelled the second one."; Debug.LogWarning(obj); } } }
public override string Order(Chore chore) { return(this.GetType().Name + " forbid the " + chore.GetType().Name); }