Added various
- Added DOC - Added Patient - Added Notifications - Added Messages - Various Refactoring
This commit is contained in:
@@ -5,8 +5,6 @@ using LinqToDB.DataProvider.SQLite;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SeniorAssistant.Configuration;
|
||||
@@ -14,12 +12,8 @@ using SeniorAssistant.Data;
|
||||
using SeniorAssistant.Models;
|
||||
using SeniorAssistant.Extensions;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SeniorAssistant.Models.Users;
|
||||
|
||||
namespace SeniorAssistant
|
||||
{
|
||||
@@ -100,6 +94,7 @@ namespace SeniorAssistant
|
||||
|
||||
services.AddSingleton<IDataContextFactory<SeniorDataContext>>(dbFactory);
|
||||
SetupDatabase(dbFactory);
|
||||
FillDatabase(dbFactory);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
@@ -144,47 +139,83 @@ namespace SeniorAssistant
|
||||
{
|
||||
using (var db = dataContext.Create())
|
||||
{
|
||||
const string baseUsername = "vecchio";
|
||||
string[] names = { "Mario", "Giovanni", "Aldo", "Giacomo", "Marcello", "Filippo" };
|
||||
|
||||
db.CreateTableIfNotExists<Heartbeat>();
|
||||
db.CreateTableIfNotExists<Sleep>();
|
||||
db.CreateTableIfNotExists<Step>();
|
||||
db.CreateTableIfNotExists<User>();
|
||||
db.CreateTableIfNotExists<Doctor>();
|
||||
db.CreateTableIfNotExists<Patient>();
|
||||
db.CreateTableIfNotExists<Notification>();
|
||||
db.CreateTableIfNotExists<Message>();
|
||||
}
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
foreach (string user in names)
|
||||
void FillDatabase(IDataContextFactory<SeniorDataContext> dataContext)
|
||||
{
|
||||
using (var db = dataContext.Create())
|
||||
{
|
||||
Random rnd = new Random();
|
||||
|
||||
List<User> users = new List<User>();
|
||||
|
||||
List<Doctor> docs = db.Doctors.ToListAsync().Result;
|
||||
if (docs.Count == 0)
|
||||
{
|
||||
var username = baseUsername + count;
|
||||
db.InsertOrReplace(new User { Role = "user", Name = user, Username = username, Password = username, Email = username + "@email.st" } );
|
||||
count++;
|
||||
users.Add(new User { Name = "Alfredo", LastName = "Parise", Email = "alfred.pary@libero.it", Username = "alfredigno", Password = "alfy" });
|
||||
users.Add(new User { Name = "Edoardo", LastName = "Marzio", Email = "edo.marzio@libero.it", Username = "marzietto", Password = "edo64" });
|
||||
|
||||
docs.Add(new Doctor { Username = "alfredigno", Location = "Brasile" });
|
||||
docs.Add(new Doctor { Username = "marzietto", Location = "Uganda" });
|
||||
|
||||
foreach (var doc in docs)
|
||||
db.InsertOrReplace(doc);
|
||||
}
|
||||
|
||||
Random rnd = new Random();
|
||||
List<Patient> patients = db.Patients.ToListAsync().Result;
|
||||
if (patients.Count == 0)
|
||||
{
|
||||
const string baseUsername = "vecchio";
|
||||
string[] names = { "Mario", "Giovanni", "Aldo", "Giacomo", "Marcello", "Filippo" };
|
||||
string[] lastnames = { "Rossi", "Storti", "Baglio", "Poretti", "Marcelli", "Martelli" };
|
||||
int count = 0;
|
||||
for (count=0; count<names.Length; count++)
|
||||
{
|
||||
var username = baseUsername + count;
|
||||
users.Add(new User { Name = names[count], LastName = lastnames[count], Username = username, Password = username, Email = username + "@email.st" });
|
||||
patients.Add(new Patient { Username = username, Doctor = docs[rnd.Next(docs.Count)].Username });
|
||||
}
|
||||
|
||||
foreach (var patient in patients)
|
||||
db.InsertOrReplace(patient);
|
||||
}
|
||||
|
||||
foreach (var user in users)
|
||||
db.InsertOrReplace(user);
|
||||
|
||||
DateTime now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
|
||||
now = now.AddHours(DateTime.Now.Hour).AddMinutes(30);
|
||||
try
|
||||
{
|
||||
double totalHours = 48;
|
||||
try {
|
||||
try
|
||||
{
|
||||
DateTime maxTimeInDB = db.GetTable<Heartbeat>().MaxAsync(x => x.Time).Result;
|
||||
TimeSpan span = now.Subtract(maxTimeInDB);
|
||||
totalHours = span.TotalHours;
|
||||
} catch { }
|
||||
|
||||
for (int i = 0; i<totalHours; i++)
|
||||
}
|
||||
catch { }
|
||||
|
||||
for (int i = 0; i < totalHours; i++)
|
||||
{
|
||||
DateTime time = now.AddHours(-i);
|
||||
for (int num = 0; num < names.Length; num++)
|
||||
foreach (var patient in patients)
|
||||
{
|
||||
string user = baseUsername + num;
|
||||
|
||||
if (time.Day != now.Day && time.Hour == 21)
|
||||
{
|
||||
db.Insert(new Sleep() { Username = user, Time = time, Value = rnd.Next(5 * 3600000, 9 * 3600000) });
|
||||
db.Insert(new Sleep() { Username = patient.Username, Time = time, Value = rnd.Next(5 * 3600000, 9 * 3600000) });
|
||||
}
|
||||
db.Insert(new Heartbeat() { Username = user, Time = time, Value = rnd.Next(50, 120) });
|
||||
db.Insert(new Step() { Username = user, Time = time, Value = rnd.Next(100, 500) });
|
||||
db.Insert(new Heartbeat() { Username = patient.Username, Time = time, Value = rnd.Next(50, 120) });
|
||||
db.Insert(new Step() { Username = patient.Username, Time = time, Value = rnd.Next(100, 500) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user