public CrmResponse AddNewJbi(ENTITIES.JBI jbi) { CrmResponse response = new CrmResponse(); try { JBI newJbi = new JBI(); Type myType = newJbi.GetType(); PropertyInfo[] props = myType.GetProperties(); foreach (PropertyInfo prop in props) { object jbiValue = jbi.GetType().GetProperty(prop.Name).GetValue(jbi); newJbi.GetType().GetProperty(prop.Name).SetValue(newJbi, jbiValue); } _context.JBIs.Add(newJbi); _context.SaveChanges(); jbi.Moneln = _context.JBIs.Max().Moneln; } catch (Exception ex) { var message = ex.Message; response.desc = ex.Message; } return(response); }
public CrmResponse UpdateJBI(ENTITIES.JBI jbi) { CrmResponse response = new CrmResponse(); try { JBI updatedRow = _context.JBIs.Where((x) => x.Moneln == jbi.Moneln).FirstOrDefault(); if (updatedRow != null) { Type myType = updatedRow.GetType(); PropertyInfo[] props = myType.GetProperties(); foreach (PropertyInfo prop in props) { //object oneKey = prop.Name; //object onevalue = prop.GetValue(updatedRow, new object[] { }); object jbiValue = jbi.GetType().GetProperty(prop.Name).GetValue(jbi); updatedRow.GetType().GetProperty(prop.Name).SetValue(updatedRow, jbiValue); } _context.SaveChanges(); } else { response.rc = 1; response.title = "Id is not found"; } } catch (Exception ex) { var message = ex.Message; response.desc = ex.Message; } return(response); }