public bool Save(T entity) { try { string sql = Persist.Insert(entity); using (IDbCommand command = CreateCommand(sql)) { if (command.ExecuteNonQuery() > 0) { if (!string.IsNullOrEmpty(Query.EntityMap.PrimaryKeyName)) { if (Query.EntityMap.IsAutoincrement) { command.CommandText = "SELECT LAST_INSERT_ID() AS Id;"; string res = command.ExecuteScalar() + ""; int id = int.Parse(res); PropertyInfo property = Query.EntityMap.Type.GetProperty(Query.EntityMap.PrimaryKeyName); property.SetValue(entity, DataFormater.ParseToData(property, id)); } } command.Dispose(); return(true); } else { command.Dispose(); return(false); } } } catch { throw; } }
public UserProfile Create(UserProfile profile) { try { _dac.Insert(profile); } catch (Exception err) { throw new Exception(Errors.ERR_PROFILEM_BADREQUEST, err); } return(profile); }
public Entity Create(Entity entity) { try { if (entity.isValid()) { _persist.Insert(entity); } else { throw new Exception(Error.ERR_REFM_ENTITY_NOT_VALID); } } catch (Exception err) { throw new Exception(Error.ERR_REFM_BADREQUEST, err); } return(entity); }