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;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using WebPresentation.Filters.ImageLoad;
using AutoMapper;
namespace WebPresentation.Controllers
{
......@@ -12,13 +14,15 @@ namespace WebPresentation.Controllers
public class AccessController : Controller
{
private readonly IMapper _mapper;
private readonly UserManager<User> _userManager;
private readonly SignInManager<User> _signInManager;
public AccessController(SignInManager<User> signInManager,
UserManager<User> userManager)
UserManager<User> userManager,
IMapper mapper )
{
_mapper = mapper;
_userManager = userManager;
_signInManager = signInManager;
}
......@@ -68,6 +72,7 @@ namespace WebPresentation.Controllers
return View();
}
[HttpPost]
[ImageLoadFilter]
public async Task<IActionResult> Register(RegisterationInputModel Input)
{
Input.ReturnUrl ??= Url.Content("/Home/Index");
......@@ -75,14 +80,15 @@ namespace WebPresentation.Controllers
ViewBag.ReturUrl = Input.ReturnUrl;
if (ModelState.IsValid)
{
var patient = _mapper.Map<Patient>(Input.Patient);
var user = new User {
NormalizedEmail = Input.Email,
FirstName=Input.FirstName,
LastName=Input.LastName,
Avatar=Input.Avatar,
Avatar=Input.ImageName,
UserName = Input.Email,
Email = Input.Email,
Patient = Input.Patient,
Patient = patient,
CreationTime = DateTime.Now,
};
......
......@@ -10,6 +10,8 @@ using ApplicationCore.DTOs;
using AutoMapper;
using WebPresentation.ViewModels;
using System.Threading.Tasks;
using WebPresentation.Filters.ImageLoad;
using Microsoft.EntityFrameworkCore;
namespace WebPresentation.Controllers
{
......@@ -45,14 +47,47 @@ namespace WebPresentation.Controllers
return View(t);
}
[Authorize(Roles = "patient")]
public async Task<IActionResult> Edit(int id)
public async Task<IActionResult> Edit()
{
var t = await getCurrentPatient();
if (id != t.Id) {
return View("Error");
}
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")]
public async Task<IActionResult> Details(int? id ) {
var t = await getCurrentPatient();
......
......@@ -43,7 +43,7 @@ namespace WebPresentation.Controllers
if (ModelState.IsValid)
{
var uId = GetUserId();
var p = _patientService.GetByUserId(uId).Id;
var p = _patientService.GetByUserId(uId).Result.Id;
if (medicalState.PrescriptionTime == DateTime.MinValue )
medicalState.PrescriptionTime = DateTime.Now;
var n= ((IMedicalStateService)_service).AddToPateint(p,_mapper.Map<MedicalStateDTO>(medicalState));
......
......@@ -32,20 +32,21 @@ namespace WebPresentation.Controllers
{
if (ModelState.IsValid)
{
var user = new User
{
NormalizedEmail = Input.Email,
FirstName = Input.FirstName,
LastName = Input.LastName,
Avatar = Input.Avatar,
UserName = Input.Email,
Email = Input.Email,
Patient = Input.Patient,
CreationTime = DateTime.Now,
};
var result =_userManager.CreateAsync(user, Input.Password).Result;
var patient = _mapper.Map<Patient>(Input.Patient);
var user = new User
{
NormalizedEmail = Input.Email,
FirstName = Input.FirstName,
LastName = Input.LastName,
Avatar = Input.ImageName,
UserName = Input.Email,
Email = Input.Email,
Patient = patient,
CreationTime = DateTime.Now,
};
var result =_userManager.CreateAsync(user, Input.Password).Result;
if (result.Succeeded) {
return RedirectToAction("Index", "Patients");
......
......@@ -22,8 +22,14 @@ namespace ApplicationCore.Mappere
.ForMember(dest => dest.Ingredients, opt => opt.MapFrom(src => src.Ingredients))
.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<MedicineIngredientDTO, MedicineIngredientViewModel>().ReverseMap();
......
using ApplicationDomain.Entities;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebPresentation.ViewModels;
namespace WebPresentation.ViewModel.Identity
{
public class RegisterationInputModel
public class RegisterationInputModel : IImageForm
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
public IFormFile ImageFile { get; set; }
public string ImageName { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
public string Avatar { get; set; }
[Required]
public Patient Patient { get; set; }
public PatientViewModel Patient { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 3)]
[DataType(DataType.Password)]
......
......@@ -8,15 +8,19 @@ using System.Threading.Tasks;
namespace WebPresentation.ViewModels
{
public class PatientViewModel : BaseViewModel //,IImageForm
public class PatientViewModel : BaseViewModel , IImageForm
{
public String UserId { get; set; }
public User User { get; set; }
public String BIO { get; set; }
// public IFormFile ImageFile { get; set; }
// public string ImageName { get; set; }
public ICollection<MedicalStateViewModel> MedicalStates { get; set; }
public IFormFile ImageFile { get; set; }
public string ImageName { get; set; }
}
}
......@@ -28,7 +28,7 @@
<section class="page-section bg-primary text-black mb-0">
<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="row d-flex justify-content-center align-items-center h-100">
<div class="col">
......@@ -84,8 +84,8 @@
<div class="form-group row mb-4">
<div data-mdb-input-init class="form-outline col">
<input type="text" asp-for="@Model.Avatar" class="form-control form-control-lg" />
<label class="form-label" asp-for="@Model.Avatar">Image</label>
<input type="file" asp-for="@Model.ImageFile" class="form-control form-control-lg" />
<label class="form-label" asp-for="@Model.ImageFile">Image File</label>
</div>
</div>
......
@model PatientViewModel
@model PatientViewModel;
@{
ViewData["userName"] = Model.User.FirstName + " " + Model.User.LastName;
ViewData["title"] = "Edit";
ViewBag.Avatar = Model.User.Avatar;
ViewData["Controller"] = "Home";
ViewBag.owner = Model;
ViewData["Title"] = "Edit";
}
<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">
<label asp-for="@Model.User.FirstName" class="labels"></label>
<input asp-for="@Model.User.FirstName" class="form-control">
<label asp-for="User.FirstName" class="form-label"></label>
<input asp-for="User.FirstName" class="form-control" />
<span asp-validation-for="User.FirstName" class="text-danger"></span>
</div>
<div class="col-md-6">
<label class="labels" asp-for="@Model.User.LastName"></label>
<input type="text" class="form-control" asp-for="@Model.User.LastName">
<label asp-for="User.LastName" class="form-label"></label>
<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 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="mt-5 text-center"><button class="btn btn-primary profile-button" role="submit" type="button">Save Profile</button></div>
<div class="col-12 mt-4">
<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>
</form>
</section>
\ No newline at end of file
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
\ No newline at end of file
......@@ -67,7 +67,7 @@
<td>@ing.Dosage</td>
<td>@ing.ManufactureName</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>
</td>
</tr>
......@@ -211,7 +211,7 @@
<td>
<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>
` :
......@@ -305,7 +305,7 @@
showToast('Failed to remove medicine', 'Error');
}
}
async function DeleteConfirm(title, message, action,param) {
async function DeleteConfirm(title, message,param) {
debugger
const modalBody = document.querySelector('#item-container');
modalBody.innerHTML = `
......@@ -329,7 +329,7 @@
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">
<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>
</div>
......
......@@ -27,7 +27,10 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Views\Patients\" />
<Content Update="Views\Home\Edit.cshtml">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
</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