Skip to content

Commit

Permalink
fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxi1324 committed Jun 13, 2023
1 parent a0962c3 commit 3ae6ab3
Show file tree
Hide file tree
Showing 29 changed files with 100 additions and 82 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CertificatPassword=Password1
AdminHall=AdminHall
AutomatPassword=AutomatPassword
JWTSecret=JWTSecretSecretSecretSecretSecret
3 changes: 3 additions & 0 deletions MsSqlServer/.system/instance_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a58120f0-9522-418b-901b-c6cb4f509b6e
8766624031385570547
3226
Binary file added MsSqlServer/.system/system/lsa.hiv
Binary file not shown.
Binary file added MsSqlServer/.system/system/security.hiv
Binary file not shown.
3 changes: 3 additions & 0 deletions MsSqlServer1/.system/instance_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
afb14dc6-6a4c-4041-a9e4-1b8e7ab10e87
1865148958748939607
803
Binary file added MsSqlServer1/.system/system/lsa.hiv
Binary file not shown.
Binary file added MsSqlServer1/.system/system/security.hiv.lkg
Binary file not shown.
Binary file modified ZID.Automat/src/ZID.Automat.Api/AutomatDatabase2.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Ubiety.Dns.Core;
using ZID.Automat.Application;
using ZID.Automat.Dto.Models;
using ZID.Automat.Repository;
Expand Down
36 changes: 19 additions & 17 deletions ZID.Automat/src/ZID.Automat.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@


var corsis = Environment.GetEnvironmentVariable("CorsOrigin")?.Split(";");
string[] CorsOrigins = corsis??Conf.GetSection("CorsOrigin").Get<string[]>();
string[] CorsOrigins = corsis ?? Conf.GetSection("CorsOrigin").Get<string[]>();


string JWT = Environment.GetEnvironmentVariable("JWTSecret") ?? Conf.GetSection("UserLoginConf").GetSection("JWT").GetValue<string>("JWTSecret");
Expand All @@ -60,7 +60,7 @@
{
jeint = int.Parse(je);
}
float JWTExpireTime = jeint??JWTConfSection.GetValue<int>("JWTExpireTime");
float JWTExpireTime = jeint ?? JWTConfSection.GetValue<int>("JWTExpireTime");
string JWTSecret = Environment.GetEnvironmentVariable("JWTSecret") ?? JWTConfSection.GetValue<string>("JWTSecret");

string AutomatPassword = Environment.GetEnvironmentVariable("AutomatPassword") ?? AuthConfSection.GetValue<string>("AutomatPassword");
Expand All @@ -71,43 +71,46 @@
string TestUserName = TestUserConfSection.GetValue<string>("TestUserName");
string TestUserPassword = TestUserConfSection.GetValue<string>("TestUserPassword");

string UseDb = DBSection.GetValue<string>("UseDatabase");
string UseDb = Environment.GetEnvironmentVariable("UseDatabase") ?? DBSection.GetValue<string>("UseDatabase");
string DbConnString = Environment.GetEnvironmentVariable("ConnectionString") ?? DBSection.GetSection(UseDb).GetValue<string>("ConnectionString");

var Borrow = Conf.GetSection("Borrow");

var bt =Environment.GetEnvironmentVariable("MaxBorrowTime");
var bt = Environment.GetEnvironmentVariable("MaxBorrowTime");
int? btint = null;
if (bt != null)
{
btint = int.Parse(bt);
}
int MaxBorrowTime = btint??Borrow.GetValue<int>("MaxBorrowTime");
int MaxBorrowTime = btint ?? Borrow.GetValue<int>("MaxBorrowTime");

var HttpsConf = Conf.GetSection("HttpsConf");
string CertPass = Environment.GetEnvironmentVariable("CertificatPassword")?? HttpsConf.GetValue<string>("CertificatPassword");
string CertPass = Environment.GetEnvironmentVariable("CertificatPassword") ?? HttpsConf.GetValue<string>("CertificatPassword");
string CertPath = Environment.GetEnvironmentVariable("CertificatPath") ?? HttpsConf.GetValue<string>("CertificatPath");

Console.WriteLine($"database {UseDb}");


