Merge
merged commit form master that fixed most things
This commit is contained in:
@@ -6,6 +6,8 @@ using LinqToDB;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
using SeniorAssistant.Models.Users;
|
using SeniorAssistant.Models.Users;
|
||||||
|
using SeniorAssistant.Data;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
@@ -16,118 +18,119 @@ namespace IdentityDemo.Controllers
|
|||||||
public class AccountController : BaseController
|
public class AccountController : BaseController
|
||||||
{
|
{
|
||||||
private static readonly string NoteModified = "Il tuo dottore ha modificato la nota per te";
|
private static readonly string NoteModified = "Il tuo dottore ha modificato la nota per te";
|
||||||
|
private static readonly string InvalidLogIn = "Username o Password sbagliati";
|
||||||
|
private static readonly string AlreadyLogIn = "L'utente e' gia' loggato";
|
||||||
|
private static readonly string UsernameDupl = "Lo username selezionato e' gia' in uso";
|
||||||
|
private static readonly string ModNotExists = "L'oggetto da modificare non esiste";
|
||||||
|
private static readonly string AlreadyPatie = "Sei gia' un paziente";
|
||||||
|
private static readonly string DocNotExists = "Il dottore selezionato non esiste";
|
||||||
|
private static readonly string InsertAsDoct = "Ti ha inserito come il suo dottore: ";
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult _login(string username, string password)
|
public async Task<ActionResult> _login(string username, string password)
|
||||||
{
|
{
|
||||||
JsonResponse response = new JsonResponse
|
var result = await (from u in Db.Users
|
||||||
{
|
where u.Username.Equals(username)
|
||||||
Success = false,
|
&& u.Password.Equals(password)
|
||||||
Message = "Username or password is invalid."
|
select u).ToListAsync();
|
||||||
};
|
|
||||||
|
|
||||||
var result = Db.GetTable<User>().Where(user => user.Username.Equals(username) && user.Password.Equals(password)).ToListAsync().Result;
|
|
||||||
|
|
||||||
if (result.Count == 1)
|
if (result.Count == 1)
|
||||||
{
|
{
|
||||||
var loggedUser = HttpContext.Session.GetString(Username);
|
User user = result.First();
|
||||||
if (loggedUser==null || !loggedUser.Equals(username)) // non ha senso
|
HttpContext.Session.SetString(Username, username);
|
||||||
{
|
HttpContext.Session.SetString("email", user.Email);
|
||||||
User user = result.First();
|
HttpContext.Session.SetString("name", user.Name);
|
||||||
HttpContext.Session.SetString(Username, username);
|
HttpContext.Session.SetString("lastname", user.LastName);
|
||||||
HttpContext.Session.SetString("email", user.Email);
|
|
||||||
HttpContext.Session.SetString("name", user.Name);
|
|
||||||
HttpContext.Session.SetString("lastname", user.LastName);
|
|
||||||
|
|
||||||
var isDoc = (from d in Db.Doctors
|
var isDoc = (from d in Db.Doctors
|
||||||
where d.Username.Equals(username)
|
where d.Username.Equals(username)
|
||||||
select d).ToArray().FirstOrDefault() != null;
|
select d).ToArray().FirstOrDefault() != null;
|
||||||
HttpContext.Session.SetString("role", isDoc? "doctor":"patient");
|
HttpContext.Session.SetString("role", isDoc? "doctor":"patient");
|
||||||
|
|
||||||
response.Success = true;
|
return Json(OkJson);
|
||||||
response.Message = Request.Query["ReturnUrl"];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
response.Message = "User already logged";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Json(response);
|
return Json(new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = InvalidLogIn
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult _logout()
|
public ActionResult _logout()
|
||||||
{
|
{
|
||||||
HttpContext.Session.Clear();
|
HttpContext.Session.Clear();
|
||||||
return Json(new JsonResponse());
|
return Json(OkJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult _register(User user, string code = "")
|
public async Task<ActionResult> _register(User user, string code = "")
|
||||||
{
|
{
|
||||||
return Action(() =>
|
try
|
||||||
{
|
{
|
||||||
try
|
Db.Insert(user);
|
||||||
|
if (code != null && code.Equals("444442220"))
|
||||||
{
|
{
|
||||||
Db.Insert(user);
|
Db.Insert(new Doctor
|
||||||
if(code != null && code.Equals("444442220"))
|
|
||||||
{
|
{
|
||||||
Db.Insert(new Doctor
|
Username = user.Username
|
||||||
{
|
});
|
||||||
Username = user.Username
|
};
|
||||||
});
|
return await _login(user.Username, user.Password);
|
||||||
};
|
}
|
||||||
return _login(user.Username, user.Password);
|
catch
|
||||||
}
|
{
|
||||||
catch
|
return Json(new JsonResponse()
|
||||||
{
|
{
|
||||||
return Json(new JsonResponse(false, "Username already exists"));
|
Success = false,
|
||||||
}
|
Message = UsernameDupl
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult _notification(string username, string message)
|
public async Task<ActionResult> _notification(string username, string message, string redirectUrl = "#")
|
||||||
{
|
{
|
||||||
return LoggedAction(() =>
|
return await LoggedAction(() =>
|
||||||
{
|
{
|
||||||
Db.Insert(new Notification()
|
Db.Insert(new Notification()
|
||||||
{
|
{
|
||||||
Message = message,
|
Body = message,
|
||||||
Username = username,
|
Username = HttpContext.Session.GetString(Username),
|
||||||
Time = DateTime.Now,
|
Receiver = username,
|
||||||
Seen = false
|
Url = redirectUrl,
|
||||||
|
Time = DateTime.Now
|
||||||
});
|
});
|
||||||
return Json(OkJson);
|
return Json(OkJson);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
public ActionResult _notification(int id)
|
public async Task<ActionResult> _notification(int id)
|
||||||
{
|
{
|
||||||
return LoggedAction(() =>
|
return await LoggedAction(() =>
|
||||||
{
|
{
|
||||||
JsonResponse response = OkJson;
|
JsonResponse response = OkJson;
|
||||||
|
|
||||||
Notification note = Db.Notifications.Where(n => n.Id == id).ToArray().FirstOrDefault();
|
Notification note = Db.Notifications.Where(n => n.Id == id).ToArray().FirstOrDefault();
|
||||||
if(note != null)
|
if(note != null)
|
||||||
{
|
{
|
||||||
note.Seen = true;
|
note.Seen = DateTime.Now;
|
||||||
Db.Update(note);
|
Db.Update(note);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response.Success = false;
|
response.Success = false;
|
||||||
response.Message = "La notifica da modificare non esiste";
|
response.Message = ModNotExists;
|
||||||
}
|
}
|
||||||
return Json(response);
|
return Json(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult _addDoc(string doctor)
|
public async Task<ActionResult> _addDoc(string doctor)
|
||||||
{
|
{
|
||||||
return LoggedAction(() =>
|
return await LoggedAction(() =>
|
||||||
{
|
{
|
||||||
string username = HttpContext.Session.GetString(Username);
|
string username = HttpContext.Session.GetString(Username);
|
||||||
var isAlreadyPatient = Db.Patients.Where(p => p.Username.Equals(username)).ToArray().FirstOrDefault() != null;
|
var isAlreadyPatient = Db.Patients.Where(p => p.Username.Equals(username)).ToArray().FirstOrDefault() != null;
|
||||||
@@ -135,7 +138,7 @@ namespace IdentityDemo.Controllers
|
|||||||
return Json(new JsonResponse()
|
return Json(new JsonResponse()
|
||||||
{
|
{
|
||||||
Success = false,
|
Success = false,
|
||||||
Message = "You are already a patient"
|
Message = AlreadyPatie
|
||||||
});
|
});
|
||||||
|
|
||||||
var docExist = Db.Doctors.Where(d => d.Username.Equals(doctor)).ToArray().FirstOrDefault() != null;
|
var docExist = Db.Doctors.Where(d => d.Username.Equals(doctor)).ToArray().FirstOrDefault() != null;
|
||||||
@@ -143,7 +146,7 @@ namespace IdentityDemo.Controllers
|
|||||||
return Json(new JsonResponse()
|
return Json(new JsonResponse()
|
||||||
{
|
{
|
||||||
Success = false,
|
Success = false,
|
||||||
Message = "Doctor doesn't exist"
|
Message = DocNotExists
|
||||||
});
|
});
|
||||||
|
|
||||||
Db.Insert(new Patient()
|
Db.Insert(new Patient()
|
||||||
@@ -152,40 +155,65 @@ namespace IdentityDemo.Controllers
|
|||||||
Username = username
|
Username = username
|
||||||
});
|
});
|
||||||
|
|
||||||
_notification(doctor, "L'utente "+username+" ti ha inserito come il suo dottore.");
|
var a = _notification(doctor, InsertAsDoct + username);
|
||||||
return Json(new JsonResponse());
|
return Json(OkJson);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult _sendMessage(string reciver, string body)
|
public async Task<ActionResult> _sendMessage(string receiver, string body)
|
||||||
{
|
{
|
||||||
return LoggedAction(() => {
|
return await LoggedAction(() => {
|
||||||
string username = HttpContext.Session.GetString(Username);
|
string username = HttpContext.Session.GetString(Username);
|
||||||
Message message = new Message()
|
Message message = new Message()
|
||||||
{
|
{
|
||||||
Reciver = reciver,
|
Receiver = receiver,
|
||||||
Body = body,
|
Body = body,
|
||||||
Time = DateTime.Now,
|
Time = DateTime.Now,
|
||||||
Username = username,
|
Username = username
|
||||||
Seen = false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Db.Insert(message);
|
Db.Insert(message);
|
||||||
|
|
||||||
return Json(new JsonResponse());
|
return Json(OkJson);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
public ActionResult _addNote(string patient, string text)
|
public async Task<ActionResult> _addNote(string patient, string text)
|
||||||
{
|
{
|
||||||
return LoggedAccessDataOf(patient, () =>
|
return await LoggedAccessDataOf(patient, true, () =>
|
||||||
{
|
{
|
||||||
var pat = Db.Patients.Where((p) => p.Username.Equals(patient)).FirstOrDefault();
|
var pat = Db.Patients.Where((p) => p.Username.Equals(patient)).FirstOrDefault();
|
||||||
pat.Notes = text;
|
pat.Notes = text;
|
||||||
Db.Update(pat);
|
Db.Update(pat);
|
||||||
_notification(patient, NoteModified);
|
var a = _notification(patient, NoteModified);
|
||||||
|
|
||||||
|
return Json(OkJson);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut]
|
||||||
|
public async Task<ActionResult> _minHeartToPatient(string patient, int value)
|
||||||
|
{
|
||||||
|
return await LoggedAccessDataOf(patient, true, () =>
|
||||||
|
{
|
||||||
|
var pat = Db.Patients.Where((p) => p.Username.Equals(patient)).FirstOrDefault();
|
||||||
|
pat.MinHeart = value;
|
||||||
|
Db.Update(pat);
|
||||||
|
|
||||||
|
return Json(OkJson);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut]
|
||||||
|
public async Task<ActionResult> _maxHeartToPatient(string patient, int value)
|
||||||
|
{
|
||||||
|
return await LoggedAccessDataOf(patient, true, () =>
|
||||||
|
{
|
||||||
|
var pat = Db.Patients.Where((p) => p.Username.Equals(patient)).FirstOrDefault();
|
||||||
|
pat.MaxHeart = value;
|
||||||
|
Db.Update(pat);
|
||||||
|
|
||||||
return Json(OkJson);
|
return Json(OkJson);
|
||||||
});
|
});
|
||||||
@@ -193,7 +221,7 @@ namespace IdentityDemo.Controllers
|
|||||||
|
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async System.Threading.Tasks.Task<ActionResult> Save(IFormFile file)
|
public async Task<ActionResult> _save(IFormFile file)
|
||||||
{
|
{
|
||||||
return LoggedAction(() =>
|
return LoggedAction(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace SeniorAssistant.Controllers
|
namespace SeniorAssistant.Controllers
|
||||||
{
|
{
|
||||||
@@ -16,19 +17,19 @@ namespace SeniorAssistant.Controllers
|
|||||||
[Route("Heartbeat")]
|
[Route("Heartbeat")]
|
||||||
public IActionResult Heartbeat()
|
public IActionResult Heartbeat()
|
||||||
{
|
{
|
||||||
return CheckAuthorized("Heartbeat");
|
return CheckAuthorized("Data", "Heartbeat");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("Sleep")]
|
[Route("Sleep")]
|
||||||
public IActionResult Sleep()
|
public IActionResult Sleep()
|
||||||
{
|
{
|
||||||
return CheckAuthorized("Sleep");
|
return CheckAuthorized("Data", "Sleep");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("Step")]
|
[Route("Step")]
|
||||||
public IActionResult Step()
|
public IActionResult Step()
|
||||||
{
|
{
|
||||||
return CheckAuthorized("Step");
|
return CheckAuthorized("Data", "Step");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("Users")]
|
[Route("Users")]
|
||||||
@@ -40,13 +41,16 @@ namespace SeniorAssistant.Controllers
|
|||||||
[Route("User/{User}")]
|
[Route("User/{User}")]
|
||||||
public IActionResult SingleUser(string user)
|
public IActionResult SingleUser(string user)
|
||||||
{
|
{
|
||||||
return CheckAuthorized("Data", user);
|
var u = (from us in Db.Users
|
||||||
|
where us.Username.Equals(user)
|
||||||
|
select us).FirstOrDefault();
|
||||||
|
return CheckAuthorized("User", u);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("Message/{Id}")]
|
[Route("Message/{User}")]
|
||||||
public IActionResult Message(int id)
|
public IActionResult Message(string user)
|
||||||
{
|
{
|
||||||
return CheckAuthorized("Message", id);
|
return CheckAuthorized("Message", user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IActionResult CheckAuthorized(string view, object model = null)
|
private IActionResult CheckAuthorized(string view, object model = null)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SeniorAssistant.Models;
|
using SeniorAssistant.Models;
|
||||||
|
using SeniorAssistant.Models.Data;
|
||||||
using SeniorAssistant.Models.Users;
|
using SeniorAssistant.Models.Users;
|
||||||
|
|
||||||
namespace SeniorAssistant.Controllers.Services
|
namespace SeniorAssistant.Controllers.Services
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SeniorAssistant.Data;
|
using SeniorAssistant.Data;
|
||||||
|
using SeniorAssistant.Models.Users;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SeniorAssistant.Controllers
|
namespace SeniorAssistant.Controllers
|
||||||
{
|
{
|
||||||
@@ -10,12 +12,13 @@ namespace SeniorAssistant.Controllers
|
|||||||
{
|
{
|
||||||
protected static readonly string MustBeLogged = "Devi essere loggato per vedere/modificare questo dato";
|
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 InvalidModel = "Modello non valido";
|
||||||
protected static readonly string NoAuthorized = "Non sei autorizzato a vedere questi dati";
|
protected static readonly string NoAuthorized = "Non sei autorizzato ad accedere a questi dati";
|
||||||
|
protected static readonly string ExceptionSer = "Il server ha riscontrato un problema: ";
|
||||||
protected static readonly string Username = "username";
|
protected static readonly string Username = "username";
|
||||||
protected readonly JsonResponse OkJson = new JsonResponse();
|
protected readonly JsonResponse OkJson = new JsonResponse();
|
||||||
|
|
||||||
IDataContextFactory<SeniorDataContext> dbFactory;
|
private IDataContextFactory<SeniorDataContext> dbFactory;
|
||||||
SeniorDataContext db;
|
private SeniorDataContext db;
|
||||||
|
|
||||||
protected T TryResolve<T>() => (T)HttpContext.RequestServices.GetService(typeof(T));
|
protected T TryResolve<T>() => (T)HttpContext.RequestServices.GetService(typeof(T));
|
||||||
|
|
||||||
@@ -34,42 +37,45 @@ namespace SeniorAssistant.Controllers
|
|||||||
{
|
{
|
||||||
return HttpContext.Session.GetString(Username) != null;
|
return HttpContext.Session.GetString(Username) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ActionResult Action(Func<ActionResult> success)
|
protected async Task<ActionResult> LoggedAction(Func<ActionResult> success)
|
||||||
{
|
{
|
||||||
return ModelState.IsValid ?
|
try
|
||||||
success.Invoke() :
|
{
|
||||||
Json(new JsonResponse()
|
if (IsLogged())
|
||||||
|
return success.Invoke();
|
||||||
|
|
||||||
|
return Json(new JsonResponse()
|
||||||
{
|
{
|
||||||
Success = false,
|
Success = false,
|
||||||
Message = InvalidModel
|
Message = MustBeLogged
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return Json(new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = ExceptionSer + Environment.NewLine +
|
||||||
|
e.Message + Environment.NewLine +
|
||||||
|
e.StackTrace + Environment.NewLine +
|
||||||
|
e.TargetSite + Environment.NewLine +
|
||||||
|
e.InnerException
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ActionResult LoggedAction(Func<ActionResult> success)
|
protected async Task<ActionResult> LoggedAccessDataOf(string username, bool patients, Func<ActionResult> success)
|
||||||
{
|
{
|
||||||
return Action(() =>
|
return await LoggedAction(() =>
|
||||||
{
|
{
|
||||||
return IsLogged() ?
|
var session = HttpContext.Session.GetString(Username);
|
||||||
success.Invoke() :
|
var condition = username.Equals(session);
|
||||||
Json(new JsonResponse()
|
var query = from patient in Db.Patients
|
||||||
{
|
where patient.Doctor.Equals(session) && patient.Username.Equals(username)
|
||||||
Success = false,
|
select patient;
|
||||||
Message = MustBeLogged
|
var num = query.ToList().Count();
|
||||||
});
|
condition = condition || (patients && num != 0);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ActionResult LoggedAccessDataOf(string username, Func<ActionResult> success, bool patients = true)
|
|
||||||
{
|
|
||||||
return LoggedAction(() =>
|
|
||||||
{
|
|
||||||
var loggedUser = HttpContext.Session.GetString(Username);
|
|
||||||
var condition = username.Equals(loggedUser);
|
|
||||||
|
|
||||||
condition = condition || (patients && (from patient in Db.Patients
|
|
||||||
where patient.Doctor.Equals(loggedUser) && patient.Username.Equals(username)
|
|
||||||
select patient).ToArray().FirstOrDefault() != null);
|
|
||||||
|
|
||||||
return condition ?
|
return condition ?
|
||||||
success.Invoke() :
|
success.Invoke() :
|
||||||
@@ -80,6 +86,47 @@ namespace SeniorAssistant.Controllers
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static protected JsonResponse LoggedAction(SeniorDataContext db, string session, Func<JsonResponse> success)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return session != null ?
|
||||||
|
success.Invoke() :
|
||||||
|
new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = MustBeLogged
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = ExceptionSer + e.Message
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected JsonResponse LoggedAccessDataOf(SeniorDataContext db, string session, string username, bool patients, Func<JsonResponse> success)
|
||||||
|
{
|
||||||
|
return LoggedAction(db, session, () =>
|
||||||
|
{
|
||||||
|
var condition = username.Equals(session);
|
||||||
|
condition = condition || (patients && (from patient in db.Patients
|
||||||
|
where patient.Doctor.Equals(session) && patient.Username.Equals(username)
|
||||||
|
select patient).ToArray().FirstOrDefault() != null);
|
||||||
|
|
||||||
|
return condition ?
|
||||||
|
success.Invoke() :
|
||||||
|
new JsonResponse()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = NoAuthorized
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class JsonResponse
|
public class JsonResponse
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace SeniorAssistant.Controllers.Services
|
|||||||
[HttpGet("{username}")]
|
[HttpGet("{username}")]
|
||||||
public async Task<IActionResult> Read(string username)
|
public async Task<IActionResult> Read(string username)
|
||||||
{
|
{
|
||||||
return LoggedAccessDataOf(username, () =>
|
return await LoggedAccessDataOf(username, true, () =>
|
||||||
{
|
{
|
||||||
return Json(Db.GetTable<TEntity>().Where((u) => u.Username.Equals(username)).ToArray());
|
return Json(Db.GetTable<TEntity>().Where((u) => u.Username.Equals(username)).ToArray());
|
||||||
});
|
});
|
||||||
@@ -22,12 +22,12 @@ namespace SeniorAssistant.Controllers.Services
|
|||||||
[HttpPut("{username}")]
|
[HttpPut("{username}")]
|
||||||
public async Task<IActionResult> Update(string username, [FromBody] TEntity entity)
|
public async Task<IActionResult> Update(string username, [FromBody] TEntity entity)
|
||||||
{
|
{
|
||||||
return LoggedAccessDataOf(username, () =>
|
return await LoggedAccessDataOf(username, false, () =>
|
||||||
{
|
{
|
||||||
entity.Username = username;
|
entity.Username = username;
|
||||||
Db.Update(entity);
|
Db.Update(entity);
|
||||||
return Json(OkJson);
|
return Json(OkJson);
|
||||||
}, false);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using LinqToDB;
|
using LinqToDB;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SeniorAssistant.Models.Data;
|
||||||
using SeniorAssistant.Models;
|
using SeniorAssistant.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SeniorAssistant.Controllers.Services
|
namespace SeniorAssistant.Controllers.Services
|
||||||
@@ -11,6 +13,7 @@ namespace SeniorAssistant.Controllers.Services
|
|||||||
where TEntity : class, IHasTime
|
where TEntity : class, IHasTime
|
||||||
{
|
{
|
||||||
private static readonly string DateNotCorrect = "Il formato della data non e' corretto";
|
private static readonly string DateNotCorrect = "Il formato della data non e' corretto";
|
||||||
|
private static readonly string AnomalDataHear = "Valore dei battiti cardiaci anomalo";
|
||||||
|
|
||||||
[HttpGet("{username}/{date:regex((today|\\d{{4}}-\\d{{2}}-\\d{{2}}))}/{hour:range(0, 23)?}")]
|
[HttpGet("{username}/{date:regex((today|\\d{{4}}-\\d{{2}}-\\d{{2}}))}/{hour:range(0, 23)?}")]
|
||||||
public async Task<IActionResult> Read(string username, string date, int hour = -1) => await Read(username, date, date, hour);
|
public async Task<IActionResult> Read(string username, string date, int hour = -1) => await Read(username, date, date, hour);
|
||||||
@@ -18,7 +21,7 @@ namespace SeniorAssistant.Controllers.Services
|
|||||||
[HttpGet("{username}/{from:regex((today|\\d{{4}}-\\d{{2}}-\\d{{2}}))}/{to:regex((today|\\d{{4}}-\\d{{2}}-\\d{{2}}))}/{hour:range(0, 23)?}")]
|
[HttpGet("{username}/{from:regex((today|\\d{{4}}-\\d{{2}}-\\d{{2}}))}/{to:regex((today|\\d{{4}}-\\d{{2}}-\\d{{2}}))}/{hour:range(0, 23)?}")]
|
||||||
public async Task<IActionResult> Read(string username, string from, string to, int hour = -1)
|
public async Task<IActionResult> Read(string username, string from, string to, int hour = -1)
|
||||||
{
|
{
|
||||||
return LoggedAccessDataOf(username, () =>
|
return await LoggedAccessDataOf(username, true, () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -42,7 +45,7 @@ namespace SeniorAssistant.Controllers.Services
|
|||||||
[HttpGet("{username}/last/{hour:min(1)}")]
|
[HttpGet("{username}/last/{hour:min(1)}")]
|
||||||
public async Task<IActionResult> Read(string username, int hour)
|
public async Task<IActionResult> Read(string username, int hour)
|
||||||
{
|
{
|
||||||
return LoggedAccessDataOf(username, () =>
|
return await LoggedAccessDataOf(username, true, () =>
|
||||||
{
|
{
|
||||||
DateTime date = DateTime.Now.AddHours(-hour);
|
DateTime date = DateTime.Now.AddHours(-hour);
|
||||||
return Json((from entity in Db.GetTable<TEntity>()
|
return Json((from entity in Db.GetTable<TEntity>()
|
||||||
@@ -53,24 +56,42 @@ namespace SeniorAssistant.Controllers.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Create([FromBody]TEntity item)
|
public async Task<IActionResult> Create(TEntity item)
|
||||||
{
|
{
|
||||||
return Action(() =>
|
return await LoggedAccessDataOf(item.Username, false, () =>
|
||||||
{
|
{
|
||||||
Db.Insert(item);
|
Db.Insert(item);
|
||||||
|
|
||||||
|
if (item is Heartbeat temp)
|
||||||
|
{
|
||||||
|
var result = (from p in Db.Patients
|
||||||
|
where p.Username.Equals(item.Username)
|
||||||
|
select p).ToArray().FirstOrDefault();
|
||||||
|
if (result.MinHeart > temp.Value || result.MaxHeart < temp.Value)
|
||||||
|
{
|
||||||
|
var date = WebUtility.UrlEncode(item.Time.ToString("yyyy/MM/dd"));
|
||||||
|
Db.Insert(new Notification() {
|
||||||
|
Username = item.Username,
|
||||||
|
Receiver = result.Doctor,
|
||||||
|
Body = item.Username + ":" + AnomalDataHear,
|
||||||
|
Url = "/user/" + item.Username + "?from=" + date + "&to=" + date,
|
||||||
|
Time = DateTime.Now
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Json(OkJson);
|
return Json(OkJson);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
public async Task<IActionResult> Update([FromBody]TEntity item)
|
public async Task<IActionResult> Update(TEntity item)
|
||||||
{
|
{
|
||||||
return LoggedAccessDataOf(item.Username, () =>
|
return await LoggedAccessDataOf(item.Username, false, () =>
|
||||||
{
|
{
|
||||||
var e = Read(item.Username, item.Time);
|
if (Read(item.Username, item.Time) == null)
|
||||||
if (e == null)
|
|
||||||
{
|
{
|
||||||
Create(item);
|
var a = Create(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -78,7 +99,7 @@ namespace SeniorAssistant.Controllers.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Json(OkJson);
|
return Json(OkJson);
|
||||||
}, false);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[NonAction]
|
[NonAction]
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
using LinqToDB;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using LinqToDB;
|
||||||
using LinqToDB.Data;
|
using LinqToDB.Data;
|
||||||
using LinqToDB.DataProvider;
|
using LinqToDB.DataProvider;
|
||||||
using SeniorAssistant.Models;
|
using SeniorAssistant.Models;
|
||||||
|
using SeniorAssistant.Models.Data;
|
||||||
using SeniorAssistant.Models.Users;
|
using SeniorAssistant.Models.Users;
|
||||||
|
|
||||||
namespace SeniorAssistant.Data
|
namespace SeniorAssistant.Data
|
||||||
@@ -20,5 +23,37 @@ namespace SeniorAssistant.Data
|
|||||||
public ITable<Patient> Patients => GetTable<Patient>();
|
public ITable<Patient> Patients => GetTable<Patient>();
|
||||||
public ITable<Notification> Notifications => GetTable<Notification>();
|
public ITable<Notification> Notifications => GetTable<Notification>();
|
||||||
public ITable<Message> Messages => GetTable<Message>();
|
public ITable<Message> Messages => GetTable<Message>();
|
||||||
|
|
||||||
|
public T[] GetLastMessages<T>(ITable<T> table, string receiver, ref int numNotSeen, int max = 10)
|
||||||
|
where T : IHasMessage
|
||||||
|
{
|
||||||
|
var notSeen = (from t in table
|
||||||
|
where t.Receiver.Equals(receiver) && t.Seen == default
|
||||||
|
orderby t.Time descending
|
||||||
|
select t).Take(max).ToArray();
|
||||||
|
var messages = new T[max];
|
||||||
|
numNotSeen = notSeen.Length;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < numNotSeen; i++)
|
||||||
|
{
|
||||||
|
messages[i] = notSeen[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (numNotSeen < max)
|
||||||
|
{
|
||||||
|
var messSeen = (from t in table
|
||||||
|
where t.Receiver.Equals(receiver) && t.Seen != default
|
||||||
|
orderby t.Time descending
|
||||||
|
select t).Take(max - numNotSeen).ToArray();
|
||||||
|
|
||||||
|
foreach (var m in messSeen)
|
||||||
|
{
|
||||||
|
messages[i] = m;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using LinqToDB.Mapping;
|
using LinqToDB.Mapping;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SeniorAssistant.Models
|
namespace SeniorAssistant.Models.Data
|
||||||
{
|
{
|
||||||
public class Heartbeat : IHasTime
|
public class Heartbeat : IHasTime
|
||||||
{
|
{
|
||||||
@@ -14,10 +14,5 @@ namespace SeniorAssistant.Models
|
|||||||
public DateTime Time { get; set; }
|
public DateTime Time { get; set; }
|
||||||
|
|
||||||
public double Value { get; set; }
|
public double Value { get; set; }
|
||||||
|
|
||||||
/*
|
|
||||||
[Association(ThisKey = nameof(Username), OtherKey = nameof(User.Username), CanBeNull = false)]
|
|
||||||
public User UserObj { get; set; }
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using LinqToDB.Mapping;
|
using LinqToDB.Mapping;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SeniorAssistant.Models
|
namespace SeniorAssistant.Models.Data
|
||||||
{
|
{
|
||||||
public class Sleep : IHasTime
|
public class Sleep : IHasTime
|
||||||
{
|
{
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using LinqToDB.Mapping;
|
using LinqToDB.Mapping;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SeniorAssistant.Models
|
namespace SeniorAssistant.Models.Data
|
||||||
{
|
{
|
||||||
public class Step : IHasTime
|
public class Step : IHasTime
|
||||||
{
|
{
|
||||||
14
SeniorAssistant/Models/Interfaces/IHasMessage.cs
Normal file
14
SeniorAssistant/Models/Interfaces/IHasMessage.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using LinqToDB.Mapping;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace SeniorAssistant.Models
|
||||||
|
{
|
||||||
|
public interface IHasMessage : IHasTime
|
||||||
|
{
|
||||||
|
string Receiver { get; set; }
|
||||||
|
|
||||||
|
string Body { get; set; }
|
||||||
|
|
||||||
|
DateTime Seen { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ using System;
|
|||||||
|
|
||||||
namespace SeniorAssistant.Models
|
namespace SeniorAssistant.Models
|
||||||
{
|
{
|
||||||
public class Message : IHasTime
|
public class Message : IHasMessage
|
||||||
{
|
{
|
||||||
[Column(IsPrimaryKey = true, CanBeNull = false, IsIdentity = true)]
|
[Column(IsPrimaryKey = true, CanBeNull = false, IsIdentity = true)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@@ -13,14 +13,12 @@ namespace SeniorAssistant.Models
|
|||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public string Reciver { get; set; }
|
public string Receiver { get; set; }
|
||||||
|
|
||||||
[NotNull]
|
|
||||||
public string Body { get; set; }
|
public string Body { get; set; }
|
||||||
|
|
||||||
public bool Seen { get; set; }
|
public DateTime Seen { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System;
|
|||||||
|
|
||||||
namespace SeniorAssistant.Models
|
namespace SeniorAssistant.Models
|
||||||
{
|
{
|
||||||
public class Notification : IHasTime
|
public class Notification : IHasMessage
|
||||||
{
|
{
|
||||||
[Column(IsPrimaryKey = true, CanBeNull = false, IsIdentity = true)]
|
[Column(IsPrimaryKey = true, CanBeNull = false, IsIdentity = true)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@@ -13,9 +13,14 @@ namespace SeniorAssistant.Models
|
|||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public DateTime Time { get; set; }
|
public DateTime Time { get; set; }
|
||||||
|
|
||||||
public bool Seen { get; set; }
|
[NotNull]
|
||||||
|
public string Receiver { get; set; }
|
||||||
public string Message { get; set; }
|
|
||||||
|
public string Body { get; set; }
|
||||||
|
|
||||||
|
public string Url { get; set; }
|
||||||
|
|
||||||
|
public DateTime Seen { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,10 @@ namespace SeniorAssistant.Models.Users
|
|||||||
[Column(IsPrimaryKey = true, CanBeNull = false)]
|
[Column(IsPrimaryKey = true, CanBeNull = false)]
|
||||||
public string Username { get; set; }
|
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 Location { get; set; }
|
||||||
|
|
||||||
public string Schedule { get; set; }
|
public string Schedule { get; set; }
|
||||||
|
|
||||||
|
public string PhoneNumber { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ namespace SeniorAssistant.Models.Users
|
|||||||
[Column(IsPrimaryKey = true, CanBeNull = false)]
|
[Column(IsPrimaryKey = true, CanBeNull = false)]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
|
|
||||||
[Association(ThisKey = "Username", OtherKey = nameof(User.Username), CanBeNull = false)]
|
|
||||||
public User UserData { get; set; }
|
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public string Doctor { get; set; }
|
public string Doctor { get; set; }
|
||||||
|
|
||||||
public string Notes { get; set; }
|
public string Notes { get; set; }
|
||||||
|
|
||||||
|
public int MaxHeart { get; set; }
|
||||||
|
|
||||||
|
public int MinHeart { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
<DockerTargetOS>Windows</DockerTargetOS>
|
<DockerTargetOS>Windows</DockerTargetOS>
|
||||||
<UserSecretsId>7506fc54-8ed1-4c9b-9004-35d36db99964</UserSecretsId>
|
<UserSecretsId>7506fc54-8ed1-4c9b-9004-35d36db99964</UserSecretsId>
|
||||||
|
<LangVersion>7.1</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using SeniorAssistant.Configuration;
|
using SeniorAssistant.Configuration;
|
||||||
using SeniorAssistant.Data;
|
using SeniorAssistant.Data;
|
||||||
using SeniorAssistant.Models;
|
using SeniorAssistant.Models;
|
||||||
|
using SeniorAssistant.Models.Data;
|
||||||
|
using SeniorAssistant.Models.Users;
|
||||||
using SeniorAssistant.Extensions;
|
using SeniorAssistant.Extensions;
|
||||||
using Swashbuckle.AspNetCore.Swagger;
|
using Swashbuckle.AspNetCore.Swagger;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using SeniorAssistant.Models.Users;
|
|
||||||
|
|
||||||
namespace SeniorAssistant
|
namespace SeniorAssistant
|
||||||
{
|
{
|
||||||
@@ -71,21 +72,6 @@ namespace SeniorAssistant
|
|||||||
// .AddEntityFrameworkStores<ApplicationDbContext>();
|
// .AddEntityFrameworkStores<ApplicationDbContext>();
|
||||||
|
|
||||||
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||||
services.AddSingleton<IList<IMenuItem>>(new List<IMenuItem>
|
|
||||||
{
|
|
||||||
new MenuItem("Index", "/"),
|
|
||||||
new SubMenu()
|
|
||||||
{
|
|
||||||
Text = "Raw Data",
|
|
||||||
Items = new MenuItem[]
|
|
||||||
{
|
|
||||||
new MenuItem("Users", "/users"),
|
|
||||||
new MenuItem("Heartbeat", "/heartbeat"),
|
|
||||||
new MenuItem("Sleep", "/sleep"),
|
|
||||||
new MenuItem("Step", "/step")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var dbFactory = new SeniorDataContextFactory(
|
var dbFactory = new SeniorDataContextFactory(
|
||||||
dataProvider: SQLiteTools.GetDataProvider(),
|
dataProvider: SQLiteTools.GetDataProvider(),
|
||||||
@@ -131,7 +117,7 @@ namespace SeniorAssistant
|
|||||||
|
|
||||||
app.Run(async (context) =>
|
app.Run(async (context) =>
|
||||||
{
|
{
|
||||||
await context.Response.WriteAsync("Oops, something went wrong");
|
await context.Response.WriteAsync("Oops, this page doesn't exist");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,154 +1,57 @@
|
|||||||
@inject IHttpContextAccessor HttpContextAccessor
|
@model string
|
||||||
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
@inject IHttpContextAccessor Http
|
||||||
@model string
|
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewBag.Title = "Hello Razor";
|
ViewBag.Title = "Hello Razor";
|
||||||
var session = HttpContextAccessor.HttpContext.Session;
|
var session = Http.HttpContext.Session.GetString("username");
|
||||||
var username = session.GetString("username");
|
|
||||||
|
|
||||||
bool auth = username.Equals(Model);
|
|
||||||
bool isDoc = session.GetString("role").Equals("doctor");
|
|
||||||
Patient patient = null;
|
|
||||||
if (isDoc)
|
|
||||||
{
|
|
||||||
var db = dbFactory.Create();
|
|
||||||
patient = (from p in db.Patients
|
|
||||||
where p.Username.Equals(Model) && p.Doctor.Equals(username)
|
|
||||||
select p).ToArray().FirstOrDefault();
|
|
||||||
auth = auth || patient != null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (!auth)
|
<div id="grid"></div>
|
||||||
{
|
|
||||||
<p class="box-title text-red">Non sei autorizzato a vedere i dati di @Model</p>
|
<script>
|
||||||
}
|
$(document).ready(function () {
|
||||||
else
|
var baseUrl = "@Url.Content("~/api/" + Model + "/" + session + "/today")";
|
||||||
{
|
|
||||||
// Aggiungere un qualcosa per scegliere le ore da vedere (Max 48?)
|
$("#grid").kendoGrid({
|
||||||
<div>
|
dataSource: {
|
||||||
<input id="hours-data" type="text" placeholder="hours" value="24" />
|
transport: {
|
||||||
<button id="refresh-hours" class="fc-button">Cambia ora</button>
|
read: {
|
||||||
<div id="chart-data"></div>
|
url: baseUrl,
|
||||||
</div>
|
type: "GET"
|
||||||
@if(isDoc && patient != null)
|
|
||||||
{
|
|
||||||
<div>
|
|
||||||
<textarea id="note-area" placeholder="Scrivi una nota..">@patient.Notes</textarea>
|
|
||||||
<button id="send-note" class="btn">Salva</button>
|
|
||||||
<p id="note-error"></p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
$("#send-note").on("click", function () {
|
|
||||||
var text = $("#note-area").val().trim();
|
|
||||||
$.ajax({
|
|
||||||
url: "/Account/_addNote",
|
|
||||||
type: "PUT",
|
|
||||||
data: {
|
|
||||||
Patient: "@Model", Text: text
|
|
||||||
},
|
|
||||||
success: function (data) {
|
|
||||||
$("#note-error").html(data.success?"Nota salvata":data.message);
|
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
});
|
serverPaging: false,
|
||||||
</script>
|
serverSorting: false,
|
||||||
}
|
batch: false,
|
||||||
|
schema: {
|
||||||
|
model: {
|
||||||
|
id: "username",
|
||||||
<script>
|
fields: {
|
||||||
$("#hours-data").on("change keyup paste click", function () {
|
username: { type: "string" },
|
||||||
var t = $(this);
|
time: { type: "date" },
|
||||||
t.val(t.val().replace(/[^0-9]/g, '').substring(0, 2));
|
value: { type: "number" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scrollable: true,
|
||||||
|
sortable: true,
|
||||||
|
filterable: true,
|
||||||
|
editable: false,
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: "username",
|
||||||
|
title: "Username"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: "time",
|
||||||
|
title: "Date/Time",
|
||||||
|
format: "{0:dd/MM/yyyy HH:mm}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: "value",
|
||||||
|
title: "@Model"
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
$("#refresh-hours").on("click", function () {
|
});
|
||||||
var hours = $("#hours-data").val();
|
</script>
|
||||||
var base_url = "@Url.Content("~/api/")";
|
|
||||||
var end_url = "/@Model/last/" + hours;
|
|
||||||
|
|
||||||
$.getJSON(base_url + "heartbeat" + end_url, function (heartbeat) {
|
|
||||||
$.getJSON(base_url + "step" + end_url, function (steps) {
|
|
||||||
$.getJSON(base_url + "sleep" + end_url, function (sleep) {
|
|
||||||
var sleepArr = [];
|
|
||||||
sleep.forEach( function (el) {
|
|
||||||
sleepArr.push({ "time": el.time, "value": 1 });
|
|
||||||
var base_time = new Date(el.time).getTime();
|
|
||||||
|
|
||||||
for (var i = 60000; i <= el.value; i += 60000) {
|
|
||||||
sleepArr.push({ "time": new Date(base_time + i), "value": 1 });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#chart-data").kendoChart({
|
|
||||||
title: { text: "Visualizzazione attivita' di @Model" },
|
|
||||||
legend: { position: "bottom" },
|
|
||||||
seriesDefaults: {
|
|
||||||
type: "line",
|
|
||||||
style: "smooth"
|
|
||||||
},
|
|
||||||
series: [{
|
|
||||||
name: "Battito",
|
|
||||||
field: "value",
|
|
||||||
color: "red",
|
|
||||||
axis: "Heartbeat",
|
|
||||||
categoryField: "time",
|
|
||||||
data: heartbeat,
|
|
||||||
tooltip: {
|
|
||||||
visible: true,
|
|
||||||
format: "{0}%",
|
|
||||||
template: "Media di: #= value # bpm"
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
name: "Passi",
|
|
||||||
field: "value",
|
|
||||||
color: "blue",
|
|
||||||
axis: "Steps",
|
|
||||||
categoryField: "time",
|
|
||||||
data: steps,
|
|
||||||
tooltip: {
|
|
||||||
visible: true,
|
|
||||||
format: "{0}%",
|
|
||||||
template: "#= series.name #: #= value #"
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
type: "area",
|
|
||||||
name: "Sonno",
|
|
||||||
field: "value",
|
|
||||||
color: "black",
|
|
||||||
axis: "Sleep",
|
|
||||||
categoryField: "time",
|
|
||||||
data: sleepArr
|
|
||||||
}],
|
|
||||||
categoryAxis: {
|
|
||||||
labels: {
|
|
||||||
rotation: +45,
|
|
||||||
dateFormats: {
|
|
||||||
hours: "HH:mm"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
type: "Date",
|
|
||||||
baseUnit: "hours"
|
|
||||||
},
|
|
||||||
valueAxes: [{
|
|
||||||
name: "Heartbeat",
|
|
||||||
color: "red"
|
|
||||||
}, {
|
|
||||||
name: "Steps",
|
|
||||||
color: "blue"
|
|
||||||
}, {
|
|
||||||
name: "Sleep",
|
|
||||||
color: "gray",
|
|
||||||
visible: false,
|
|
||||||
max: 1,
|
|
||||||
min: 0
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$("#refresh-hours").click();
|
|
||||||
</script>
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
@{
|
|
||||||
ViewBag.Title = "Hello Razor";
|
|
||||||
}
|
|
||||||
|
|
||||||
<div id="grid"></div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
$(document).ready(function () {
|
|
||||||
var baseUrl = "@Url.Content("~/api/heartbeat/")";
|
|
||||||
|
|
||||||
$("#grid").kendoGrid({
|
|
||||||
dataSource: {
|
|
||||||
transport: {
|
|
||||||
read: { url: baseUrl, type: "GET" }
|
|
||||||
},
|
|
||||||
serverPaging: false,
|
|
||||||
serverSorting: false,
|
|
||||||
batch: false,
|
|
||||||
schema: {
|
|
||||||
model: {
|
|
||||||
id: "username",
|
|
||||||
fields: {
|
|
||||||
username: { type: "string" },
|
|
||||||
time: { type: "date" },
|
|
||||||
value: {type: "number" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scrollable: true,
|
|
||||||
sortable: true,
|
|
||||||
filterable: true,
|
|
||||||
editable: false,
|
|
||||||
columns: [
|
|
||||||
{ field: "username", title: "Username" },
|
|
||||||
{ field: "time", title: "Date/Time", format: "{0:dd/MM/yyyy HH:mm}" },
|
|
||||||
{ field: "value", title: "Heartbeats" }
|
|
||||||
]
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
@model int
|
@model string
|
||||||
@inject IHttpContextAccessor HttpContextAccessor
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||||
@using LinqToDB;
|
@using LinqToDB;
|
||||||
@@ -7,24 +7,81 @@
|
|||||||
ViewBag.Title = "Hello Razor";
|
ViewBag.Title = "Hello Razor";
|
||||||
string username = HttpContextAccessor.HttpContext.Session.GetString("username");
|
string username = HttpContextAccessor.HttpContext.Session.GetString("username");
|
||||||
var db = dbFactory.Create();
|
var db = dbFactory.Create();
|
||||||
var message = (from m in db.Messages
|
var user = (from u in db.Users
|
||||||
where m.Id.Equals(Model) && m.Reciver.Equals(username)
|
where u.Username.Equals(Model)
|
||||||
select m).ToArray().FirstOrDefault();
|
select u).FirstOrDefault();
|
||||||
|
var messages = (from m in db.Messages
|
||||||
|
where (m.Username.Equals(Model) && m.Receiver.Equals(username))
|
||||||
|
||(m.Receiver.Equals(Model) && m.Username.Equals(username))
|
||||||
|
orderby m.Time ascending
|
||||||
|
select m).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@if (message == null)
|
@if (messages.Count() == 0)
|
||||||
{
|
{
|
||||||
<p class="text-red">Non hai il permesso</p>
|
<p class="text-red">Non hai messaggi</p>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
message.Seen = true;
|
<h3 class="text-bold">Messaggi con @user.Name @user.LastName</h3>
|
||||||
db.Update(message);
|
|
||||||
<p>Messaggio da @message.Username</p>
|
foreach (var message in messages)
|
||||||
<p>Inviato il @message.Time</p>
|
{
|
||||||
<div class="info-box-text">
|
if (message.Seen == default && message.Receiver.Equals(username))
|
||||||
@message.Body
|
{
|
||||||
</div>
|
message.Seen = DateTime.Now;
|
||||||
|
db.Update(message);
|
||||||
|
}
|
||||||
|
<div>
|
||||||
|
@if (message.Receiver.Equals(username))
|
||||||
|
{
|
||||||
|
<div class="pull-left"></div>
|
||||||
|
<div class="pull-right-container bg-light-blue">
|
||||||
|
<span style="white-space: pre-line" class="">@message.Body</span>
|
||||||
|
<p class="text-aqua">@message.Seen</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="pull-right-container bg-green-gradient">
|
||||||
|
<div style="white-space: pre-line" class="">@message.Body</div>
|
||||||
|
<p class="text-aqua">@message.Seen</p>
|
||||||
|
</div>
|
||||||
|
<div class="pull-right"></div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
<div class="pull-right">
|
||||||
|
<textarea id="res-message" class="progress-text" placeholder="Scrivi qui per scrivere un messaggio"></textarea>
|
||||||
|
<button id="btn-send-message">Invia</button>
|
||||||
|
<p id="message-error" class="text-red"></p>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
$("#btn-send-message").on("click", function () {
|
||||||
|
var min = 10;
|
||||||
|
var body = $("#res-message").val().trim();
|
||||||
|
var endMessage = $("#message-error");
|
||||||
|
if (body.length < min) {
|
||||||
|
endMessage.html("Messaggio non valido (minimo " + min + " caratteri)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/Account/_sendMessage",
|
||||||
|
type: "POST",
|
||||||
|
data: {
|
||||||
|
Receiver: "@Model",
|
||||||
|
Body: body
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
console.log(data);
|
||||||
|
$("#res-message").val("");
|
||||||
|
endMessage.html("Messaggio inviato");
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
@{
|
|
||||||
ViewBag.Title = "Hello Razor";
|
|
||||||
}
|
|
||||||
|
|
||||||
<div id="grid"></div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
$(document).ready(function () {
|
|
||||||
var baseUrl = "@Url.Content("~/api/sleep/")";
|
|
||||||
|
|
||||||
$("#grid").kendoGrid({
|
|
||||||
dataSource: {
|
|
||||||
transport: {
|
|
||||||
read: { url: baseUrl, type: "GET" }
|
|
||||||
},
|
|
||||||
serverPaging: false,
|
|
||||||
serverSorting: false,
|
|
||||||
batch: false,
|
|
||||||
schema: {
|
|
||||||
model: {
|
|
||||||
id: "username",
|
|
||||||
fields: {
|
|
||||||
username: { type: "string", },
|
|
||||||
time: { type: "date" },
|
|
||||||
value: { type: "number" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scrollable: true,
|
|
||||||
sortable: true,
|
|
||||||
filterable: true,
|
|
||||||
editable: false,
|
|
||||||
columns: [
|
|
||||||
{ field: "username", title: "Username" },
|
|
||||||
{ field: "time", title: "Date/Time", format: "{0:dd/MM/yyyy HH:mm}" },
|
|
||||||
{ field: "value", title: "Sleep Time", format: "{n2}", template: '${value/3600000}' }
|
|
||||||
]
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
@{
|
|
||||||
ViewBag.Title = "Hello Razor";
|
|
||||||
}
|
|
||||||
|
|
||||||
<div id="grid"></div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
$(document).ready(function () {
|
|
||||||
var baseUrl = "@Url.Content("~/api/step/")";
|
|
||||||
|
|
||||||
$("#grid").kendoGrid({
|
|
||||||
dataSource: {
|
|
||||||
transport: {
|
|
||||||
read: { url: baseUrl, type: "GET" }
|
|
||||||
},
|
|
||||||
serverPaging: false,
|
|
||||||
serverSorting: false,
|
|
||||||
batch: false,
|
|
||||||
schema: {
|
|
||||||
model: {
|
|
||||||
id: "username",
|
|
||||||
fields: {
|
|
||||||
username: { type: "string", },
|
|
||||||
time: { type: "date" },
|
|
||||||
value: { type: "number" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scrollable: true,
|
|
||||||
sortable: true,
|
|
||||||
filterable: true,
|
|
||||||
editable: false,
|
|
||||||
columns: [
|
|
||||||
{ field: "username", title: "Username" },
|
|
||||||
{ field: "time", title: "Date/Time", format: "{0:dd/MM/yyyy HH:mm}" },
|
|
||||||
{ field: "value", title: "Steps done" }
|
|
||||||
]
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
|
||||||
184
SeniorAssistant/Views/Home/User.cshtml
Normal file
184
SeniorAssistant/Views/Home/User.cshtml
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
|
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||||
|
@model User
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "Hello Razor";
|
||||||
|
var session = HttpContextAccessor.HttpContext.Session;
|
||||||
|
var username = session.GetString("username");
|
||||||
|
|
||||||
|
bool auth = username.Equals(Model.Username);
|
||||||
|
bool isDoc = session.GetString("role").Equals("doctor");
|
||||||
|
Patient patient = null;
|
||||||
|
if (isDoc)
|
||||||
|
{
|
||||||
|
var db = dbFactory.Create();
|
||||||
|
patient = (from p in db.Patients
|
||||||
|
where p.Username.Equals(Model.Username) && p.Doctor.Equals(username)
|
||||||
|
select p).ToArray().FirstOrDefault();
|
||||||
|
auth = auth || patient != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (!auth)
|
||||||
|
{
|
||||||
|
<p class="box-title text-red">Non sei autorizzato a vedere i dati di @Model.Name @Model.LastName</p>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
@if (isDoc && patient != null)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
<textarea id="note-area" placeholder="Scrivi una nota..">@patient.Notes</textarea>
|
||||||
|
<button id="send-note" class="btn">Salva</button>
|
||||||
|
<p id="note-error"></p>
|
||||||
|
</div>
|
||||||
|
<a class="" href="/Message/@patient.Username">Invia un messaggio al tuo paziente</a>
|
||||||
|
<div>
|
||||||
|
<p>Inserisci un minimo o massimo valore per il battito cardiaco</p>
|
||||||
|
<p>Se il valore del battito del paziente supera i valori che hai inserito verrai notificato</p>
|
||||||
|
<label>Max:</label>
|
||||||
|
<input id="maxHeart" placeholder="max" value="@patient.MaxHeart" />
|
||||||
|
<label>Min:</label>
|
||||||
|
<input id="minHeart" placeholder="min" value="@patient.MinHeart" />
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
$("#send-note").on("click", function () {
|
||||||
|
var text = $("#note-area").val().trim();
|
||||||
|
$.ajax({
|
||||||
|
url: "/Account/_addNote",
|
||||||
|
type: "PUT",
|
||||||
|
data: {
|
||||||
|
Patient: "@Model.Username", Text: text
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
$("#note-error").html(data.success ? "Nota salvata" : data.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$("#maxHeart, #minHeart").on("change keyup paste click", function () {
|
||||||
|
onlyNum($(this));
|
||||||
|
});
|
||||||
|
$("#maxHeart, #minHeart").on("blur", function () {
|
||||||
|
var value = parseInt($(this).val());
|
||||||
|
var id = $(this).attr("id");
|
||||||
|
$.ajax({
|
||||||
|
url: "/Account/_" + id + "ToPatient",
|
||||||
|
type: "PUT",
|
||||||
|
data: {
|
||||||
|
Patient: "@Model.Username",
|
||||||
|
Value: value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function onlyNum(object, numChar = 3) {
|
||||||
|
object.val(object.val().replace(/[^0-9]/g, '').substring(0, numChar));
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#hours-data").on("change keyup paste click", function () {
|
||||||
|
onlyNum($(this), 2);
|
||||||
|
});
|
||||||
|
$("#refresh-hours").on("click", function () {
|
||||||
|
var hours = $("#hours-data").val();
|
||||||
|
var base_url = "@Url.Content("~/api/")";
|
||||||
|
var end_url = "/@Model.Username/last/" + hours;
|
||||||
|
|
||||||
|
$.getJSON(base_url + "heartbeat" + end_url, function (heartbeat) {
|
||||||
|
$.getJSON(base_url + "step" + end_url, function (steps) {
|
||||||
|
$.getJSON(base_url + "sleep" + end_url, function (sleep) {
|
||||||
|
var sleepArr = [];
|
||||||
|
|
||||||
|
sleep.forEach(function (el) {
|
||||||
|
sleepArr.push({ "time": el.time, "value": 1 });
|
||||||
|
var base_time = new Date(el.time).getTime();
|
||||||
|
|
||||||
|
for (var i = 60000; i <= el.value; i += 60000) {
|
||||||
|
sleepArr.push({ "time": new Date(base_time + i), "value": 1 });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (Object.keys(heartbeat).length == 0
|
||||||
|
&& Object.keys(steps).length == 0
|
||||||
|
&& Object.keys(sleep).length == 0)
|
||||||
|
$("#chart-data").html("Nessun dato");
|
||||||
|
else
|
||||||
|
$("#chart-data").kendoChart({
|
||||||
|
title: { text: "Visualizzazione attivita' di @Model.Name @Model.LastName" },
|
||||||
|
legend: { position: "bottom" },
|
||||||
|
seriesDefaults: {
|
||||||
|
type: "line",
|
||||||
|
style: "smooth"
|
||||||
|
},
|
||||||
|
series: [{
|
||||||
|
name: "Battito",
|
||||||
|
field: "value",
|
||||||
|
color: "red",
|
||||||
|
axis: "Heartbeat",
|
||||||
|
categoryField: "time",
|
||||||
|
data: heartbeat,
|
||||||
|
tooltip: {
|
||||||
|
visible: true,
|
||||||
|
format: "{0}%",
|
||||||
|
template: "Media di: #= value # bpm"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
name: "Passi",
|
||||||
|
field: "value",
|
||||||
|
color: "blue",
|
||||||
|
axis: "Steps",
|
||||||
|
categoryField: "time",
|
||||||
|
data: steps,
|
||||||
|
tooltip: {
|
||||||
|
visible: true,
|
||||||
|
format: "{0}%",
|
||||||
|
template: "#= series.name #: #= value #"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
type: "area",
|
||||||
|
name: "Sonno",
|
||||||
|
field: "value",
|
||||||
|
color: "black",
|
||||||
|
axis: "Sleep",
|
||||||
|
categoryField: "time",
|
||||||
|
data: sleepArr
|
||||||
|
}],
|
||||||
|
categoryAxis: {
|
||||||
|
labels: {
|
||||||
|
rotation: +45,
|
||||||
|
dateFormats: {
|
||||||
|
hours: "HH:mm"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
type: "Date",
|
||||||
|
baseUnit: "hours"
|
||||||
|
},
|
||||||
|
valueAxes: [{
|
||||||
|
name: "Heartbeat",
|
||||||
|
color: "red"
|
||||||
|
}, {
|
||||||
|
name: "Steps",
|
||||||
|
color: "blue"
|
||||||
|
}, {
|
||||||
|
name: "Sleep",
|
||||||
|
color: "gray",
|
||||||
|
visible: false,
|
||||||
|
max: 1,
|
||||||
|
min: 0
|
||||||
|
}]
|
||||||
|
}); /* Kendo */
|
||||||
|
}); /* sleep */
|
||||||
|
}); /* steps */
|
||||||
|
}); /* heart */
|
||||||
|
}); /* click */
|
||||||
|
$("#refresh-hours").click();
|
||||||
|
</script>
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
<!-- hidden-xs hides the username on small devices so only the image appears. -->
|
<!-- hidden-xs hides the username on small devices so only the image appears. -->
|
||||||
<span id="user-name" class="hidden-xs">@Model</span>
|
<span id="user-name" class="hidden-xs">@Model</span>
|
||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu" style="box-shadow: black 0px 0px 2px">
|
||||||
<!-- The user image in the menu -->
|
<!-- The user image in the menu -->
|
||||||
<li class="user-header">
|
<li class="user-header">
|
||||||
<img src="@session.GetString("avatar")" class="img-circle" alt="User Image" id="avatar">
|
<img src="@session.GetString("avatar")" class="img-circle" alt="User Image" id="avatar">
|
||||||
|
|||||||
@@ -4,51 +4,10 @@
|
|||||||
@{
|
@{
|
||||||
var db = dbFactory.Create();
|
var db = dbFactory.Create();
|
||||||
var maxMessage = 10;
|
var maxMessage = 10;
|
||||||
var notSeen = (from n in db.Messages
|
var num = 0;
|
||||||
where n.Reciver.Equals(Model) && n.Seen == false
|
var messages = db.GetLastMessages(db.Messages, Model, ref num, maxMessage);
|
||||||
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">
|
<a id="id-message-toggle" href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
<i class="fa fa-envelope-o"></i>
|
<i class="fa fa-envelope-o"></i>
|
||||||
@if (num != 0)
|
@if (num != 0)
|
||||||
@@ -64,8 +23,8 @@
|
|||||||
</a>
|
</a>
|
||||||
@if (messages.Length != 0)
|
@if (messages.Length != 0)
|
||||||
{
|
{
|
||||||
<ul id="id-message-drop" class="dropdown-menu">
|
<ul id="id-message-drop" class="dropdown-menu" style="box-shadow: black 0px 0px 2px">
|
||||||
<li class="header">You have @num unread message</li>
|
<li class="header">Hai @num messaggi non letti</li>
|
||||||
<li>
|
<li>
|
||||||
<!-- Inner Menu: contains the messages -->
|
<!-- Inner Menu: contains the messages -->
|
||||||
<ul class="menu">
|
<ul class="menu">
|
||||||
@@ -75,7 +34,7 @@
|
|||||||
{
|
{
|
||||||
<li>
|
<li>
|
||||||
<!-- start notification -->
|
<!-- start notification -->
|
||||||
<a id="message-@message.Id" @if(message.Seen) {<text>class= "bg-gray"</text>} href="/Message/@message.Id">
|
<a id="message-@message.Id" @if(message.Seen != default) {<text>class= "bg-gray"</text>} href="/Message/@message.Username">
|
||||||
<i class="fa text-lime">@message.Time</i><br />
|
<i class="fa text-lime">@message.Time</i><br />
|
||||||
@message.Body
|
@message.Body
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -3,29 +3,10 @@
|
|||||||
|
|
||||||
@{
|
@{
|
||||||
var db = dbFactory.Create();
|
var db = dbFactory.Create();
|
||||||
var notifications = (from n in db.Notifications
|
var num = 0;
|
||||||
where n.Username.Equals(Model) && n.Seen == false
|
var notifications = db.GetLastMessages(db.Notifications, Model, ref num);
|
||||||
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">
|
<a id="id-notification-toggle" href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
<i class="fa fa-bell-o"></i>
|
<i class="fa fa-bell-o"></i>
|
||||||
@if (num != 0)
|
@if (num != 0)
|
||||||
@@ -33,50 +14,48 @@
|
|||||||
<span class="label label-warning">@num</span>
|
<span class="label label-warning">@num</span>
|
||||||
}
|
}
|
||||||
</a>
|
</a>
|
||||||
@if (num != 0)
|
<ul id="id-notification-drop" class="dropdown-menu" style="box-shadow: black 0px 0px 2px">
|
||||||
{
|
<li class="header">Hai @num nuove notifiche</li>
|
||||||
<ul id="id-notification-drop" class="dropdown-menu">
|
<li>
|
||||||
<li class="header">You have @num notifications</li>
|
<!-- Inner Menu: contains the notifications -->
|
||||||
<li>
|
<ul class="menu">
|
||||||
<!-- Inner Menu: contains the notifications -->
|
@foreach (var notification in notifications)
|
||||||
<ul class="menu">
|
{
|
||||||
@foreach (var notification in notifications)
|
if (notification != null)
|
||||||
{
|
{
|
||||||
<li>
|
<li>
|
||||||
<!-- start notification -->
|
<!-- start notification -->
|
||||||
<a id="notification-@notification.Id" href="#">
|
<a id="notification-@notification.Id" class="@if (notification.Seen != default) {<text>bg-gray</text>}" href="@notification.Url">
|
||||||
<i class="fa fa-users text-aqua">@notification.Time</i><br />
|
<i class="fa fa-users text-aqua">@notification.Time</i><br />
|
||||||
@notification.Message
|
@notification.Body
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<!-- end notification -->
|
<!-- end notification -->
|
||||||
}
|
}
|
||||||
</ul>
|
}
|
||||||
</li>
|
</ul>
|
||||||
<!-- <li class="footer"><a href="#">View all</a></li> -->
|
</li>
|
||||||
</ul>
|
<!-- <li class="footer"><a href="#">View all</a></li> -->
|
||||||
|
</ul>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var user = "@Model";
|
var user = "@Model";
|
||||||
$("[id^='notification-']").on("click", function () {
|
$("[id^='notification-']").on("click", function () {
|
||||||
var id = this.id.replace(/notification-/g, '');
|
var id = this.id.replace(/notification-/g, '');
|
||||||
var allId = this.id;
|
var allId = this.id;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
url: "/Account/_notification",
|
url: "/Account/_notification",
|
||||||
data: { id: id },
|
data: { id: id },
|
||||||
success: function () {
|
success: function () {
|
||||||
$("#" + allId).remove();
|
$("#" + allId).addClass("bg-gray");
|
||||||
var num = parseInt($("#id-notification-toggle span").html()) - 1;
|
var num = parseInt($("#id-notification-toggle span").html()) - 1;
|
||||||
if (num == 0) {
|
if (num == 0)
|
||||||
$("#id-notification-toggle span").remove();
|
$("#id-notification-toggle span").remove();
|
||||||
$("#id-notification-drop").remove();
|
else
|
||||||
}
|
$("#id-notification-toggle span").html(num);
|
||||||
else
|
}
|
||||||
$("#id-notification-toggle span").html(num);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
});
|
||||||
}
|
</script>
|
||||||
@@ -30,37 +30,8 @@
|
|||||||
<p class="text-bold">Dottore: @doctor.Name @doctor.LastName</p>
|
<p class="text-bold">Dottore: @doctor.Name @doctor.LastName</p>
|
||||||
<p class="text-fuchsia">Dove mi puoi trovare? @doctor.Location</p>
|
<p class="text-fuchsia">Dove mi puoi trovare? @doctor.Location</p>
|
||||||
<textarea class="progress-text" placeholder="Nessuna nuova nota" readonly>@patientData.Notes</textarea>
|
<textarea class="progress-text" placeholder="Nessuna nuova nota" readonly>@patientData.Notes</textarea>
|
||||||
|
|
||||||
<div id="send-doc-message">
|
<a class="" href="/Message/@doctor.Username">Invia un messaggio al tuo dottore</a>
|
||||||
<p>Invia un messaggio al tuo dottore</p>
|
|
||||||
<textarea id="doc-message" class="progress-text" placeholder="scrivi qui"></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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
@inject IList<IMenuItem> Menu
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
@inject IHttpContextAccessor HttpContextAccessor
|
|
||||||
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var session = HttpContextAccessor.HttpContext.Session;
|
var session = HttpContextAccessor.HttpContext.Session;
|
||||||
|
string search = HttpContextAccessor.HttpContext.Request.Query["q"];
|
||||||
string username = session.GetString("username");
|
string username = session.GetString("username");
|
||||||
|
|
||||||
if (username != null)
|
if (username != null)
|
||||||
{
|
{
|
||||||
Menu = new List<IMenuItem>(Menu);
|
var isDoc = session.GetString("role").Equals("doctor");
|
||||||
Menu.RemoveAt(1);
|
var Menu = new List<IMenuItem>();
|
||||||
Menu.Insert(1, new MenuItem("Dati personali", "/user/" + username));
|
Menu.Add(new MenuItem("Profilo", "/"));
|
||||||
if (session.GetString("role").Equals("doctor"))
|
Menu.Add(new MenuItem("Dati personali", "/user/" + username));
|
||||||
|
if (isDoc)
|
||||||
{
|
{
|
||||||
var db = dbFactory.Create();
|
var db = dbFactory.Create();
|
||||||
var patients = (from p in db.Patients
|
var patients = (from p in db.Patients
|
||||||
@@ -25,36 +26,87 @@
|
|||||||
}
|
}
|
||||||
Menu.Add(sub);
|
Menu.Add(sub);
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
}
|
|
||||||
<ul class="sidebar-menu" data-widget="tree">
|
|
||||||
@foreach (var menuItem in Menu)
|
|
||||||
{
|
|
||||||
switch (menuItem)
|
|
||||||
{
|
{
|
||||||
case MenuItem single:
|
var db = dbFactory.Create();
|
||||||
<li>
|
var patient = (from p in db.Patients
|
||||||
<a href="@single.HRef">@single.Text</a>
|
where p.Username.Equals(username)
|
||||||
</li>
|
select p).FirstOrDefault();
|
||||||
break;
|
Menu.Add(new MenuItem("Invia un messaggio al dottore", "/Message/" + patient.Doctor));
|
||||||
case SubMenu multi:
|
}
|
||||||
<li class="treeview">
|
<aside class="main-sidebar">
|
||||||
<a href="#">
|
<!-- sidebar: style can be found in sidebar.less -->
|
||||||
<i class="fa fa-link"></i><span>@multi.Text</span>
|
<section class="sidebar">
|
||||||
<span class="pull-right-container">
|
@if (isDoc)
|
||||||
<i class="fa fa-angle-left pull-right"></i>
|
{
|
||||||
</span>
|
<!-- Sidebar user panel (optional) -->
|
||||||
</a>
|
<!-- search form (Optional) -->
|
||||||
<ul class="treeview-menu">
|
<form action="#" method="get" class="sidebar-form">
|
||||||
@foreach (MenuItem item in multi.Items)
|
<div class="input-group">
|
||||||
|
<input type="text" name="q" class="form-control" placeholder="Search..." , value="@search">
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button type="submit" name="search" id="search-btn" class="btn btn-flat">
|
||||||
|
<i class="fa fa-search"></i>
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<!-- /.search form -->
|
||||||
|
<!-- Sidebar Menu -->
|
||||||
|
}
|
||||||
|
<div>
|
||||||
|
<ul class="sidebar-menu" data-widget="tree">
|
||||||
|
@foreach (var menuItem in Menu)
|
||||||
{
|
{
|
||||||
<li>
|
switch (menuItem)
|
||||||
<a href="@item.HRef">@item.Text</a>
|
{
|
||||||
</li>
|
case MenuItem single:
|
||||||
|
<li>
|
||||||
|
<a href="@single.HRef">@single.Text</a>
|
||||||
|
</li>
|
||||||
|
break;
|
||||||
|
case SubMenu multi:
|
||||||
|
<li class="treeview @if(search != null) {<text>menu-open</text>}">
|
||||||
|
<a href="#">
|
||||||
|
<i class="fa fa-link"></i><span>@multi.Text</span>
|
||||||
|
<span class="pull-right-container">
|
||||||
|
<i class="fa fa-angle-left pull-right"></i>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<ul class="treeview-menu" @if (search != null) { <text> style="display: block;" </text> }>
|
||||||
|
@foreach (MenuItem item in multi.Items)
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
@{
|
||||||
|
var text = item.Text;
|
||||||
|
var bg = "";
|
||||||
|
if (search != null && item.Text.StartsWith(search))
|
||||||
|
{
|
||||||
|
bg = "bg-aqua";
|
||||||
|
text = item.Text.Replace(search, "<em>" + search + "</em>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<a href="@item.HRef" class="@bg">
|
||||||
|
@Html.Raw(text)
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</div>
|
||||||
break;
|
<!-- /.sidebar-menu -->
|
||||||
|
</section>
|
||||||
|
<!-- /.sidebar -->
|
||||||
|
</aside>
|
||||||
|
@if (search != null)
|
||||||
|
{
|
||||||
|
<script>
|
||||||
|
$("body").removeClass("sidebar-collapse");
|
||||||
|
</script>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</ul>
|
}
|
||||||
@@ -2,10 +2,12 @@
|
|||||||
@using Microsoft.Extensions.Options
|
@using Microsoft.Extensions.Options
|
||||||
@inject IOptions<SeniorAssistant.Configuration.Kendo> Kendo
|
@inject IOptions<SeniorAssistant.Configuration.Kendo> Kendo
|
||||||
@inject IOptions<SeniorAssistant.Configuration.Theme> Theme
|
@inject IOptions<SeniorAssistant.Configuration.Theme> Theme
|
||||||
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var kendo = Kendo.Value;
|
var kendo = Kendo.Value;
|
||||||
var theme = Theme.Value;
|
var theme = Theme.Value;
|
||||||
|
var logged = HttpContextAccessor.HttpContext.Session.GetString("username") != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -46,27 +48,8 @@ scratch. This page gets rid of all links and provides the needed markup only.
|
|||||||
<script src="~/kendo/@(kendo.Version)/js/jquery.min.js"></script>
|
<script src="~/kendo/@(kendo.Version)/js/jquery.min.js"></script>
|
||||||
<script src="~/kendo/@(kendo.Version)/js/kendo.all.min.js"></script>
|
<script src="~/kendo/@(kendo.Version)/js/kendo.all.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<!--
|
|
||||||
BODY TAG OPTIONS:
|
<body class="hold-transition @(theme.Skin.GetDescription()) @(!logged?theme.Layout.GetDescription():"")">
|
||||||
=================
|
|
||||||
Apply one or more of the following classes to get the
|
|
||||||
desired effect
|
|
||||||
|---------------------------------------------------------|
|
|
||||||
| SKINS | skin-blue |
|
|
||||||
| | skin-black |
|
|
||||||
| | skin-purple |
|
|
||||||
| | skin-yellow |
|
|
||||||
| | skin-red |
|
|
||||||
| | skin-green |
|
|
||||||
|---------------------------------------------------------|
|
|
||||||
|LAYOUT OPTIONS | fixed |
|
|
||||||
| | layout-boxed |
|
|
||||||
| | layout-top-nav |
|
|
||||||
| | sidebar-collapse |
|
|
||||||
| | sidebar-mini |
|
|
||||||
|---------------------------------------------------------|
|
|
||||||
-->
|
|
||||||
<body class="hold-transition @(theme.Skin.GetDescription()) @(theme.Layout.GetDescription())">
|
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<!-- Main Header -->
|
<!-- Main Header -->
|
||||||
<header class="main-header">
|
<header class="main-header">
|
||||||
@@ -80,9 +63,14 @@ desired effect
|
|||||||
<!-- Header Navbar -->
|
<!-- Header Navbar -->
|
||||||
<nav class="navbar navbar-static-top" role="navigation">
|
<nav class="navbar navbar-static-top" role="navigation">
|
||||||
<!-- Sidebar toggle button-->
|
<!-- Sidebar toggle button-->
|
||||||
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
|
@if (logged)
|
||||||
<span class="sr-only">Toggle navigation</span>
|
{
|
||||||
</a>
|
<text>
|
||||||
|
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
|
||||||
|
<span class="sr-only">Toggle navigation</span>
|
||||||
|
</a>
|
||||||
|
</text>
|
||||||
|
}
|
||||||
<!-- Navbar Right Menu -->
|
<!-- Navbar Right Menu -->
|
||||||
<div>
|
<div>
|
||||||
@{ await Html.RenderPartialAsync("NavbarRightMenu"); }
|
@{ await Html.RenderPartialAsync("NavbarRightMenu"); }
|
||||||
@@ -90,30 +78,7 @@ desired effect
|
|||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
<!-- Left side column. contains the logo and sidebar -->
|
<!-- Left side column. contains the logo and sidebar -->
|
||||||
<aside class="main-sidebar">
|
@{ await Html.RenderPartialAsync("SidebarMenu"); }
|
||||||
<!-- sidebar: style can be found in sidebar.less -->
|
|
||||||
<section class="sidebar">
|
|
||||||
<!-- Sidebar user panel (optional) -->
|
|
||||||
<!-- search form (Optional) -->
|
|
||||||
<form action="#" method="get" class="sidebar-form">
|
|
||||||
<div class="input-group">
|
|
||||||
<input type="text" name="q" class="form-control" placeholder="Search...">
|
|
||||||
<span class="input-group-btn">
|
|
||||||
<button type="submit" name="search" id="search-btn" class="btn btn-flat">
|
|
||||||
<i class="fa fa-search"></i>
|
|
||||||
</button>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<!-- /.search form -->
|
|
||||||
<!-- Sidebar Menu -->
|
|
||||||
<div>
|
|
||||||
@{ await Html.RenderPartialAsync("SidebarMenu"); }
|
|
||||||
</div>
|
|
||||||
<!-- /.sidebar-menu -->
|
|
||||||
</section>
|
|
||||||
<!-- /.sidebar -->
|
|
||||||
</aside>
|
|
||||||
<!-- Content Wrapper. Contains page content -->
|
<!-- Content Wrapper. Contains page content -->
|
||||||
<div class="content-wrapper">
|
<div class="content-wrapper">
|
||||||
<!-- Content Header (Page header) -->
|
<!-- Content Header (Page header) -->
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
@using SeniorAssistant.Models;
|
@using SeniorAssistant.Models;
|
||||||
@using SeniorAssistant.Models.Users;
|
@using SeniorAssistant.Models.Users;
|
||||||
|
@using SeniorAssistant.Models.Data;
|
||||||
@using SeniorAssistant.Data;
|
@using SeniorAssistant.Data;
|
||||||
@using Microsoft.AspNetCore.Mvc;
|
@using Microsoft.AspNetCore.Mvc;
|
||||||
@using Microsoft.AspNetCore.Http;
|
@using Microsoft.AspNetCore.Http;
|
||||||
|
@using System.Linq;
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
},
|
},
|
||||||
"theme": {
|
"theme": {
|
||||||
"skin": "Purple",
|
"skin": "Purple",
|
||||||
"layout": "SidebarMini"
|
"layout": "SidebarCollapse"
|
||||||
},
|
},
|
||||||
"connectionStrings": {
|
"connectionStrings": {
|
||||||
"SeniorDb": "Data Source=senior.db;"
|
"SeniorDb": "Data Source=senior.db;"
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user