isList handling
This commit is contained in:
20
DbService.cs
20
DbService.cs
@ -15,6 +15,7 @@ namespace de.hottis.genericdatabaseapiservice.Services {
|
||||
|
||||
public class DbServiceException : Exception {}
|
||||
public class NotDataFoundException : DbServiceException {}
|
||||
public class TooMuchDataFoundException : DbServiceException {}
|
||||
|
||||
public class DbService : IDbService {
|
||||
private readonly IConfiguration Configuration;
|
||||
@ -30,7 +31,7 @@ namespace de.hottis.genericdatabaseapiservice.Services {
|
||||
Configuration["Database:Name"]);
|
||||
}
|
||||
|
||||
async public Task<List<TOUT>> ReadBySelect<TIN, TOUT>(string selectStatement, TIN input) {
|
||||
async public Task<List<TOUT>> ReadBySelect<TIN, TOUT>(string selectStatement, bool justOne, TIN input) {
|
||||
var itemList = new List<TOUT>();
|
||||
|
||||
Console.WriteLine("ConnInfo: {0}", databaseConnInfo);
|
||||
@ -63,14 +64,12 @@ namespace de.hottis.genericdatabaseapiservice.Services {
|
||||
var dma = (DataMemberAttribute)attributes[0];
|
||||
int ordinal = reader.GetOrdinal(dma.Name);
|
||||
Console.WriteLine("Output DataMember name: {0} {1} {2} ", dma.Name, dma.TypeId, ordinal);
|
||||
if (propertyInfo.PropertyType == typeof(System.String)) {
|
||||
if (reader.IsDBNull(ordinal)) {
|
||||
propertyInfo.SetValue(item, null);
|
||||
Console.WriteLine("Output Value: null");
|
||||
} else {
|
||||
propertyInfo.SetValue(item, reader.GetString(ordinal));
|
||||
Console.WriteLine("Output Value:{0}", reader.GetString(ordinal));
|
||||
}
|
||||
if (reader.IsDBNull(ordinal)) {
|
||||
propertyInfo.SetValue(item, null);
|
||||
Console.WriteLine("Output Value: null");
|
||||
} else if (propertyInfo.PropertyType == typeof(System.String)) {
|
||||
propertyInfo.SetValue(item, reader.GetString(ordinal));
|
||||
Console.WriteLine("Output Value:{0}", reader.GetString(ordinal));
|
||||
} else if (propertyInfo.PropertyType == typeof(System.Int32)) {
|
||||
propertyInfo.SetValue(item, reader.GetInt32(ordinal));
|
||||
Console.WriteLine("Output Value:{0}", reader.GetInt32(ordinal));
|
||||
@ -85,6 +84,9 @@ namespace de.hottis.genericdatabaseapiservice.Services {
|
||||
if (itemList.Count == 0) {
|
||||
throw new NotDataFoundException();
|
||||
}
|
||||
if (justOne && itemList.Count > 1) {
|
||||
throw new TooMuchDataFoundException();
|
||||
}
|
||||
|
||||
return itemList;
|
||||
}
|
||||
|
Reference in New Issue
Block a user