public async Task <bool> Change([NotNull] TEntity model) { var method = new StackTrace().GetCurrentMethod(); try { _prnt.ModelState.AddModelError(method, string.Empty); if (_prnt.ModelState.IsValid) { var oldItem = await Get(model.Id); if (!ObjectHelper.Compare(oldItem, model, "Id")) { _prnt.DbContext.Entry(oldItem).CurrentValues.SetValues(model); await _prnt.DbContext.SaveChangesAsync(); } _prnt.ModelState.Remove(method); return(true); } } catch (DbUpdateException ex) { Debug.WriteLine(ex.StackTrace); } return(false); }
public void TestCompareMethod() { TestItem1 = new testClass1(1, 2, 3); TestItem2 = new testClass1(1, 2, 3); TestItem3 = new testClass2(4, 5, 6); TestItem4 = new testClass2(4, 5, 6); Assert.IsNotNull(ObjectHelper.Compare(TestItem1, TestItem2)); Assert.IsNotNull(ObjectHelper.Compare(TestItem3, TestItem4)); Assert.IsNull(ObjectHelper.Compare(TestItem1, TestItem4)); Assert.IsNull(ObjectHelper.Compare(TestItem2, TestItem3)); }