public ChatGroup Updateobject(int id, ChatGroup filled) { ChatGroup obj = _context.ChatGroups.Find(id); PropertyInfo[] props = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo prop in props) { object currentprop = prop.GetValue(filled); if (currentprop is Int32) { int currentint = (int)currentprop; if (currentint == 0) { prop.SetValue(filled, prop.GetValue(obj), null); } } else if (currentprop is Int16) { Int16 currentInt16 = (Int16)currentprop; if (currentInt16 == 0) { prop.SetValue(filled, prop.GetValue(obj), null); } } else if (currentprop is Byte) { Byte currentByte = (Byte)currentprop; if (currentByte == 0) { prop.SetValue(filled, prop.GetValue(obj), null); } } else if (currentprop is Boolean) { Boolean currentBoolean = (Boolean)currentprop; if (currentBoolean == (Boolean)prop.GetValue(obj)) { prop.SetValue(filled, prop.GetValue(obj), null); } } else if (currentprop is String) { prop.SetValue(filled, (String)currentprop, null); } else if (currentprop is DateTime) { DateTime currentDateTime = (DateTime)currentprop; if (currentDateTime == new DateTime()) { prop.SetValue(filled, prop.GetValue(obj), null); } } else { if (currentprop == null) { prop.SetValue(filled, prop.GetValue(obj), null); } } } return(filled); }