Commit 7b112f0f authored by hasan khaddour's avatar hasan khaddour

add patient image load feature

parent ebc69772
...@@ -5,6 +5,8 @@ using Microsoft.AspNetCore.Identity; ...@@ -5,6 +5,8 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using WebPresentation.Filters.ImageLoad;
using AutoMapper;
namespace WebPresentation.Controllers namespace WebPresentation.Controllers
{ {
...@@ -12,13 +14,15 @@ namespace WebPresentation.Controllers ...@@ -12,13 +14,15 @@ namespace WebPresentation.Controllers
public class AccessController : Controller public class AccessController : Controller
{ {
private readonly IMapper _mapper;
private readonly UserManager<User> _userManager; private readonly UserManager<User> _userManager;
private readonly SignInManager<User> _signInManager; private readonly SignInManager<User> _signInManager;
public AccessController(SignInManager<User> signInManager, public AccessController(SignInManager<User> signInManager,
UserManager<User> userManager) UserManager<User> userManager,
IMapper mapper )
{ {
_mapper = mapper;
_userManager = userManager; _userManager = userManager;
_signInManager = signInManager; _signInManager = signInManager;
} }
...@@ -68,6 +72,7 @@ namespace WebPresentation.Controllers ...@@ -68,6 +72,7 @@ namespace WebPresentation.Controllers
return View(); return View();
} }
[HttpPost] [HttpPost]
[ImageLoadFilter]
public async Task<IActionResult> Register(RegisterationInputModel Input) public async Task<IActionResult> Register(RegisterationInputModel Input)
{ {
Input.ReturnUrl ??= Url.Content("/Home/Index"); Input.ReturnUrl ??= Url.Content("/Home/Index");
...@@ -75,14 +80,15 @@ namespace WebPresentation.Controllers ...@@ -75,14 +80,15 @@ namespace WebPresentation.Controllers
ViewBag.ReturUrl = Input.ReturnUrl; ViewBag.ReturUrl = Input.ReturnUrl;
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
var patient = _mapper.Map<Patient>(Input.Patient);
var user = new User { var user = new User {
NormalizedEmail = Input.Email, NormalizedEmail = Input.Email,
FirstName=Input.FirstName, FirstName=Input.FirstName,
LastName=Input.LastName, LastName=Input.LastName,
Avatar=Input.Avatar, Avatar=Input.ImageName,
UserName = Input.Email, UserName = Input.Email,
Email = Input.Email, Email = Input.Email,
Patient = Input.Patient, Patient = patient,
CreationTime = DateTime.Now, CreationTime = DateTime.Now,
}; };
......
...@@ -10,6 +10,8 @@ using ApplicationCore.DTOs; ...@@ -10,6 +10,8 @@ using ApplicationCore.DTOs;
using AutoMapper; using AutoMapper;
using WebPresentation.ViewModels; using WebPresentation.ViewModels;
using System.Threading.Tasks; using System.Threading.Tasks;
using WebPresentation.Filters.ImageLoad;
using Microsoft.EntityFrameworkCore;
namespace WebPresentation.Controllers namespace WebPresentation.Controllers
{ {
...@@ -45,14 +47,47 @@ namespace WebPresentation.Controllers ...@@ -45,14 +47,47 @@ namespace WebPresentation.Controllers
return View(t); return View(t);
} }
[Authorize(Roles = "patient")] [Authorize(Roles = "patient")]
public async Task<IActionResult> Edit(int id)
public async Task<IActionResult> Edit()
{ {
var t = await getCurrentPatient(); var t = await getCurrentPatient();
if (id != t.Id) {
return View("Error");
}
return View(t); return View(t);
} }
[HttpPost]
[ValidateAntiForgeryToken]
[ImageLoadFilter]
public IActionResult Edit(int id, [FromForm] PatientViewModel viewModel)
{
if (id != viewModel.Id)
{
return NotFound();
}
PatientDTO dto;
if (ModelState.IsValid)
{
try
{
dto = _mapper.Map<PatientDTO>(viewModel);
dto.User.Avatar= viewModel.ImageName;
dto = _patientService.Update(dto);
}
catch (DbUpdateConcurrencyException)
{
return View("Error");
}
return RedirectToAction("Details", new { id = dto.Id });
}
return View(viewModel);
}
[Authorize(Roles = "patient")] [Authorize(Roles = "patient")]
public async Task<IActionResult> Details(int? id ) { public async Task<IActionResult> Details(int? id ) {
var t = await getCurrentPatient(); var t = await getCurrentPatient();
......
...@@ -43,7 +43,7 @@ namespace WebPresentation.Controllers ...@@ -43,7 +43,7 @@ namespace WebPresentation.Controllers
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
var uId = GetUserId(); var uId = GetUserId();
var p = _patientService.GetByUserId(uId).Id; var p = _patientService.GetByUserId(uId).Result.Id;
if (medicalState.PrescriptionTime == DateTime.MinValue ) if (medicalState.PrescriptionTime == DateTime.MinValue )
medicalState.PrescriptionTime = DateTime.Now; medicalState.PrescriptionTime = DateTime.Now;
var n= ((IMedicalStateService)_service).AddToPateint(p,_mapper.Map<MedicalStateDTO>(medicalState)); var n= ((IMedicalStateService)_service).AddToPateint(p,_mapper.Map<MedicalStateDTO>(medicalState));
......
...@@ -32,20 +32,21 @@ namespace WebPresentation.Controllers ...@@ -32,20 +32,21 @@ namespace WebPresentation.Controllers
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
var user = new User var patient = _mapper.Map<Patient>(Input.Patient);
{ var user = new User
NormalizedEmail = Input.Email, {
FirstName = Input.FirstName, NormalizedEmail = Input.Email,
LastName = Input.LastName, FirstName = Input.FirstName,
Avatar = Input.Avatar, LastName = Input.LastName,
UserName = Input.Email, Avatar = Input.ImageName,
Email = Input.Email, UserName = Input.Email,
Patient = Input.Patient, Email = Input.Email,
CreationTime = DateTime.Now, Patient = patient,
CreationTime = DateTime.Now,
};
};
var result =_userManager.CreateAsync(user, Input.Password).Result;
var result =_userManager.CreateAsync(user, Input.Password).Result;
if (result.Succeeded) { if (result.Succeeded) {
return RedirectToAction("Index", "Patients"); return RedirectToAction("Index", "Patients");
......
...@@ -22,8 +22,14 @@ namespace ApplicationCore.Mappere ...@@ -22,8 +22,14 @@ namespace ApplicationCore.Mappere
.ForMember(dest => dest.Ingredients, opt => opt.MapFrom(src => src.Ingredients)) .ForMember(dest => dest.Ingredients, opt => opt.MapFrom(src => src.Ingredients))
.ForMember(dest => dest.MedicineIngredients, opt => opt.MapFrom(src => src.MedicineIngredients)); .ForMember(dest => dest.MedicineIngredients, opt => opt.MapFrom(src => src.MedicineIngredients));
CreateMap<PatientDTO, PatientViewModel>().ReverseMap();
CreateMap<PatientViewModel, PatientDTO>();
CreateMap<PatientDTO, PatientViewModel>()
.ForMember(dest => dest.ImageName, opt => opt.MapFrom(src => src.User.Avatar))
.ForMember(dest => dest.ImageFile, opt => opt.Ignore());
;
CreateMap<IngredientViewModel, IngredientDTO>().ReverseMap(); CreateMap<IngredientViewModel, IngredientDTO>().ReverseMap();
CreateMap<MedicineIngredientDTO, MedicineIngredientViewModel>().ReverseMap(); CreateMap<MedicineIngredientDTO, MedicineIngredientViewModel>().ReverseMap();
......
using ApplicationDomain.Entities; using ApplicationDomain.Entities;
using Microsoft.AspNetCore.Http;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using WebPresentation.ViewModels;
namespace WebPresentation.ViewModel.Identity namespace WebPresentation.ViewModel.Identity
{ {
public class RegisterationInputModel public class RegisterationInputModel : IImageForm
{ {
[Required] [Required]
[EmailAddress] [EmailAddress]
[Display(Name = "Email")] [Display(Name = "Email")]
public string Email { get; set; } public string Email { get; set; }
public IFormFile ImageFile { get; set; }
public string ImageName { get; set; }
[Required] [Required]
public string FirstName { get; set; } public string FirstName { get; set; }
[Required] [Required]
public string LastName { get; set; } public string LastName { get; set; }
public string Avatar { get; set; }
[Required] [Required]
public Patient Patient { get; set; } public PatientViewModel Patient { get; set; }
[Required] [Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 3)] [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 3)]
[DataType(DataType.Password)] [DataType(DataType.Password)]
......
...@@ -8,15 +8,19 @@ using System.Threading.Tasks; ...@@ -8,15 +8,19 @@ using System.Threading.Tasks;
namespace WebPresentation.ViewModels namespace WebPresentation.ViewModels
{ {
public class PatientViewModel : BaseViewModel //,IImageForm public class PatientViewModel : BaseViewModel , IImageForm
{ {
public String UserId { get; set; } public String UserId { get; set; }
public User User { get; set; } public User User { get; set; }
public String BIO { get; set; } public String BIO { get; set; }
// public IFormFile ImageFile { get; set; }
// public string ImageName { get; set; }
public ICollection<MedicalStateViewModel> MedicalStates { get; set; } public ICollection<MedicalStateViewModel> MedicalStates { get; set; }
public IFormFile ImageFile { get; set; }
public string ImageName { get; set; }
} }
} }
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<section class="page-section bg-primary text-black mb-0"> <section class="page-section bg-primary text-black mb-0">
<h3 class="mb-5 text-uppercase text-center">Patient Registration</h3> <h3 class="mb-5 text-uppercase text-center">Patient Registration</h3>
<form method="post" asp-controller="Access" asp-action="Register"> <form method="post" asp-controller="Access" asp-action="Register" enctype="multipart/form-data">
<div class="container py-5 h-100"> <div class="container py-5 h-100">
<div class="row d-flex justify-content-center align-items-center h-100"> <div class="row d-flex justify-content-center align-items-center h-100">
<div class="col"> <div class="col">
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
<div class="form-group row mb-4"> <div class="form-group row mb-4">
<div data-mdb-input-init class="form-outline col"> <div data-mdb-input-init class="form-outline col">
<input type="text" asp-for="@Model.Avatar" class="form-control form-control-lg" /> <input type="file" asp-for="@Model.ImageFile" class="form-control form-control-lg" />
<label class="form-label" asp-for="@Model.Avatar">Image</label> <label class="form-label" asp-for="@Model.ImageFile">Image File</label>
</div> </div>
</div> </div>
......
@model PatientViewModel @model PatientViewModel;
@{ @{
ViewData["Title"] = "Edit";
ViewData["userName"] = Model.User.FirstName + " " + Model.User.LastName;
ViewData["title"] = "Edit";
ViewBag.Avatar = Model.User.Avatar;
ViewData["Controller"] = "Home";
ViewBag.owner = Model;
} }
<div class="container page-section">
<div class="row justify-content-center">
<div class="">
<div class="card shadow-sm">
<div class="card-body">
<form asp-action="Edit" class="row g-3" enctype="multipart/form-data">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="col-md-6">
<label asp-for="BIO" class="form-label">Patient Personal info</label>
<input asp-for="BIO" class="form-control" />
<span asp-validation-for="BIO" class="text-danger"></span>
</div>
<style>
.form-control:focus {
box-shadow: none;
border-color: #BA68C8
}
.profile-button {
background: rgb(99, 39, 120);
box-shadow: none;
border: none
}
.profile-button:hover {
background: #682773
}
.profile-button:focus {
background: #682773;
box-shadow: none
}
.profile-button:active {
background: #682773;
box-shadow: none
}
.back:hover {
color: #682773;
cursor: pointer
}
.labels {
font-size: 11px
}
.add-experience:hover {
background: #BA68C8;
color: #fff;
cursor: pointer;
border: solid 1px #BA68C8
}
</style>
<section class="page-section">
<form method="post" asp-action="Edit" asp-controller="Home">
<div class="container rounded bg-white mt-5 mb-5">
<div class="row">
<div class="col-md-3 border-right">
<div class="d-flex flex-column align-items-center text-center p-3 py-5">
<img class="rounded-circle mt-5" width="150px" src="/img/@Model.User.Avatar"><span class="font-weight-bold">@Model.User.FirstName</span><span class="text-black-50">@Model.User.Email</span><span> </span>
</div>
</div>
<div class="col-md-5 border-right">
<div class="p-3 py-5">
<div class="d-flex justify-content-between align-items-center mb-3">
<h4 class="text-right">Profile Settings</h4>
</div>
<div class="row mt-2">
<div class="col-md-6"> <div class="col-md-6">
<label asp-for="@Model.User.FirstName" class="labels"></label> <label asp-for="User.FirstName" class="form-label"></label>
<input asp-for="@Model.User.FirstName" class="form-control"> <input asp-for="User.FirstName" class="form-control" />
<span asp-validation-for="User.FirstName" class="text-danger"></span>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label class="labels" asp-for="@Model.User.LastName"></label> <label asp-for="User.LastName" class="form-label"></label>
<input type="text" class="form-control" asp-for="@Model.User.LastName"> <input asp-for="User.LastName" class="form-control" />
<span asp-validation-for="User.LastName" class="text-danger"></span>
</div>
<div class="col-12">
<label asp-for="ImageFile" class="form-label">Image File</label>
<input type="file" asp-for="ImageFile" class="form-control" />
<span asp-validation-for="ImageFile" class="text-danger"></span>
</div> </div>
</div>
<div class="row mt-3">
<div class="col-md-12"><label class="labels" asp-for="@Model.BIO"></label><input type="text" class="form-control" asp-for="@Model.BIO"></div>
<div class="col-md-12"><label class="labels" asp-for="@Model.User.UserName"></label><input type="text" class="form-control" asp-for="@Model.User.UserName"></div>
</div>
<div class="row mt-3">
<div class="col-md-12"><label class="labels" asp-for="@Model.User.Avatar"></label><input type="text" class="form-control" asp-for="@Model.User.Avatar"></div>
</div> <div class="col-12 mt-4">
<div class="mt-5 text-center"><button class="btn btn-primary profile-button" role="submit" type="button">Save Profile</button></div> <input type="hidden" asp-for="Id" />
<input type="hidden" asp-for="User.Id" />
<input type="hidden" asp-for="UserId" />
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</form> </div>
</section>
\ No newline at end of file
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
\ No newline at end of file
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<td>@ing.Dosage</td> <td>@ing.Dosage</td>
<td>@ing.ManufactureName</td> <td>@ing.ManufactureName</td>
<td> <td>
<button class="btn btn-danger btn-sm" ondblclick='DeleteConfirm("Delete Confirm", "Are you sure you want to delete @ing.TradeName from this medical case?", "RemoveMedicine", @ing.Id)'>Delete</button> <button class="btn btn-danger btn-sm" ondblclick='DeleteConfirm("Delete Confirm", "Are you sure you want to delete @ing.TradeName from this medical case?", @ing.Id)'>Delete</button>
<button class="btn btn-info btn-sm" onclick="DetailMedicine(@ing.Id)">Details</button> <button class="btn btn-info btn-sm" onclick="DetailMedicine(@ing.Id)">Details</button>
</td> </td>
</tr> </tr>
...@@ -211,7 +211,7 @@ ...@@ -211,7 +211,7 @@
<td> <td>
<button class="btn btn-primary" onclick="DetailMedicine( ${medicine.id})">Details</button> <button class="btn btn-primary" onclick="DetailMedicine( ${medicine.id})">Details</button>
<button class="btn btn-danger" onclick='DeleteConfirm("Delete Confirm", "Are you sure you want to delete ${medicine.name} From this medical Case" , "ReomveMedicine" ,${medicine.id})'>Delete</button> <button class="btn btn-danger" onclick='DeleteConfirm("Delete Confirm", "Are you sure you want to delete ${medicine.name} From this medical Case" ,${medicine.id})'>Delete</button>
</td> </td>
` : ` :
...@@ -305,7 +305,7 @@ ...@@ -305,7 +305,7 @@
showToast('Failed to remove medicine', 'Error'); showToast('Failed to remove medicine', 'Error');
} }
} }
async function DeleteConfirm(title, message, action,param) { async function DeleteConfirm(title, message,param) {
debugger debugger
const modalBody = document.querySelector('#item-container'); const modalBody = document.querySelector('#item-container');
modalBody.innerHTML = ` modalBody.innerHTML = `
...@@ -329,7 +329,7 @@ ...@@ -329,7 +329,7 @@
style="height: 0; background-color: transparent; opacity: .75; border-top: 2px dashed #9e9e9e;"> style="height: 0; background-color: transparent; opacity: .75; border-top: 2px dashed #9e9e9e;">
<div class="modal-footer d-flex justify-content-center border-top-0 py-4"> <div class="modal-footer d-flex justify-content-center border-top-0 py-4">
<button class="btn btn-danger" onclick="${action}(${param})" data-dismiss="modal" aria-label="Close">Delete</button> <button class="btn btn-danger" onclick="RemoveMedicine(${param})" data-dismiss="modal" aria-label="Close">Delete</button>
<button class="btn btn-info" class="close" data-dismiss="modal" aria-label="Close">Close</button> <button class="btn btn-info" class="close" data-dismiss="modal" aria-label="Close">Close</button>
</div> </div>
......
...@@ -27,7 +27,10 @@ ...@@ -27,7 +27,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Views\Patients\" /> <Content Update="Views\Home\Edit.cshtml">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup> </ItemGroup>
</Project> </Project>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment