95 lines
3.3 KiB
C#
95 lines
3.3 KiB
C#
using Datamodels.BusinessModels;
|
|
using Datamodels.DatabaseModels;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using Repositories.Interfaces;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Linq;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Datamodels.SearchModels;
|
|
using System.Linq.Expressions;
|
|
using System.Diagnostics;
|
|
|
|
namespace Repositories
|
|
{
|
|
public class FwMariaSearchRepo : IFwMariaSearchRepo
|
|
{
|
|
private readonly FwDbContext _dbContext = new FwDbContext();
|
|
private readonly ILogger<FwMariaSearchRepo> _logger;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public FwMariaSearchRepo(ILogger<FwMariaSearchRepo> logger, IConfiguration configuration)
|
|
{
|
|
_logger = logger;
|
|
_configuration = configuration;
|
|
try
|
|
{
|
|
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
|
|
{
|
|
_dbContext._connectionString = "SERVER=127.0.0.1;DATABASE=testdb;PORT=3306;USER=root;PASSWORD=example";
|
|
}
|
|
else
|
|
{
|
|
string usedDb = configuration.GetSection("GeneralSettings").GetSection("DbToUse").Get<string>();
|
|
string connectionString = configuration.GetConnectionString(usedDb);
|
|
_dbContext._connectionString = connectionString;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Database Connection Configuration not valid");
|
|
}
|
|
}
|
|
|
|
public async Task<DataResult<List<Address>>> GetAllAddresses()
|
|
{
|
|
try
|
|
{
|
|
var result = await _dbContext.Address.Where(x => x.City == "Augsburg" || x.City == "München").Where(y => y.StreetName.Contains("bruck")).ToListAsync().ConfigureAwait(false);
|
|
return new DataResult<List<Address>> { Data = result };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new DataResult<List<Address>>
|
|
{
|
|
GeneralResult = GeneralResults.DatabaseError,
|
|
UserMessage = "Fehler beim Laden der Adressen",
|
|
ServerMessage = ex.Message
|
|
};
|
|
}
|
|
}
|
|
|
|
public Task<object> GetAllSortedData(TableModel queryFieldDef, List<SortModel> sortModel)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<string> GetBlobData(string tableName, string fieldName, long id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<object> GetDataFilteredAndSorted(List<FilterModel> filter, List<SortModel> sortModel, long skip = 0, long take = -1)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<DataResult<List<IEntityClass>>> GetFilteredData<T>(List<Expression> expressions, long skip = 0, long take = -1) where T : IEntityClass
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
public class FilterLinq<T>
|
|
{
|
|
public static Expression<Func<T, Boolean>> GetWherePredicate(string whereFieldList, string whereFieldValues)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|