#endregion
/*
var httpsConnectionAdapterOptions = new HttpsConnectionAdapterOptions

if (bool.Parse(Environment.GetEnvironmentVariable("UseSSL") ?? "false"))
{

var httpsConnectionAdapterOptions = new HttpsConnectionAdapterOptions
{
SslProtocols = System.Security.Authentication.SslProtocols.Tls12,
ClientCertificateMode = ClientCertificateMode.AllowCertificate,
ServerCertificate = new X509Certificate2(CertPath, CertPass)

};*/
/* builder.WebHost.ConfigureKestrel(options =>
};
builder.WebHost.ConfigureKestrel(options =>
{
options.ConfigureEndpointDefaults(list =>
{
list.UseHttps(httpsConnectionAdapterOptions);
});
});
*/
}
#region ASPIntern
builder.Services.AddControllers((register) =>
{
Expand Down Expand Up @@ -160,7 +163,7 @@

#region Configuration
builder.Services.AddSingleton(new JWTCo() { JWTExpireTime = JWTExpireTime, JWTSecret = JWTSecret });
builder.Services.AddSingleton(new TestUserCo() {UseDebug = UseDebug, TestUserName = TestUserName, TestUserPassword = TestUserPassword});
builder.Services.AddSingleton(new TestUserCo() { UseDebug = UseDebug, TestUserName = TestUserName, TestUserPassword = TestUserPassword });
builder.Services.AddSingleton(new BorrowCo() { MaxBorrowTime = MaxBorrowTime });
builder.Services.AddSingleton(new AutomatCo() { Password = AutomatPassword });
builder.Services.AddSingleton(new AdminCo() { Hall = AdminHall });
Expand All @@ -178,10 +181,10 @@
#endregion

#region Repositories
builder.Services.AddScoped<IRepositoryRead,GenericRepository>();
builder.Services.AddScoped<IRepositoryRead, GenericRepository>();
builder.Services.AddScoped<IRepositoryWrite, GenericRepository>();

builder.Services.AddScoped <IAnalyticsRepository, AnalyticsRepository>();
builder.Services.AddScoped<IAnalyticsRepository, AnalyticsRepository>();

#endregion

Expand Down Expand Up @@ -215,7 +218,7 @@
var app = builder.Build();

#region Development Config
if (app.Environment.IsDevelopment() &&true)
if (app.Environment.IsDevelopment() && true)
{
app.UseSwagger();
app.UseSwaggerUI();
Expand All @@ -228,7 +231,7 @@
var exception = context.Features
.Get<IExceptionHandlerPathFeature>()
?.Error;
var response = new { error = exception?.Message ??"Error" };
var response = new { error = exception?.Message ?? "Error" };
await context.Response.WriteAsJsonAsync(response);
}));
#endregion
Expand All @@ -241,4 +244,3 @@

app.MapControllers();
app.Run();

