Besciamello #1

Merged
Berack96 merged 8 commits from besciamello into master 2019-01-15 21:35:00 +01:00
8 changed files with 20 additions and 17 deletions
Showing only changes of commit 5bdc0dcba7 - Show all commits

View File

@@ -45,9 +45,11 @@ namespace IdentityDemo.Controllers
[HttpPost]
public ActionResult _login(string username, string password)
{
JsonResponse response = new JsonResponse();
response.Success = false;
response.Message = "Username or password is invalid.";
JsonResponse response = new JsonResponse
{
Success = false,
Message = "Username or password is invalid."
};
var strunz = Db.GetTable<User>().Where(user => user.Username.Equals(username) && user.Password.Equals(password)).ToListAsync().Result;

View File

@@ -47,6 +47,8 @@ namespace SeniorAssistant.Controllers
[Route("User/{User}")]
public IActionResult SingleUser(string user)
{
if(session.GetString("username") == null)
return RedirectToAction("Index");
return View("data", user);
}
}

View File

@@ -7,7 +7,6 @@ namespace SeniorAssistant.Models
{
[PrimaryKey]
[NotNull]
[Association(ThisKey = nameof(Username), OtherKey = nameof(User.Username), CanBeNull = false)]
public string Username { get; set; }
[PrimaryKey]
@@ -15,5 +14,10 @@ namespace SeniorAssistant.Models
public DateTime Time { get; set; }
public double Value { get; set; }
/*
[Association(ThisKey = nameof(Username), OtherKey = nameof(User.Username), CanBeNull = false)]
public User UserObj { get; set; }
*/
}
}

View File

@@ -7,7 +7,6 @@ namespace SeniorAssistant.Models
{
[PrimaryKey]
[NotNull]
[Association(ThisKey = nameof(Username), OtherKey = nameof(User.Username), CanBeNull = false)]
public string Username { get; set; }
[PrimaryKey]

View File

@@ -7,7 +7,6 @@ namespace SeniorAssistant.Models
{
[PrimaryKey]
[NotNull]
[Association(ThisKey = nameof(Username), OtherKey = nameof(User.Username), CanBeNull = false)]
public string Username { get; set; }
[PrimaryKey]

View File

@@ -1,18 +1,19 @@
using LinqToDB.Mapping;
using Microsoft.AspNetCore.Identity;
using Newtonsoft.Json;
namespace SeniorAssistant.Models
{
public class User : IHasUsername
{
[PrimaryKey]
[NotNull]
[Column(IsPrimaryKey = true, CanBeNull = false)]
public string Username { get; set; }
[NotNull]
public string Email { get; set; }
[NotNull]
[JsonIgnore]
public string Password { get; set; }
[NotNull]

View File

@@ -121,7 +121,7 @@ namespace SeniorAssistant
using (var db = dataContext.Create())
{
const string baseUsername = "vecchio";
string[] users = { "Mario", "Giovanni", "Aldo", "Giacomo", "Marcello", "Filippo" };
string[] names = { "Mario", "Giovanni", "Aldo", "Giacomo", "Marcello", "Filippo" };
db.CreateTableIfNotExists<Heartbeat>();
db.CreateTableIfNotExists<Sleep>();
@@ -130,7 +130,7 @@ namespace SeniorAssistant
{
db.CreateTable<User>();
int count = 0;
foreach (string user in users)
foreach (string user in names)
{
var username = baseUsername + count;
db.InsertOrReplace(new User { Name = user, Username = username, Password = username, Email = username + "@email.st" } );
@@ -145,7 +145,7 @@ namespace SeniorAssistant
now = now.AddHours(DateTime.Now.Hour).AddMinutes(30);
try
{
double totalHours = 50;
double totalHours = 48;
try {
DateTime maxTimeInDB = db.GetTable<Heartbeat>().MaxAsync(x => x.Time).Result;
TimeSpan span = now.Subtract(maxTimeInDB);
@@ -155,21 +155,17 @@ namespace SeniorAssistant
for (int i = 0; i<totalHours; i++)
{
DateTime time = now.AddHours(-i);
for (int num = 0; num < users.Length; num++)
for (int num = 0; num < names.Length; num++)
{
string user = baseUsername + num;
if (time.Day != now.Day)
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 Heartbeat() { Username = user, Time = time, Value = rnd.Next(50, 120) });
db.Insert(new Step() { Username = user, Time = time, Value = rnd.Next(100, 500) });
}
if (time.Day != now.Day)
{
now = now.AddDays(-1);
}
}
}
catch { }

Binary file not shown.