Besciamello #1
2
.gitignore
vendored
2
.gitignore
vendored
@@ -261,3 +261,5 @@ __pycache__/
|
|||||||
*.pyc
|
*.pyc
|
||||||
|
|
||||||
SeniorAssistant/SeniorAssistant/wwwroot/*
|
SeniorAssistant/SeniorAssistant/wwwroot/*
|
||||||
|
/SeniorAssistant/Controllers/TestController.cs
|
||||||
|
/SeniorAssistant/Views/Test/*
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ using SeniorAssistant.Models;
|
|||||||
using SeniorAssistant.Controllers;
|
using SeniorAssistant.Controllers;
|
||||||
using LinqToDB;
|
using LinqToDB;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using SeniorAssistant.Models.Users;
|
||||||
|
|
||||||
namespace IdentityDemo.Controllers
|
namespace IdentityDemo.Controllers
|
||||||
{
|
{
|
||||||
@@ -12,6 +13,8 @@ namespace IdentityDemo.Controllers
|
|||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
public class AccountController : BaseController
|
public class AccountController : BaseController
|
||||||
{
|
{
|
||||||
|
private readonly JsonResponse OkJson = new JsonResponse();
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult _login(string username, string password)
|
public ActionResult _login(string username, string password)
|
||||||
{
|
{
|
||||||
@@ -26,15 +29,20 @@ namespace IdentityDemo.Controllers
|
|||||||
if (result.Count == 1)
|
if (result.Count == 1)
|
||||||
{
|
{
|
||||||
var loggedUser = HttpContext.Session.GetString(Username);
|
var loggedUser = HttpContext.Session.GetString(Username);
|
||||||
if (loggedUser==null || !loggedUser.Equals(username))
|
if (loggedUser==null || !loggedUser.Equals(username)) // non ha senso
|
||||||
{
|
{
|
||||||
User user = result.First();
|
User user = result.First();
|
||||||
HttpContext.Session.SetString(Username, username);
|
HttpContext.Session.SetString(Username, username);
|
||||||
HttpContext.Session.SetString("email", user.Email);
|
HttpContext.Session.SetString("email", user.Email);
|
||||||
HttpContext.Session.SetString("name", user.Name);
|
HttpContext.Session.SetString("name", user.Name);
|
||||||
HttpContext.Session.SetString("role", user.Role);
|
|
||||||
//HttpContext.Session.SetString("lastname", user.LastName);
|
//HttpContext.Session.SetString("lastname", user.LastName);
|
||||||
|
|
||||||
|
|
||||||
|
var isDoc = (from d in Db.Doctors
|
||||||
|
where d.Username.Equals(username)
|
||||||
|
select d).ToArray().FirstOrDefault() != null;
|
||||||
|
HttpContext.Session.SetString("role", isDoc? "doctor":"patient");
|
||||||
|
|
||||||
response.Success = true;
|
response.Success = true;
|
||||||
response.Message = Request.Query["ReturnUrl"];
|
response.Message = Request.Query["ReturnUrl"];
|
||||||
}
|
}
|
||||||
@@ -56,34 +64,109 @@ namespace IdentityDemo.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult _register(User user)
|
public ActionResult _register(User user)
|
||||||
{
|
{
|
||||||
JsonResponse response = new JsonResponse() { Success = true };
|
return Action(() =>
|
||||||
|
|
||||||
if(ModelState.IsValid)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Db.Insert(user);
|
Db.Insert(user);
|
||||||
_login(user.Username, user.Password);
|
return _login(user.Username, user.Password);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
response.Success = false;
|
return Json(new JsonResponse(false, "Username already exists"));
|
||||||
response.Message = "Username already exists";
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult _notification(string username, string message)
|
||||||
|
{
|
||||||
|
return LoggedAction(() =>
|
||||||
|
{
|
||||||
|
Db.Insert(new Notification()
|
||||||
|
{
|
||||||
|
Message = message,
|
||||||
|
Username = username,
|
||||||
|
Time = DateTime.Now,
|
||||||
|
Seen = false
|
||||||
|
});
|
||||||
|
return Json(OkJson);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut]
|
||||||
|
public ActionResult _notification(int id)
|
||||||
|
{
|
||||||
|
return LoggedAction(() =>
|
||||||
|
{
|
||||||
|
JsonResponse response = OkJson;
|
||||||
|
|
||||||
|
Notification note = Db.Notifications.Where(n => n.Id == id).ToArray().FirstOrDefault();
|
||||||
|
if(note != null)
|
||||||
|
{
|
||||||
|
note.Seen = true;
|
||||||
|
Db.Update(note);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response.Success = false;
|
response.Success = false;
|
||||||
response.Message = "Modello non valido";
|
response.Message = "La notifica da modificare non esiste";
|
||||||
}
|
}
|
||||||
|
|
||||||
return Json(response);
|
return Json(response);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class JsonResponse
|
[HttpPost]
|
||||||
|
public ActionResult _addDoc(string doctor)
|
||||||
{
|
{
|
||||||
public bool Success { get; internal set; }
|
return LoggedAction(() =>
|
||||||
public string Message { get; internal set; }
|
{
|
||||||
|
string username = HttpContext.Session.GetString(Username);
|
||||||
|
var isAlreadyPatient = Db.Patients.Where(p => p.Username.Equals(username)).ToArray().FirstOrDefault() != null;
|
||||||
|
if (isAlreadyPatient)
|
||||||
|
return Json(new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "You are already a patient"
|
||||||
|
});
|
||||||
|
|
||||||
|
var docExist = Db.Doctors.Where(d => d.Username.Equals(doctor)).ToArray().FirstOrDefault() != null;
|
||||||
|
if(!docExist)
|
||||||
|
return Json(new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Doctor doesn't exist"
|
||||||
|
});
|
||||||
|
|
||||||
|
Db.Insert(new Patient()
|
||||||
|
{
|
||||||
|
Doctor = doctor,
|
||||||
|
Username = username
|
||||||
|
});
|
||||||
|
|
||||||
|
_notification(doctor, "L'utente "+username+" ti ha inserito come il suo dottore.");
|
||||||
|
return Json(new JsonResponse());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult _sendMessage(string reciver, string body)
|
||||||
|
{
|
||||||
|
return LoggedAction(() => {
|
||||||
|
string username = HttpContext.Session.GetString(Username);
|
||||||
|
Message message = new Message()
|
||||||
|
{
|
||||||
|
Reciver = reciver,
|
||||||
|
Body = body,
|
||||||
|
Time = DateTime.Now,
|
||||||
|
Username = username,
|
||||||
|
Seen = false
|
||||||
|
};
|
||||||
|
|
||||||
|
Db.Insert(message);
|
||||||
|
|
||||||
|
return Json(new JsonResponse());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace SeniorAssistant.Controllers
|
namespace SeniorAssistant.Controllers
|
||||||
{
|
{
|
||||||
@@ -45,9 +43,15 @@ namespace SeniorAssistant.Controllers
|
|||||||
return CheckAuthorized("Data", user);
|
return CheckAuthorized("Data", user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Route("Message/{Id}")]
|
||||||
|
public IActionResult Message(int id)
|
||||||
|
{
|
||||||
|
return CheckAuthorized("Message", id);
|
||||||
|
}
|
||||||
|
|
||||||
private IActionResult CheckAuthorized(string view, object model = null)
|
private IActionResult CheckAuthorized(string view, object model = null)
|
||||||
{
|
{
|
||||||
if (HttpContext.Session.GetString("username") == null)
|
if (!IsLogged())
|
||||||
{
|
{
|
||||||
model = "/" + view;
|
model = "/" + view;
|
||||||
view = "Index";
|
view = "Index";
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SeniorAssistant.Models;
|
using SeniorAssistant.Models;
|
||||||
|
using SeniorAssistant.Models.Users;
|
||||||
|
|
||||||
namespace SeniorAssistant.Controllers.Services
|
namespace SeniorAssistant.Controllers.Services
|
||||||
{
|
{
|
||||||
@@ -18,4 +19,12 @@ namespace SeniorAssistant.Controllers.Services
|
|||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class UserController : CrudController<User>
|
public class UserController : CrudController<User>
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class PatientController : CrudController<Patient>
|
||||||
|
{ }
|
||||||
|
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class DoctorController : CrudController<Doctor>
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SeniorAssistant.Data;
|
using SeniorAssistant.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace SeniorAssistant.Controllers
|
namespace SeniorAssistant.Controllers
|
||||||
{
|
{
|
||||||
public abstract class BaseController : Controller
|
public abstract class BaseController : Controller
|
||||||
{
|
{
|
||||||
|
protected static readonly string MustBeLogged = "Devi essere loggato per vedere/modificare questo dato";
|
||||||
|
protected static readonly string InvalidModel = "Modello non valido";
|
||||||
|
protected static readonly string NoAuthorized = "Non sei autorizzato a vedere questi dati";
|
||||||
protected static readonly string Username = "username";
|
protected static readonly string Username = "username";
|
||||||
|
|
||||||
IDataContextFactory<SeniorDataContext> dbFactory;
|
IDataContextFactory<SeniorDataContext> dbFactory;
|
||||||
@@ -28,5 +33,63 @@ namespace SeniorAssistant.Controllers
|
|||||||
{
|
{
|
||||||
return HttpContext.Session.GetString(Username) != null;
|
return HttpContext.Session.GetString(Username) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ActionResult Action(Func<ActionResult> success)
|
||||||
|
{
|
||||||
|
return ModelState.IsValid ?
|
||||||
|
success.Invoke() :
|
||||||
|
Json(new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = InvalidModel
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ActionResult LoggedAction(Func<ActionResult> success)
|
||||||
|
{
|
||||||
|
return Action(() =>
|
||||||
|
{
|
||||||
|
return IsLogged() ?
|
||||||
|
success.Invoke() :
|
||||||
|
Json(new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = MustBeLogged
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ActionResult LoggedAccessDataOf(string username, Func<ActionResult> success)
|
||||||
|
{
|
||||||
|
return LoggedAction(() =>
|
||||||
|
{
|
||||||
|
var loggedUser = HttpContext.Session.GetString(Username);
|
||||||
|
var condition = username.Equals(loggedUser);
|
||||||
|
|
||||||
|
condition = condition || (from patient in Db.Patients
|
||||||
|
where patient.Doctor.Equals(loggedUser) && patient.Username.Equals(username)
|
||||||
|
select patient).ToArray().FirstOrDefault() != null;
|
||||||
|
|
||||||
|
return condition ?
|
||||||
|
success.Invoke() :
|
||||||
|
Json(new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = NoAuthorized
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class JsonResponse
|
||||||
|
{
|
||||||
|
public JsonResponse(bool success=true, string message="")
|
||||||
|
{
|
||||||
|
Success = success;
|
||||||
|
Message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Success { get; set; }
|
||||||
|
public string Message { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using LinqToDB.Data;
|
using LinqToDB.Data;
|
||||||
using LinqToDB.DataProvider;
|
using LinqToDB.DataProvider;
|
||||||
using SeniorAssistant.Models;
|
using SeniorAssistant.Models;
|
||||||
|
using SeniorAssistant.Models.Users;
|
||||||
|
|
||||||
namespace SeniorAssistant.Data
|
namespace SeniorAssistant.Data
|
||||||
{
|
{
|
||||||
@@ -11,8 +12,13 @@ namespace SeniorAssistant.Data
|
|||||||
: base(dataProvider, connectionString)
|
: base(dataProvider, connectionString)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public ITable<User> User => GetTable<User>();
|
public ITable<User> Users => GetTable<User>();
|
||||||
|
|
||||||
public ITable<Heartbeat> Heartbeats => GetTable<Heartbeat>();
|
public ITable<Heartbeat> Heartbeats => GetTable<Heartbeat>();
|
||||||
|
public ITable<Sleep> Sleeps => GetTable<Sleep>();
|
||||||
|
public ITable<Step> Steps => GetTable<Step>();
|
||||||
|
public ITable<Doctor> Doctors => GetTable<Doctor>();
|
||||||
|
public ITable<Patient> Patients => GetTable<Patient>();
|
||||||
|
public ITable<Notification> Notifications => GetTable<Notification>();
|
||||||
|
public ITable<Message> Messages => GetTable<Message>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SeniorAssistant.Models
|
namespace SeniorAssistant.Models
|
||||||
{
|
{
|
||||||
@@ -12,8 +9,7 @@ namespace SeniorAssistant.Models
|
|||||||
|
|
||||||
public class MenuItem : IMenuItem
|
public class MenuItem : IMenuItem
|
||||||
{
|
{
|
||||||
public MenuItem(string text) : this(text, "#") { }
|
public MenuItem(string text, string href = "#")
|
||||||
public MenuItem(string text, string href)
|
|
||||||
{
|
{
|
||||||
Text = text;
|
Text = text;
|
||||||
HRef = href;
|
HRef = href;
|
||||||
|
|||||||
26
SeniorAssistant/Models/Message.cs
Normal file
26
SeniorAssistant/Models/Message.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using LinqToDB.Mapping;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SeniorAssistant.Models
|
||||||
|
{
|
||||||
|
public class Message : IHasTime
|
||||||
|
{
|
||||||
|
[Column(IsPrimaryKey = true, CanBeNull = false, IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
public DateTime Time { get; set; }
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
public string Reciver { get; set; }
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
public string Body { get; set; }
|
||||||
|
|
||||||
|
public bool Seen { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
21
SeniorAssistant/Models/Notification.cs
Normal file
21
SeniorAssistant/Models/Notification.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using LinqToDB.Mapping;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SeniorAssistant.Models
|
||||||
|
{
|
||||||
|
public class Notification : IHasTime
|
||||||
|
{
|
||||||
|
[Column(IsPrimaryKey = true, CanBeNull = false, IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
public DateTime Time { get; set; }
|
||||||
|
|
||||||
|
public bool Seen { get; set; }
|
||||||
|
|
||||||
|
public string Message { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
17
SeniorAssistant/Models/Users/Doctor.cs
Normal file
17
SeniorAssistant/Models/Users/Doctor.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using LinqToDB.Mapping;
|
||||||
|
|
||||||
|
namespace SeniorAssistant.Models.Users
|
||||||
|
{
|
||||||
|
public class Doctor : IHasUsername
|
||||||
|
{
|
||||||
|
[Column(IsPrimaryKey = true, CanBeNull = false)]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
[Association(ThisKey = "Username", OtherKey = nameof(User.Username), CanBeNull = false)]
|
||||||
|
public User UserData { get; set; }
|
||||||
|
|
||||||
|
public string Location { get; set; }
|
||||||
|
|
||||||
|
public string Schedule { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
18
SeniorAssistant/Models/Users/Patient.cs
Normal file
18
SeniorAssistant/Models/Users/Patient.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using LinqToDB.Mapping;
|
||||||
|
|
||||||
|
namespace SeniorAssistant.Models.Users
|
||||||
|
{
|
||||||
|
public class Patient : IHasUsername
|
||||||
|
{
|
||||||
|
[Column(IsPrimaryKey = true, CanBeNull = false)]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
[Association(ThisKey = "Username", OtherKey = nameof(User.Username), CanBeNull = false)]
|
||||||
|
public User UserData { get; set; }
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
public string Doctor { get; set; }
|
||||||
|
|
||||||
|
public string Notes { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using LinqToDB.Mapping;
|
using LinqToDB.Mapping;
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SeniorAssistant.Models
|
namespace SeniorAssistant.Models
|
||||||
@@ -16,9 +15,6 @@ namespace SeniorAssistant.Models
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
|
|
||||||
[NotNull]
|
|
||||||
public string Role { get; set; }
|
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public string LastName { get; set; }
|
public string LastName { get; set; }
|
||||||
@@ -5,8 +5,6 @@ using LinqToDB.DataProvider.SQLite;
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.Data.Sqlite;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using SeniorAssistant.Configuration;
|
using SeniorAssistant.Configuration;
|
||||||
@@ -14,12 +12,8 @@ using SeniorAssistant.Data;
|
|||||||
using SeniorAssistant.Models;
|
using SeniorAssistant.Models;
|
||||||
using SeniorAssistant.Extensions;
|
using SeniorAssistant.Extensions;
|
||||||
using Swashbuckle.AspNetCore.Swagger;
|
using Swashbuckle.AspNetCore.Swagger;
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using SeniorAssistant.Models.Users;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace SeniorAssistant
|
namespace SeniorAssistant
|
||||||
{
|
{
|
||||||
@@ -100,6 +94,7 @@ namespace SeniorAssistant
|
|||||||
|
|
||||||
services.AddSingleton<IDataContextFactory<SeniorDataContext>>(dbFactory);
|
services.AddSingleton<IDataContextFactory<SeniorDataContext>>(dbFactory);
|
||||||
SetupDatabase(dbFactory);
|
SetupDatabase(dbFactory);
|
||||||
|
FillDatabase(dbFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// 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())
|
using (var db = dataContext.Create())
|
||||||
{
|
{
|
||||||
const string baseUsername = "vecchio";
|
|
||||||
string[] names = { "Mario", "Giovanni", "Aldo", "Giacomo", "Marcello", "Filippo" };
|
|
||||||
|
|
||||||
db.CreateTableIfNotExists<Heartbeat>();
|
db.CreateTableIfNotExists<Heartbeat>();
|
||||||
db.CreateTableIfNotExists<Sleep>();
|
db.CreateTableIfNotExists<Sleep>();
|
||||||
db.CreateTableIfNotExists<Step>();
|
db.CreateTableIfNotExists<Step>();
|
||||||
db.CreateTableIfNotExists<User>();
|
db.CreateTableIfNotExists<User>();
|
||||||
|
db.CreateTableIfNotExists<Doctor>();
|
||||||
int count = 0;
|
db.CreateTableIfNotExists<Patient>();
|
||||||
foreach (string user in names)
|
db.CreateTableIfNotExists<Notification>();
|
||||||
{
|
db.CreateTableIfNotExists<Message>();
|
||||||
var username = baseUsername + count;
|
}
|
||||||
db.InsertOrReplace(new User { Role = "user", Name = user, Username = username, Password = username, Email = username + "@email.st" } );
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FillDatabase(IDataContextFactory<SeniorDataContext> dataContext)
|
||||||
|
{
|
||||||
|
using (var db = dataContext.Create())
|
||||||
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
|
|
||||||
|
List<User> users = new List<User>();
|
||||||
|
|
||||||
|
List<Doctor> docs = db.Doctors.ToListAsync().Result;
|
||||||
|
if (docs.Count == 0)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
DateTime now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
|
||||||
now = now.AddHours(DateTime.Now.Hour).AddMinutes(30);
|
now = now.AddHours(DateTime.Now.Hour).AddMinutes(30);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
double totalHours = 48;
|
double totalHours = 48;
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
DateTime maxTimeInDB = db.GetTable<Heartbeat>().MaxAsync(x => x.Time).Result;
|
DateTime maxTimeInDB = db.GetTable<Heartbeat>().MaxAsync(x => x.Time).Result;
|
||||||
TimeSpan span = now.Subtract(maxTimeInDB);
|
TimeSpan span = now.Subtract(maxTimeInDB);
|
||||||
totalHours = span.TotalHours;
|
totalHours = span.TotalHours;
|
||||||
} catch { }
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
for (int i = 0; i<totalHours; i++)
|
for (int i = 0; i < totalHours; i++)
|
||||||
{
|
{
|
||||||
DateTime time = now.AddHours(-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)
|
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 Heartbeat() { Username = patient.Username, Time = time, Value = rnd.Next(50, 120) });
|
||||||
db.Insert(new Step() { Username = user, Time = time, Value = rnd.Next(100, 500) });
|
db.Insert(new Step() { Username = patient.Username, Time = time, Value = rnd.Next(100, 500) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
@inject IHttpContextAccessor HttpContextAccessor
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
|
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||||
@model string
|
@model string
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewBag.Title = "Hello Razor";
|
ViewBag.Title = "Hello Razor";
|
||||||
var session = HttpContextAccessor.HttpContext.Session;
|
var session = HttpContextAccessor.HttpContext.Session;
|
||||||
|
var username = session.GetString("username");
|
||||||
|
|
||||||
// Questa variabile serve a sapere se si e' autorizzati o meno.
|
bool auth = username.Equals(Model);
|
||||||
// Per ora e' semplice ma magari si puo' peggiorare utilizzando il ruolo di Doc... etc
|
if (session.GetString("role").Equals("doctor"))
|
||||||
// (Utilizzare inject DbContext)
|
{
|
||||||
bool auth = session.GetString("username").Equals(Model);
|
var db = dbFactory.Create();
|
||||||
|
var isDocPatient = (from p in db.Patients
|
||||||
|
where p.Username.Equals(Model) && p.Doctor.Equals(username)
|
||||||
|
select p).ToArray().FirstOrDefault() != null;
|
||||||
|
auth = auth || isDocPatient;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (!auth)
|
@if (!auth)
|
||||||
@@ -18,10 +25,18 @@
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Aggiungere un qualcosa per scegliere le ore da vedere (Max 48?)
|
// Aggiungere un qualcosa per scegliere le ore da vedere (Max 48?)
|
||||||
<div id="chart"></div>
|
<input id="hours-data" type="text" placeholder="hours" value="24" />
|
||||||
|
<button id="refresh-hours" class="fc-button">Cambia ora</button>
|
||||||
|
<div id="chart-data"></div>
|
||||||
<script>
|
<script>
|
||||||
|
$("#hours-data").on("change keyup paste click", function () {
|
||||||
|
var t = $(this);
|
||||||
|
t.val(t.val().replace(/[^0-9]/g, '').substring(0, 2));
|
||||||
|
});
|
||||||
|
$("#refresh-hours").on("click", function () {
|
||||||
|
var hours = $("#hours-data").val();
|
||||||
var base_url = "@Url.Content("~/api/")";
|
var base_url = "@Url.Content("~/api/")";
|
||||||
var end_url = "/@Model/last/48";
|
var end_url = "/@Model/last/" + hours;
|
||||||
|
|
||||||
$.getJSON(base_url + "heartbeat" + end_url, function (heartbeat) {
|
$.getJSON(base_url + "heartbeat" + end_url, function (heartbeat) {
|
||||||
$.getJSON(base_url + "step" + end_url, function (steps) {
|
$.getJSON(base_url + "step" + end_url, function (steps) {
|
||||||
@@ -36,7 +51,7 @@ else
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#chart").kendoChart({
|
$("#chart-data").kendoChart({
|
||||||
title: { text: "Visualizzazione attivita' di @Model" },
|
title: { text: "Visualizzazione attivita' di @Model" },
|
||||||
legend: { position: "bottom" },
|
legend: { position: "bottom" },
|
||||||
seriesDefaults: {
|
seriesDefaults: {
|
||||||
@@ -103,5 +118,7 @@ else
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
$("#refresh-hours").click();
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,6 @@ se non loggato deve tornare qua
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Html.RenderPartialAsync("Profile");
|
await Html.RenderPartialAsync("Profile"); // magari sostituire qui
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
30
SeniorAssistant/Views/Home/Message.cshtml
Normal file
30
SeniorAssistant/Views/Home/Message.cshtml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
@model int
|
||||||
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
|
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||||
|
@using LinqToDB;
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "Hello Razor";
|
||||||
|
string username = HttpContextAccessor.HttpContext.Session.GetString("username");
|
||||||
|
var db = dbFactory.Create();
|
||||||
|
var message = (from m in db.Messages
|
||||||
|
where m.Id.Equals(Model) && m.Reciver.Equals(username)
|
||||||
|
select m).ToArray().FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
@if (message == null)
|
||||||
|
{
|
||||||
|
<p class="text-red">Non hai il permesso</p>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message.Seen = true;
|
||||||
|
db.Update(message);
|
||||||
|
<p>Messaggio da @message.Username</p>
|
||||||
|
<p>Inviato il @message.Time</p>
|
||||||
|
<div class="info-box-text">
|
||||||
|
@message.Body
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
@@ -13,14 +13,6 @@
|
|||||||
dataSource: {
|
dataSource: {
|
||||||
transport: {
|
transport: {
|
||||||
read: { url: baseUrl, type: "GET" }
|
read: { url: baseUrl, type: "GET" }
|
||||||
|
|
||||||
/*
|
|
||||||
parameterMap: function (model, operation) {
|
|
||||||
if (operation !== "read" && model) {
|
|
||||||
return kendo.stringify(model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
},
|
},
|
||||||
serverPaging: false,
|
serverPaging: false,
|
||||||
serverSorting: false,
|
serverSorting: false,
|
||||||
@@ -30,7 +22,8 @@
|
|||||||
id: "username",
|
id: "username",
|
||||||
fields: {
|
fields: {
|
||||||
username: { type: "string" },
|
username: { type: "string" },
|
||||||
name: { type: "string" }
|
name: { type: "string" },
|
||||||
|
lastName: { type: "string" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,9 +33,10 @@
|
|||||||
filterable: true,
|
filterable: true,
|
||||||
editable: false,
|
editable: false,
|
||||||
columns: [
|
columns: [
|
||||||
{ field: "username", title: "Username" },
|
|
||||||
{ field: "name", title: "Name" },
|
{ field: "name", title: "Name" },
|
||||||
{ field: "url", title: "",template:'<a href=/user/#=username#>Vedi Dati</a>'}/*,
|
{ field: "lastName", title: "Lastname" },
|
||||||
|
{ field: "url", title: "", template: '<a href=/user/#=username#>Vedi Dati</a>' }
|
||||||
|
/*,
|
||||||
{ field: "time", title: "Date/Time", format: "{dd/MM/yyyy HH}" },
|
{ field: "time", title: "Date/Time", format: "{dd/MM/yyyy HH}" },
|
||||||
{ field: "value", title: "Heartbeats" }
|
{ field: "value", title: "Heartbeats" }
|
||||||
*/
|
*/
|
||||||
|
|||||||
90
SeniorAssistant/Views/Shared/Messages.cshtml
Normal file
90
SeniorAssistant/Views/Shared/Messages.cshtml
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
@model string
|
||||||
|
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||||
|
|
||||||
|
@{
|
||||||
|
var db = dbFactory.Create();
|
||||||
|
var maxMessage = 10;
|
||||||
|
var notSeen = (from n in db.Messages
|
||||||
|
where n.Reciver.Equals(Model) && n.Seen == false
|
||||||
|
orderby n.Time descending
|
||||||
|
select n).Take(maxMessage).ToArray();
|
||||||
|
|
||||||
|
var messages = new Message[maxMessage];
|
||||||
|
var num = notSeen.Length;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i=0; i<num; i++)
|
||||||
|
{
|
||||||
|
messages[i] = notSeen[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num < maxMessage)
|
||||||
|
{
|
||||||
|
var messSeen = (from n in db.Messages
|
||||||
|
where n.Reciver.Equals(Model) && n.Seen == true
|
||||||
|
orderby n.Time descending
|
||||||
|
select n).Take(maxMessage-num).ToArray();
|
||||||
|
|
||||||
|
foreach(var m in messSeen)
|
||||||
|
{
|
||||||
|
messages[i] = m;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<script>
|
||||||
|
$(document).ready(
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
url: "/Account/_message",
|
||||||
|
data: { Username: "@Model", Message: "stronzo" },
|
||||||
|
success: function (data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<a id="id-message-toggle" href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
|
<i class="fa fa-envelope-o"></i>
|
||||||
|
@if (num != 0)
|
||||||
|
{
|
||||||
|
<span class="label label-danger">
|
||||||
|
@num
|
||||||
|
@if(num > maxMessage)
|
||||||
|
{
|
||||||
|
@:+
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
@if (messages.Length != 0)
|
||||||
|
{
|
||||||
|
<ul id="id-message-drop" class="dropdown-menu">
|
||||||
|
<li class="header">You have @num unread message</li>
|
||||||
|
<li>
|
||||||
|
<!-- Inner Menu: contains the messages -->
|
||||||
|
<ul class="menu">
|
||||||
|
@foreach (var message in messages)
|
||||||
|
{
|
||||||
|
if(message != null)
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
<!-- start notification -->
|
||||||
|
<a id="message-@message.Id" @if(message.Seen) {<text>class= "bg-gray"</text>} href="/Message/@message.Id">
|
||||||
|
<i class="fa text-lime">@message.Time</i><br />
|
||||||
|
@message.Body
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<!-- end message -->
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<!-- <li class="footer"><a href="#">View all</a></li> -->
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
@@ -6,116 +6,49 @@
|
|||||||
|
|
||||||
<div class="navbar-custom-menu">
|
<div class="navbar-custom-menu">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<!-- Messages: style can be found in dropdown.less-->
|
@if (session != null)
|
||||||
<li class="dropdown messages-menu">
|
{
|
||||||
<!-- Menu toggle button -->
|
<!--
|
||||||
|
Scheletro di una roba sopra per le notifiche e messaggi e robe in piu...
|
||||||
|
<li class="dropdown ??-menu">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
<i class="fa fa-envelope-o"></i>
|
<i class="fa fa-??-o"></i>
|
||||||
<span class="label label-success">4</span>
|
<span class="label label-??">??</span>
|
||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li class="header">You have 4 messages</li>
|
<li class="header">??</li>
|
||||||
<li>
|
<li>
|
||||||
<!-- inner menu: contains the messages -->
|
|
||||||
<ul class="menu">
|
<ul class="menu">
|
||||||
<li>
|
<li>Elements Here</li>
|
||||||
<!-- start message -->
|
|
||||||
<a href="#">
|
<a href="#">
|
||||||
<div class="pull-left">
|
<div class="pull-left">
|
||||||
<!-- User Image -->
|
|
||||||
<img src="~/AdminLTE-2.4.3/dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
|
<img src="~/AdminLTE-2.4.3/dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
|
||||||
</div>
|
</div>
|
||||||
<!-- Message title and timestamp -->
|
|
||||||
<h4>
|
<h4>
|
||||||
Support Team
|
Support Team
|
||||||
<small><i class="fa fa-clock-o"></i> 5 mins</small>
|
<small><i class="fa fa-clock-o"></i> 5 mins</small>
|
||||||
</h4>
|
</h4>
|
||||||
<!-- The message -->
|
|
||||||
<p>Why not buy a new awesome theme?</p>
|
<p>Why not buy a new awesome theme?</p>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
|
||||||
<!-- end message -->
|
|
||||||
</ul>
|
|
||||||
<!-- /.menu -->
|
|
||||||
</li>
|
|
||||||
<li class="footer"><a href="#">See All Messages</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<!-- /.messages-menu -->
|
</ul>
|
||||||
<!-- Notifications Menu -->
|
</li>
|
||||||
|
-->
|
||||||
|
<li class="dropdown messages-menu">
|
||||||
|
@{ await Html.RenderPartialAsync("Messages", session); }
|
||||||
|
</li>
|
||||||
<li class="dropdown notifications-menu">
|
<li class="dropdown notifications-menu">
|
||||||
<!-- Menu toggle button -->
|
@{ await Html.RenderPartialAsync("Notifications", session); }
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
|
||||||
<i class="fa fa-bell-o"></i>
|
|
||||||
<span class="label label-warning">10</span>
|
|
||||||
</a>
|
|
||||||
<ul class="dropdown-menu">
|
|
||||||
<li class="header">You have 10 notifications</li>
|
|
||||||
<li>
|
|
||||||
<!-- Inner Menu: contains the notifications -->
|
|
||||||
<ul class="menu">
|
|
||||||
<li>
|
|
||||||
<!-- start notification -->
|
|
||||||
<a href="#">
|
|
||||||
<i class="fa fa-users text-aqua"></i> 5 new members joined today
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
<!-- end notification -->
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
<li class="footer"><a href="#">View all</a></li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
<!-- Tasks Menu -->
|
|
||||||
<li class="dropdown tasks-menu">
|
|
||||||
<!-- Menu Toggle Button -->
|
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
|
||||||
<i class="fa fa-flag-o"></i>
|
|
||||||
<span class="label label-danger">9</span>
|
|
||||||
</a>
|
|
||||||
<ul class="dropdown-menu">
|
|
||||||
<li class="header">You have 9 tasks</li>
|
|
||||||
<li>
|
|
||||||
<!-- Inner menu: contains the tasks -->
|
|
||||||
<ul class="menu">
|
|
||||||
<li>
|
|
||||||
<!-- Task item -->
|
|
||||||
<a href="#">
|
|
||||||
<!-- Task title and progress text -->
|
|
||||||
<h3>
|
|
||||||
Design some buttons
|
|
||||||
<small class="pull-right">20%</small>
|
|
||||||
</h3>
|
|
||||||
<!-- The progress bar -->
|
|
||||||
<div class="progress xs">
|
|
||||||
<!-- Change the css width attribute to simulate progress -->
|
|
||||||
<div class="progress-bar progress-bar-aqua" style="width: 20%" role="progressbar"
|
|
||||||
aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">
|
|
||||||
<span class="sr-only">20% Complete</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<!-- end task item -->
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
<li class="footer">
|
|
||||||
<a href="#">View all tasks</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
<!-- User Account Menu -->
|
|
||||||
<li id="user-menu" class="dropdown user user-menu">
|
<li id="user-menu" class="dropdown user user-menu">
|
||||||
<!-- Menu Toggle Button -->
|
@{ await Html.RenderPartialAsync("Logout", session); }
|
||||||
@if(session != null)
|
|
||||||
{
|
|
||||||
await Html.RenderPartialAsync("Logout", session);
|
|
||||||
}
|
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<!-- Control Sidebar Toggle Button -->
|
<!-- Control Sidebar Toggle Button -->
|
||||||
<li>
|
<li>
|
||||||
<a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
|
<a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
|
||||||
</li>
|
</li>
|
||||||
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
82
SeniorAssistant/Views/Shared/Notifications.cshtml
Normal file
82
SeniorAssistant/Views/Shared/Notifications.cshtml
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
@model string
|
||||||
|
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||||
|
|
||||||
|
@{
|
||||||
|
var db = dbFactory.Create();
|
||||||
|
var notifications = (from n in db.Notifications
|
||||||
|
where n.Username.Equals(Model) && n.Seen == false
|
||||||
|
orderby n.Time
|
||||||
|
select n).ToArray();
|
||||||
|
var num = notifications.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<script>
|
||||||
|
$(document).ready(
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
url: "/Account/_notification",
|
||||||
|
data: { Username: "@Model", Message: "stronzo" },
|
||||||
|
success: function (data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<a id="id-notification-toggle" href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
|
<i class="fa fa-bell-o"></i>
|
||||||
|
@if (num != 0)
|
||||||
|
{
|
||||||
|
<span class="label label-warning">@num</span>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
@if (num != 0)
|
||||||
|
{
|
||||||
|
<ul id="id-notification-drop" class="dropdown-menu">
|
||||||
|
<li class="header">You have @num notifications</li>
|
||||||
|
<li>
|
||||||
|
<!-- Inner Menu: contains the notifications -->
|
||||||
|
<ul class="menu">
|
||||||
|
@foreach (var notification in notifications)
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
<!-- start notification -->
|
||||||
|
<a id="notification-@notification.Id" href="#">
|
||||||
|
<i class="fa fa-users text-aqua">@notification.Time</i><br />
|
||||||
|
@notification.Message
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<!-- end notification -->
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<!-- <li class="footer"><a href="#">View all</a></li> -->
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var user = "@Model";
|
||||||
|
$("[id^='notification-']").on("click", function () {
|
||||||
|
var id = this.id.replace(/notification-/g, '');
|
||||||
|
var allId = this.id;
|
||||||
|
$.ajax({
|
||||||
|
type: "PUT",
|
||||||
|
dataType: "json",
|
||||||
|
url: "/Account/_notification",
|
||||||
|
data: { id: id },
|
||||||
|
success: function () {
|
||||||
|
$("#" + allId).remove();
|
||||||
|
var num = parseInt($("#id-notification-toggle span").html()) - 1;
|
||||||
|
if (num == 0) {
|
||||||
|
$("#id-notification-toggle span").remove();
|
||||||
|
$("#id-notification-drop").remove();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$("#id-notification-toggle span").html(num);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
}
|
||||||
@@ -1,15 +1,162 @@
|
|||||||
@inject IHttpContextAccessor HttpContextAccessor
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
|
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var session = HttpContextAccessor.HttpContext.Session;
|
var session = HttpContextAccessor.HttpContext.Session;
|
||||||
|
var db = dbFactory.Create();
|
||||||
|
var username = session.GetString("username");
|
||||||
|
var patientData = db.Patients.Where(p => p.Username.Equals(username)).ToArray().FirstOrDefault();
|
||||||
|
var hasDoc = patientData != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
<div class="pull-left" , style="width: 50%">
|
||||||
<h2 class="alert-success" style="text-align:center">
|
<h2 class="alert-success" style="text-align:center">
|
||||||
Welcome @session.GetString("username")
|
Welcome @username
|
||||||
|
|
||||||
</h2>
|
</h2>
|
||||||
name: @session.GetString("name")<br />
|
name: @session.GetString("name")<br />
|
||||||
lastname: @session.GetString("lastname")<br />
|
lastname: @session.GetString("lastname")<br />
|
||||||
email: @session.GetString("email")
|
email: @session.GetString("email")<br />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box pull-right" , style="width: 45%">
|
||||||
|
@if (hasDoc) // is patient and has doc, must show doc data
|
||||||
|
{
|
||||||
|
var doctor = (from u in db.Users
|
||||||
|
join d in db.Doctors on u.Username equals d.Username
|
||||||
|
where d.Username.Equals(patientData.Doctor)
|
||||||
|
select new { u.Username, u.Name, u.LastName, d.Location }).ToArray().First();
|
||||||
|
|
||||||
|
<p class="text-bold">@doctor.Name @doctor.LastName</p>
|
||||||
|
<p class="text-fuchsia">@doctor.Location</p>
|
||||||
|
<textarea class="progress-text" placeholder="Nessuna nuova nota" readonly>@patientData.Notes</textarea>
|
||||||
|
|
||||||
|
<div id="send-doc-message">
|
||||||
|
<p>Invia un messaggio al tuo dottore</p>
|
||||||
|
<textarea id="doc-message" class="progress-text" placeholder="scrivi qui">@patientData.Notes</textarea>
|
||||||
|
<button id="btn-send-message">Invia</button>
|
||||||
|
<p id="message-error" class="text-red"></p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$("#btn-send-message").on("click", function () {
|
||||||
|
var body = $("#doc-message").val().trim();
|
||||||
|
var endMessage = $("#message-error");
|
||||||
|
if (body.length < 20) {
|
||||||
|
endMessage.html("Messaggio non valido (minimo 20 caratteri)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "Account/_sendMessage",
|
||||||
|
type: "POST",
|
||||||
|
data: {
|
||||||
|
Reciver: "@doctor.Username",
|
||||||
|
Body: body
|
||||||
|
},
|
||||||
|
success: function () {
|
||||||
|
$("#doc-message").val("");
|
||||||
|
endMessage.html("Messaggio inviato");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dynamic[] data;
|
||||||
|
Type type = null;
|
||||||
|
string title = null;
|
||||||
|
var docData = db.Doctors.Where(d => d.Username.Equals(username)).ToArray().FirstOrDefault();
|
||||||
|
|
||||||
|
if (docData != null) // is DOC
|
||||||
|
{
|
||||||
|
// see all the patient of the doc
|
||||||
|
title = "Lista dei pazienti";
|
||||||
|
var patients = (from u in db.Users
|
||||||
|
join p in db.Patients on u.Username equals p.Username
|
||||||
|
where p.Doctor.Equals(docData.Username)
|
||||||
|
select new { u.Username, u.Name, u.LastName, p.Notes, Profile = "<a href=\\\"/user/" + u.Username + "\\\">Profile</a>" }).ToArray();
|
||||||
|
data = patients;
|
||||||
|
type = patients.FirstOrDefault().GetType();
|
||||||
|
}
|
||||||
|
else // is a patient and need to choose a doctor
|
||||||
|
{
|
||||||
|
// choose which doc you want
|
||||||
|
title = "Scegli un Doc";
|
||||||
|
var docs = (from u in db.Users
|
||||||
|
join d in db.Doctors on u.Username equals d.Username
|
||||||
|
select new { u.Username, u.Name, u.LastName, d.Location, Choose = "<a id=\\\"choose-" + u.Username + "\\\" href=#>Scegli</a>" }).ToArray();
|
||||||
|
data = docs;
|
||||||
|
type = docs.FirstOrDefault().GetType();
|
||||||
|
}
|
||||||
|
|
||||||
|
var fields = new List<string>();
|
||||||
|
foreach (var field in type.GetProperties())
|
||||||
|
{
|
||||||
|
fields.Add(field.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
<p>@title</p>
|
||||||
|
<div id="var-table"></div>
|
||||||
|
<script>
|
||||||
|
var datas = [
|
||||||
|
@foreach (var el in data)
|
||||||
|
{
|
||||||
|
@:{
|
||||||
|
@foreach (var field in fields)
|
||||||
|
{
|
||||||
|
@field@:: "@Html.Raw(type.GetProperty(field).GetValue(el, null))",
|
||||||
|
}
|
||||||
|
@:},
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
$("#var-table").kendoGrid({
|
||||||
|
dataSource: {
|
||||||
|
data: datas,
|
||||||
|
schema: {
|
||||||
|
model: {
|
||||||
|
fields: {
|
||||||
|
@foreach (var field in fields)
|
||||||
|
{
|
||||||
|
@field@: : { type: "@field.GetType().Name" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scrollable: true,
|
||||||
|
sortable: true,
|
||||||
|
filterable: true,
|
||||||
|
columns: [
|
||||||
|
@foreach (var field in fields)
|
||||||
|
{
|
||||||
|
@:{ field: "@field", title: "@field", template: "#=@field#" },
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
@if(docData == null) // choose a doc
|
||||||
|
{
|
||||||
|
<text>
|
||||||
|
$('[id^="choose-"]').on("click", function () {
|
||||||
|
var id = this.id.replace("choose-", '');
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "/Account/_addDoc",
|
||||||
|
data: { doctor: id },
|
||||||
|
success: function (data) {
|
||||||
|
if (data.success) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</text>
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
@using SeniorAssistant.Models
|
@using SeniorAssistant.Models;
|
||||||
|
@using SeniorAssistant.Data;
|
||||||
@using Microsoft.AspNetCore.Mvc;
|
@using Microsoft.AspNetCore.Mvc;
|
||||||
@using Microsoft.AspNetCore.Http;
|
@using Microsoft.AspNetCore.Http;
|
||||||
Binary file not shown.
Reference in New Issue
Block a user