10 changes: 7 additions & 3 deletions ZID.Automat/src/ZID.Automat.Api/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@
"AdminHall": "AdminPassword"
},
"Database": {
"UseDatabase": "SQLite",
"UseDatabase": "MySql",
"MySql": {
"Connectionstring": "Server=localhost;Database=AutomatDatabase;Uid=root;Pwd=;"
"Connectionstring": "Server=localhost;Port=3306;Database=AutoamtDatabase4;Uid=root;Pwd=your_root_password;"
},
"SQLite": {
"Connectionstring": "Data Source=AutomatDatabase2.db"
},
"SqlServer": {
"Connectionstring": "Server=localhost,1433;Database=YourDatabaseName;User Id=sa;Password=YourStrongPassword;"
}

},
"Borrow": {
"MaxBorrowTime": 7
},
"Debug": {
"useDebug": false,
"useDebug": true,
"UserAuth": {
"TestUser": {
"TestUserName": "TestUser1",
Expand Down
7 changes: 5 additions & 2 deletions ZID.Automat/src/ZID.Automat.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
"AdminHall": "AdminPassword"
},
"Database": {
"UseDatabase": "MySql",
"UseDatabase": "SqlServer",
"MySql": {
"Connectionstring": "Server=localhost;Database=AutomatDatabase;Uid=root;Pwd=;"
"Connectionstring": "Server=localhost;Port=3306;Database=AutoamtDatabase4;Uid=root;Pwd=your_root_password;"
},
"SQLite": {
"Connectionstring": "Data Source=AutomatDatabase2.db"
},
"SqlServer": {
"Connectionstring": "Server=localhost,1433;Database=YourDatabaseName;User Id=sa;Password=YourStrongPassword;"
}
},
"Borrow": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ public void Entschuldigt(int id, bool state)

public IEnumerable<UserAdmiBorrowDto> AllBorrows()
{
return _mapper.Map<IEnumerable<Borrow>, IEnumerable<UserAdmiBorrowDto>>(_repositoryRead.GetAll<Borrow>());
return _mapper.Map<IEnumerable<Borrow>, IEnumerable<UserAdmiBorrowDto>>(_repositoryRead.GetAll<Borrow>().ToList());
}

public IEnumerable<UserAdmiBorrowDto> ToDealWithBorrows()
{
return _mapper.Map<IEnumerable<Borrow>, IEnumerable<UserAdmiBorrowDto>>(_repositoryRead.GetAll<Borrow>()).Where(b => b.Stati == 0);
return _mapper.Map<IEnumerable<Borrow>, IEnumerable<UserAdmiBorrowDto>>(_repositoryRead.GetAll<Borrow>().ToList()).Where(b => b.Stati == 0);
}

public IEnumerable<UserAdmiBorrowDto> OpenBorrows()
{
return _mapper.Map<IEnumerable<Borrow>, IEnumerable<UserAdmiBorrowDto>>(_repositoryRead.GetAll<Borrow>()).Where(b => b.Stati == 1);
return _mapper.Map<IEnumerable<Borrow>, IEnumerable<UserAdmiBorrowDto>>(_repositoryRead.GetAll<Borrow>().ToList()).Where(b => b.Stati == 1);
}

public IEnumerable<UserAdmiBorrowDto> FinishedBorrows()
{
return _mapper.Map<IEnumerable<Borrow>, IEnumerable<UserAdmiBorrowDto>>(_repositoryRead.GetAll<Borrow>()).Where(b => b.Stati == 2);
return _mapper.Map<IEnumerable<Borrow>, IEnumerable<UserAdmiBorrowDto>>(_repositoryRead.GetAll<Borrow>().ToList()).Where(b => b.Stati == 2);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ConfCategoriesService(IRepositoryRead repositoryRead, IMapper mapper, IRe

public IEnumerable<CategoryUpdateDto> AllCategories()
{
return _mapper.Map<IEnumerable<Categorie>, IEnumerable<CategoryUpdateDto>>(_repositoryRead.GetAll<Categorie>());
return _mapper.Map<IEnumerable<Categorie>, IEnumerable<CategoryUpdateDto>>(_repositoryRead.GetAll<Categorie>().ToList());
}

public void UpdateCategory(CategoryUpdateDto categoryi)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -41,7 +42,7 @@ public AdminItemService(IRepositoryRead repositoryRead, IMapper mapper, IReposit

public IEnumerable<ItemGetAllDto> GetAllItems()
{
return _repositoryRead.GetAll<Item>().Select(i => new ItemGetAllDto() { Id = i.Id, Image = i.Image, LocationImAutomat = i.LocationImAutomat, Name = i.Name });
return _repositoryRead.GetAll<Item>().ToList().Select(i => new ItemGetAllDto() { Id = i.Id, Image = i.Image, LocationImAutomat = i.LocationImAutomat, Name = i.Name });
}

public void SetItemPosition(ItemChangeLocationDto data)
Expand All @@ -59,8 +60,8 @@ public ItemAdminDetailedDto ItemDetailedGet(int id)
var item = _repositoryRead.FindById<Item>(id);
var mapped = _mapper.Map<Item, ItemAdminDetailedDto>(item);

var borrows = _repositoryRead.GetAll<Borrow>();
var bi = borrows.Where(b => b.ItemInstance?.ItemId == item?.Id);
var borrows = _repositoryRead.GetAll<Borrow>().Include(i => i.ItemInstance).Include(i => i.ItemInstance.Item);
var bi = borrows.Where(b => b.ItemInstance.ItemId == item.Id).ToList();
mapped.Borrows = _mapper.Map<IEnumerable<Borrow>, IEnumerable<UserAdmiBorrowDto>>(bi);
return mapped;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public IEnumerable<LogQrCodeAdminDto> ScannedItems()
private IEnumerable<LogQrCodeAdminDto> getLogs<T>() where T : BaseLogQrCode
{
IEnumerable<T> data = _read.GetAll<T>();
return _mapper.Map<IEnumerable<BaseLogQrCode>, IEnumerable<LogQrCodeAdminDto>>(data);
return _mapper.Map<IEnumerable<BaseLogQrCode>, IEnumerable<LogQrCodeAdminDto>>(data.ToList());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AdminUserService(IRepositoryRead repositoryRead, IMapper mapper, IReposit
public IEnumerable<UserAdminGetAll> GetAllUsers()
{
var Users = _repositoryRead.GetAll<User>();
return Users.Select((m =>
return Users.ToList().Select((m =>
{
var mapi = _mapper.Map<User, UserAdminGetAll>(m);
mapi.BorrowCount = m.Borrow.Count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Castle.Core.Internal;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Globalization;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -48,7 +49,9 @@ public IEnumerable<AnalyticItemDto> GetAnalyticsItems()

var resultRoh = _repositoryRead
.GetAll<Item>()
.OrderByDescending(i => i.ItemInstances.Where(el => el?.borrow?.BorrowDate > date).Count())
.Include(i=>i.ItemInstances)
.Include(i => i.ItemInstances.Select(i => i.borrow))
.OrderByDescending(i => i.ItemInstances.Where(el => el.borrow.BorrowDate > date).Count())
.Take(3)
.ToList();

Expand All @@ -73,7 +76,7 @@ public IEnumerable<AnalyticItemDto> GetAnalyticsItems()

public IEnumerable<WieVielZuspaetDto> WievielZuspat()
{
return _repositoryRead.GetAll<Borrow>().GroupBy(b => b.StatusEntschuldigt()).Select(b => new WieVielZuspaetDto() { num = b.Count(), label = b.Key }).OrderBy(w => w.label);
return _repositoryRead.GetAll<Borrow>().ToList().GroupBy(b => b.StatusEntschuldigt()).ToList().Select(b => new WieVielZuspaetDto() { num = b.Count(), label = b.Key }).OrderBy(w => w.label);
}

public IEnumerable<TaeglicheUserDto> TaeglicheUser()
Expand All @@ -89,8 +92,9 @@ public IEnumerable<TaeglicheUserDto> TaeglicheUser()

};
var data = _repositoryRead.GetAll<User>()
.ToList()
.GroupBy(u => cats.First(c => c.Item2 <= DateOnly.FromDateTime(u.LastLogin)).Item1)
.OrderByDescending(u=>cats.First(c=>c.Item1 == u.Key).Item2)
.OrderByDescending(u=>cats.First(c=>c.Item1 == u.Key).Item2).ToList()
.Select(u => new TaeglicheUserDto() { Label = u.Key, Value = u.Count() });
return data;
}
Expand Down
12 changes: 7 additions & 5 deletions ZID.Automat/src/ZID.Automat.Application/ItemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using ZID.Automat.Dto.Models;
using AutoMapper;
using ZID.Automat.Exceptions;
using Microsoft.EntityFrameworkCore;

namespace ZID.Automat.Application
{
Expand All @@ -24,19 +25,20 @@ public ItemService(IRepositoryRead repositoryRead, IRepositoryWrite repositoryWr
public IEnumerable<ItemDisplayDto> AllDisplayItems()
{
IEnumerable<Item> Items = _repositoryRead.GetAll<Item>().Where(i => i.LocationImAutomat != "");
return _mapper.Map<IEnumerable<Item>, IEnumerable<ItemDisplayDto>>(Items);
return _mapper.Map<IEnumerable<Item>, IEnumerable<ItemDisplayDto>>(Items.ToList());
}

public IEnumerable<ItemDisplayDto> PrevBorrowedDisplayItemsUser(string UserName)
{
IEnumerable<Borrow> Borrows = _repositoryRead.GetAll<Borrow>();
IEnumerable<Item> items = Borrows.Where(b => b.User.Name == UserName).Select(b => b?.ItemInstance?.Item!).Distinct().Where(i => i.LocationImAutomat != "");
return _mapper.Map<IEnumerable<ItemDisplayDto>>(items);
IEnumerable<Item> items = _repositoryRead.GetAll<Borrow>().Include(b=>b.User).Include(b=>b.ItemInstance).Include(b=>b.ItemInstance.Item).Where(b => b.User.Name == UserName).Select(b => b.ItemInstance.Item).Distinct().Where(i => i.LocationImAutomat != "");
return _mapper.Map<IEnumerable<ItemDisplayDto>>(items.ToList());
}

public IEnumerable<ItemDisplayDto> PopularItems()
{
var Borrows = _repositoryRead.GetAll<Borrow>().Where(i => i.ItemInstance?.Item.LocationImAutomat != "").GroupBy(b => b.ItemInstance?.Item).OrderByDescending(b=>b.Key?.Id).OrderByDescending(b => b.Count(b => b.BorrowDate > DateTime.Now.AddDays(-7))).Take(10).Select(b => b.FirstOrDefault()?.ItemInstance?.Item);
var Borrows = _repositoryRead.GetAll<Borrow>().Include(i => i.ItemInstance).Include(i => i.ItemInstance.Item).Where(i => i.ItemInstance.Item.LocationImAutomat != "").ToList().GroupBy(b => b.ItemInstance.Item).OrderByDescending(b => b.Key.Id).OrderByDescending(b => b.Count(b => b.BorrowDate > DateTime.Now.AddDays(-7))).Take(10).Select(b => b.FirstOrDefault().ItemInstance.Item);
var rest = _repositoryRead.GetAll<Item>().Where(i => i.LocationImAutomat != "").ToList().Except(Borrows);
Borrows = Borrows.Concat(rest).ToList();
return _mapper.Map<IEnumerable<ItemDisplayDto>>(Borrows);
}

Expand Down
10 changes: 6 additions & 4 deletions ZID.Automat/src/ZID.Automat.Application/QrCodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using ZID.Automat.Dto.Models;
using ZID.Automat.Exceptions;
using ZID.Automat.Repository;
using Microsoft.EntityFrameworkCore;

namespace ZID.Automat.Application
{
Expand Down Expand Up @@ -104,8 +105,8 @@ public void InvalidateQrCode(InvalidateQrCodeDto InvalidateQrCode,DateTime now)

public IEnumerable<BorrowDto> OpenQrCodes(string cn)
{
var borrows = _repositoryRead.GetAll<Borrow>().Where(b => b.IsValid() && b.User.Name == cn);
return _mapper.Map<IEnumerable<BorrowDto>>(borrows);
var borrows = _repositoryRead.GetAll<Borrow>().Where(b => (b.CollectDate == null && b.BorrowDate.AddHours(1) >= DateTime.Now )&& b.User.Name == cn);
return _mapper.Map<IEnumerable<BorrowDto>>(borrows.ToList());
}

public IEnumerable<BorrowDto> AllQrCodes(string cn)
Expand All @@ -119,12 +120,13 @@ public IEnumerable<BorrowDto> AllQrCodes(string cn)
borrows.Remove(b);
}

return _mapper.Map<IEnumerable<BorrowDto>>(borrows);
return _mapper.Map<IEnumerable<BorrowDto>>(borrows.ToList());
}

public int OpenQrCodesCount(string cn)
{
return _repositoryRead.GetAll<Borrow>().Where(b=>b.User.Name == cn && b.IsValid()).Count();
//is valid
return _repositoryRead.GetAll<Borrow>().Include(b=>b.User).Where(b=>b.User.Name == cn && (b.CollectDate == null && b.BorrowDate.AddHours(1) >= DateTime.Now)).ToList().Count();
}

public ControllerItemLocationDto ItemLocation(int itemId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ public static void ConfigureDB(this IServiceCollection services, string connecti
{
if (!options.IsConfigured)
{
if (useDb == "MySQL")
if (useDb == "MySql")
{
options.UseMySQL(connectionString);
}
else if (useDb == "SqlServer")
{
options.UseSqlServer(connectionString);

}
else if (useDb == "SQLite")
{
options.UseSqlite(connectionString);
Expand Down
Loading

0 comments on commit 3ae6ab3

Please sign in to comment.