public async Task <T> GetOne(T model) { var command = new NpgsqlCommand(); T retrieved = default(T); command.CommandText = $"SELECT {ORMQueryHelper.GetSelectColumns<T>()} FROM {tableName} WHERE {String.Join("AND", WhereCriteria(model, command, DataColumnUsage.Retrieve, null))}"; await db.CommandReaderAsync(command, (reader) => { while (reader.Read()) { LoadModel(reader, retrieved); } }); return(retrieved); }
public async Task <UserModel> Exists(UserModel model) { var user = new UserModel(); var command = new NpgsqlCommand(); command.CommandText = $"SELECT {userExistColumns} FROM {userTable} WHERE username=@username OR email=@email;"; command.Parameters.AddWithValue("username", model.Username); command.Parameters.AddWithValue("email", model.Email); int ordinal = 0; await db.CommandReaderAsync(command, reader => { user.Username = reader.GetString(ordinal++); user.Email = reader.GetString(ordinal++); }); return(user); }
public async Task <ItemModel[]> SelectItemsAsync(ItemModel item) { var command = new NpgsqlCommand(); command.CommandText = $"SELECT {itemHistorySelectColumns} FROM {itemHistoryTable} WHERE itemid=@itemid AND source=@source;"; command.Parameters.AddWithValue("@itemid", item.ItemID); command.Parameters.AddWithValue("@source", item.Source); var savedSearches = new List <ItemModel>(); await db.CommandReaderAsync(command, reader => { int ordinal = 0; var savedSearch = new ItemModel(); savedSearch.ID = reader.GetInt32(ordinal++); savedSearch.ItemID = reader.GetString(ordinal++); savedSearch.Price = (decimal[])reader.GetValue(ordinal++); savedSearch.Quantity = reader.GetInt32(ordinal++); savedSearch.Seller = reader.GetString(ordinal++); savedSearch.Meta = JsonConvert.DeserializeObject <ItemModelMeta>(reader.GetString(ordinal++)); savedSearch.LotPrice = reader.GetDecimal(ordinal++); savedSearch.Currency = reader.GetString(ordinal++); savedSearch.Title = reader.GetString(ordinal++); savedSearch.Source = reader.GetString(ordinal++); savedSearch.CreatedDate = reader.GetDateTime(ordinal++); savedSearches.Add(savedSearch); }); return(savedSearches.ToArray()); }