Association in user
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using LinqToDB;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SeniorAssistant.Models;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace SeniorAssistant.Controllers
|
namespace SeniorAssistant.Controllers
|
||||||
@@ -11,7 +14,8 @@ namespace SeniorAssistant.Controllers
|
|||||||
[Route("Index")]
|
[Route("Index")]
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
return View();
|
string username = HttpContext.Session.GetString(Username);
|
||||||
|
return View("Index", GetUser(username));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("Heartbeat")]
|
[Route("Heartbeat")]
|
||||||
@@ -41,25 +45,28 @@ namespace SeniorAssistant.Controllers
|
|||||||
[Route("User/{User}")]
|
[Route("User/{User}")]
|
||||||
public IActionResult SingleUser(string user)
|
public IActionResult SingleUser(string user)
|
||||||
{
|
{
|
||||||
var u = (from us in Db.Users
|
return CheckAuthorized("User", GetUser(user));
|
||||||
where us.Username.Equals(user)
|
|
||||||
select us).FirstOrDefault();
|
|
||||||
return CheckAuthorized("User", u);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("Message/{User}")]
|
[Route("Message/{User}")]
|
||||||
public IActionResult Message(string user)
|
public IActionResult Message(string user)
|
||||||
{
|
{
|
||||||
return CheckAuthorized("Message", user);
|
return CheckAuthorized("Message", GetUser(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
private User GetUser(string username)
|
||||||
|
{
|
||||||
|
return Db.Users
|
||||||
|
.LoadWith(u => u.Doc)
|
||||||
|
.LoadWith(u => u.Pat)
|
||||||
|
.Where(u => u.Username.Equals(username))
|
||||||
|
.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IActionResult CheckAuthorized(string view, object model = null)
|
private IActionResult CheckAuthorized(string view, object model = null)
|
||||||
{
|
{
|
||||||
if (!IsLogged())
|
if (!IsLogged())
|
||||||
{
|
return View("Index", "/" + view);
|
||||||
model = "/" + view;
|
|
||||||
view = "Index";
|
|
||||||
}
|
|
||||||
return View(view, model);
|
return View(view, model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using LinqToDB.Mapping;
|
using LinqToDB.Mapping;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using SeniorAssistant.Models.Users;
|
||||||
|
|
||||||
namespace SeniorAssistant.Models
|
namespace SeniorAssistant.Models
|
||||||
{
|
{
|
||||||
@@ -8,15 +9,27 @@ namespace SeniorAssistant.Models
|
|||||||
[Column(IsPrimaryKey = true, CanBeNull = false)]
|
[Column(IsPrimaryKey = true, CanBeNull = false)]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
|
|
||||||
[NotNull]
|
[Column(CanBeNull = false)]
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
|
||||||
[NotNull]
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
[Column(CanBeNull = false)]
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public string LastName { get; set; }
|
public string LastName { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
[Association(ThisKey = nameof(Username), OtherKey = nameof(Doctor.Username), CanBeNull = true)]
|
||||||
|
public Doctor Doc { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
[Association(ThisKey = nameof(Username), OtherKey = nameof(Patient.Username), CanBeNull = true)]
|
||||||
|
public Patient Pat { get; set; }
|
||||||
|
|
||||||
|
public bool IsDoctor() => Doc != null;
|
||||||
|
|
||||||
|
public bool IsPatient() => Pat != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
using System;
|
using Microsoft.AspNetCore;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace SeniorAssistant
|
namespace SeniorAssistant
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ logo sito
|
|||||||
disattivare l-aside e le opzioni
|
disattivare l-aside e le opzioni
|
||||||
se non loggato deve tornare qua
|
se non loggato deve tornare qua
|
||||||
-->
|
-->
|
||||||
@model string
|
@model object
|
||||||
@inject IHttpContextAccessor HttpContextAccessor
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
|
|
||||||
@{
|
@{
|
||||||
@@ -16,7 +16,7 @@ se non loggato deve tornare qua
|
|||||||
<div class="content">
|
<div class="content">
|
||||||
@if (session == null)
|
@if (session == null)
|
||||||
{
|
{
|
||||||
@if (Model != null)
|
@if (Model is string)
|
||||||
{
|
{
|
||||||
<p class="text-red box-title">Per poter accedere alla pagina [@Model] e' necessario essere loggati</p>
|
<p class="text-red box-title">Per poter accedere alla pagina [@Model] e' necessario essere loggati</p>
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,6 @@ se non loggato deve tornare qua
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Html.RenderPartialAsync("Profile"); // magari sostituire qui
|
await Html.RenderPartialAsync("Profile", Model); // magari sostituire qui
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
@model string
|
@model User
|
||||||
@inject IHttpContextAccessor HttpContextAccessor
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||||
@using LinqToDB;
|
@using LinqToDB;
|
||||||
@@ -7,12 +7,9 @@
|
|||||||
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 user = (from u in db.Users
|
|
||||||
where u.Username.Equals(Model)
|
|
||||||
select u).FirstOrDefault();
|
|
||||||
var messages = (from m in db.Messages
|
var messages = (from m in db.Messages
|
||||||
where (m.Username.Equals(Model) && m.Receiver.Equals(username))
|
where (m.Username.Equals(Model.Username) && m.Receiver.Equals(username))
|
||||||
||(m.Receiver.Equals(Model) && m.Username.Equals(username))
|
||(m.Receiver.Equals(Model.Username) && m.Username.Equals(username))
|
||||||
orderby m.Time ascending
|
orderby m.Time ascending
|
||||||
select m).ToArray();
|
select m).ToArray();
|
||||||
}
|
}
|
||||||
@@ -24,7 +21,7 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<h3 class="text-bold">Messaggi con @user.Name @user.LastName</h3>
|
<h3 class="text-bold">Messaggi con @Model.Name @Model.LastName</h3>
|
||||||
|
|
||||||
foreach (var message in messages)
|
foreach (var message in messages)
|
||||||
{
|
{
|
||||||
@@ -72,7 +69,7 @@
|
|||||||
url: "/Account/_sendMessage",
|
url: "/Account/_sendMessage",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
Receiver: "@Model",
|
Receiver: "@Model.Username",
|
||||||
Body: body
|
Body: body
|
||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
|
|||||||
@@ -8,16 +8,8 @@
|
|||||||
var username = session.GetString("username");
|
var username = session.GetString("username");
|
||||||
|
|
||||||
bool auth = username.Equals(Model.Username);
|
bool auth = username.Equals(Model.Username);
|
||||||
bool isDoc = session.GetString("role").Equals("doctor");
|
bool isDoc = Model.IsPatient() && username.Equals(Model.Pat.Doctor);
|
||||||
Patient patient = null;
|
auth = auth || isDoc;
|
||||||
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)
|
@if (!auth)
|
||||||
@@ -31,21 +23,21 @@ else
|
|||||||
<button id="refresh-hours" class="fc-button">Cambia ora</button>
|
<button id="refresh-hours" class="fc-button">Cambia ora</button>
|
||||||
<div id="chart-data"></div>
|
<div id="chart-data"></div>
|
||||||
</div>
|
</div>
|
||||||
@if (isDoc && patient != null)
|
@if (isDoc)
|
||||||
{
|
{
|
||||||
<div>
|
<div>
|
||||||
<textarea id="note-area" placeholder="Scrivi una nota..">@patient.Notes</textarea>
|
<textarea id="note-area" placeholder="Scrivi una nota..">@Model.Pat.Notes</textarea>
|
||||||
<button id="send-note" class="btn">Salva</button>
|
<button id="send-note" class="btn">Salva</button>
|
||||||
<p id="note-error"></p>
|
<p id="note-error"></p>
|
||||||
</div>
|
</div>
|
||||||
<a class="" href="/Message/@patient.Username">Invia un messaggio al tuo paziente</a>
|
<a class="" href="/Message/@Model.Pat.Username">Invia un messaggio al tuo paziente</a>
|
||||||
<div>
|
<div>
|
||||||
<p>Inserisci un minimo o massimo valore per il battito cardiaco</p>
|
<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>
|
<p>Se il valore del battito del paziente supera i valori che hai inserito verrai notificato</p>
|
||||||
<label>Max:</label>
|
<label>Max:</label>
|
||||||
<input id="maxHeart" placeholder="max" value="@patient.MaxHeart" />
|
<input id="maxHeart" placeholder="max" value="@Model.Pat.MaxHeart" />
|
||||||
<label>Min:</label>
|
<label>Min:</label>
|
||||||
<input id="minHeart" placeholder="min" value="@patient.MinHeart" />
|
<input id="minHeart" placeholder="min" value="@Model.Pat.MinHeart" />
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
$("#send-note").on("click", function () {
|
$("#send-note").on("click", function () {
|
||||||
|
|||||||
@@ -1,44 +1,39 @@
|
|||||||
@inject IHttpContextAccessor HttpContextAccessor
|
@inject IHttpContextAccessor HttpContextAccessor
|
||||||
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||||
|
@model User
|
||||||
@{
|
|
||||||
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%">
|
<div class="pull-left" , style="width: 50%">
|
||||||
<h2 class="alert-success" style="text-align:center">
|
<h2 class="alert-success" style="text-align:center">
|
||||||
Welcome @username
|
Welcome @Model.Name @Model.LastName
|
||||||
</h2>
|
</h2>
|
||||||
name: @session.GetString("name")<br />
|
name: @Model.Name<br />
|
||||||
lastname: @session.GetString("lastname")<br />
|
lastname: @Model.LastName<br />
|
||||||
email: @session.GetString("email")<br />
|
email: @Model.Email<br />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="box pull-right" , style="width: 45%">
|
<div class="box pull-right" , style="width: 45%">
|
||||||
@if (hasDoc) // is patient and has doc, must show doc data
|
@if (Model.IsPatient()) // is patient and has doc, must show doc data
|
||||||
{
|
{
|
||||||
|
var db = dbFactory.Create();
|
||||||
var doctor = (from u in db.Users
|
var doctor = (from u in db.Users
|
||||||
join d in db.Doctors on u.Username equals d.Username
|
join d in db.Doctors on u.Username equals d.Username
|
||||||
where d.Username.Equals(patientData.Doctor)
|
where d.Username.Equals(Model.Pat.Doctor)
|
||||||
select new { u.Username, u.Name, u.LastName, d.Location }).ToArray().First();
|
select new { u.Username, u.Name, u.LastName, d.Location }).ToArray().First();
|
||||||
|
|
||||||
<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>@Model.Pat.Notes</textarea>
|
||||||
|
|
||||||
<a class="" href="/Message/@doctor.Username">Invia un messaggio al tuo dottore</a>
|
<a class="" href="/Message/@doctor.Username">Invia un messaggio al tuo dottore</a>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
var db = dbFactory.Create();
|
||||||
dynamic[] data;
|
dynamic[] data;
|
||||||
Type type = null;
|
Type type = null;
|
||||||
string title = null;
|
string title = null;
|
||||||
var docData = db.Doctors.Where(d => d.Username.Equals(username)).ToArray().FirstOrDefault();
|
var docData = db.Doctors.Where(d => d.Username.Equals(Model.Username)).ToArray().FirstOrDefault();
|
||||||
|
|
||||||
if (docData != null) // is DOC
|
if (docData != null) // is DOC
|
||||||
{
|
{
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user