Commit f402feed authored by hasan khaddour's avatar hasan khaddour

fix s

parent a8be0ff8
using ApplicationCore.DTOs;
using ApplicationCore.Interfaces.IAuthentication;
using ApplicationDomain.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
......@@ -42,7 +41,34 @@ namespace ApplicationCore.Authentication
}
public async Task<IdentityResult> Register(RegisterInputDTO registerInputDTO)
public async Task<AuthenticationResult> ChangePassword(ChangePasswordRequest changePasswordRequest)
{
var user = await _userManager.FindByEmailAsync(changePasswordRequest.Email);
if (user == null)
{
var r = new AuthenticationResult(false);
r.AddError("the email not exists ");
return r;
}
var changePasswordResult = await _userManager.ChangePasswordAsync(user, changePasswordRequest.CurrentPassword, changePasswordRequest.NewPassword);
if (!changePasswordResult.Succeeded)
{
var resul = new AuthenticationResult(false);
foreach (var err in changePasswordResult.Errors)
{
resul.AddError(err.Description);
}
await _signInManager.RefreshSignInAsync(user);
return resul;
}
return new AuthenticationResult(true);
}
public async Task<AuthenticationResult> Register(RegisterInputDTO registerInputDTO)
{
var patient = new Patient {
BIO =registerInputDTO.Patient.BIO
......@@ -68,16 +94,23 @@ namespace ApplicationCore.Authentication
{
await _signInManager.SignInAsync(user, isPersistent: false);
return IdentityResult.Success;
return new AuthenticationResult(true);
}
else {
return result;
var resul = new AuthenticationResult(false);
foreach (var err in result.Errors) {
resul.AddError(err.Description);
}
return resul;
}
}
var res = new AuthenticationResult(false);
foreach (var err in result.Errors)
{
res.AddError(err.Description);
}
return res;
return result;
}
public async Task SignIn(User user, bool isPersisted)
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ApplicationCore.DTOs
{
public class AuthenticationResult
{
public bool Success { get; set; }
public string Error { get; set; }
public string Token { get; set; }
public IEnumerable<string> Errors { get; set; }
public AuthenticationResult(bool status)
{
Errors = new List<string>();
Success = status;
}
public void AddError(string error)
{
((List<string>)Errors).Add(error);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ApplicationCore.DTOs
{
public class ChangePasswordRequest
{
public String Email { get; set; }
public String NewPassword { get; set; }
public String CurrentPassword { get; set; }
}
}
using ApplicationCore.DTOs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using ApplicationDomain.Entities;
namespace ApplicationCore.Interfaces.IAuthentication
......@@ -12,8 +8,9 @@ namespace ApplicationCore.Interfaces.IAuthentication
public interface IAuthenticationManager
{
Task<Boolean> Authenticate(LoginInputDTO loginInputDTO);
Task<IdentityResult> Register(RegisterInputDTO registerInputDTO);
Task<AuthenticationResult> Register(RegisterInputDTO registerInputDTO);
Task SignOut();
Task SignIn(User user , bool isPersisted );
Task<AuthenticationResult> ChangePassword(ChangePasswordRequest changePasswordRequest);
}
}
......@@ -16,7 +16,8 @@ namespace ApplicationCore.Services
public MedicineService(
IUnitOfWork<Medicine> medicineUnitOfWork,
IMapper Mapper )
IMapper Mapper
)
:base(medicineUnitOfWork , Mapper)
{
_specification = new MedicineWithIngredientsSpecification();
......@@ -24,12 +25,13 @@ namespace ApplicationCore.Services
}
public void AddToMedicalState(MedicalStateMedicineDTO medicalStateMedicineDto)
{
var medicalState = _unitOfWork.Entity.GetById(medicalStateMedicineDto.MedicineId, _specification).Result;
if (medicalState.MedicalStateMedicines is null)
medicalState.MedicalStateMedicines = new List<MedicalStateMedicine>();
foreach (var i in medicalState.MedicalStateMedicines)
{
if (
......@@ -54,28 +56,37 @@ namespace ApplicationCore.Services
public void RemoveFromMedicalState(MedicalStateMedicineDTO medicalStateMedicineDto)
{
var medicalState = _unitOfWork.MedicalStates.GetById(medicalStateMedicineDto.MedicalStateId, _medicalSpecification).Result;
if (medicalState.MedicalStateMedicines is null)
if (medicalState.MedicalStateMedicines is null) {
throw new DomainException("you dont have this medicine");
}
var d = _unitOfWork.Entity.GetById(medicalStateMedicineDto.MedicineId, _specification).Result;
if(! medicalState.Medicines.Remove(d))
throw new DomainException("you dont have this medicine");
if (!medicalState.Medicines.Remove(d)) {
throw new DomainException("you dont have this medicine");
}
_unitOfWork.MedicalStates.Update(medicalState);
_unitOfWork.Commit();
}
public MedicineDTO GetMedicineIngredentisDetails(int medicineId) {
return _mapper.Map<MedicineDTO>(_unitOfWork.Entity
.GetById(medicineId ,
_specification));
return _mapper.Map<MedicineDTO>(
_unitOfWork.Entity
.GetById(medicineId ,
_specification
)
);
}
public async Task<IEnumerable<MedicineIngredientDTO>> GetMedicineIngredients(int id)
{
var r = await _unitOfWork.Medicines.GetById(id,_specification);
return _mapper.Map<IEnumerable<MedicineIngredientDTO>>( r.Ingredients);
return _mapper.Map<IEnumerable<MedicineIngredientDTO>>( r.MedicineIngredients);
}
}
}
......@@ -9,18 +9,20 @@ using WebPresentation.Filters.ImageLoad;
using AutoMapper;
using ApplicationCore.Interfaces.IAuthentication;
using ApplicationCore.DTOs;
using WebPresentation.ViewModels;
namespace WebPresentation.Controllers
{
[AllowAnonymous]
public class AccessController : Controller
public class AccessController : BaseController
{
private readonly IMapper _mapper;
private readonly IAuthenticationManager _authenticationManager;
public AccessController(IAuthenticationManager authenticationManager,
IMapper mapper )
IMapper mapper,
UserManager<User> userManager ):base(userManager)
{
_mapper = mapper;
_authenticationManager = authenticationManager;
......@@ -76,14 +78,14 @@ namespace WebPresentation.Controllers
var result = await _authenticationManager.Register(registerInput);
if (result.Succeeded)
if (result.Success)
{
return LocalRedirect(Input.ReturnUrl);
}
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
ModelState.AddModelError(string.Empty, error);
}
}
......@@ -102,5 +104,30 @@ namespace WebPresentation.Controllers
return Redirect("/Home/Index");
}
}
[Authorize]
public async Task<IActionResult> ChangePassword(ChangePasswordViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
var dto = _mapper.Map<ChangePasswordRequest>(model);
dto.Email = GetCurrentUser().Email;
var result =await _authenticationManager.ChangePassword(dto);
if (!result.Success)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error);
}
return View(model);
}
return RedirectToAction("index","home");
}
}
}
}
......@@ -28,6 +28,7 @@ namespace WebPresentation.Controllers
}
return _criteriaProtected;
} set { _criteriaProtected = value; } }
public CRUDController(
UserManager<User> userManager,
IService<TDto> service,
......@@ -100,8 +101,15 @@ namespace WebPresentation.Controllers
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
public async Task<IActionResult> DeleteConfirmed(int id)
{
TDto DetailDto = await _service.GetDetails(id);
if (DetailDto == null || !_criteria(DetailDto))
{
return PartialView("PartialNotFound");
}
_service.Delete(id);
return RedirectToAction("Index");
}
......@@ -139,7 +147,7 @@ namespace WebPresentation.Controllers
if (id != viewModel.Id)
{
return NotFound();
return PartialView("PartialNotFound");
}
TDto dto ;
if (ModelState.IsValid)
......@@ -156,37 +164,38 @@ namespace WebPresentation.Controllers
return View("Error");
}
return RedirectToAction("Details",new { id=dto.Id});
return Json(new { success = true, redirectUrl = Url.Action("Details", new { id = viewModel.Id }) });
}
return View(viewModel);
return PartialView(viewModel);
}
public IActionResult Create()
{
return View();
return PartialView();
}
[HttpPost]
[ValidateAntiForgeryToken]
[StateValidationFilter]
[ImageLoadFilter]
public virtual IActionResult Create(TVModel viewModel, int id)
{
if (ModelState.IsValid)
TDto dto = _mapper.Map<TDto>(viewModel);
if (viewModel == null || !_criteria(dto))
{
return PartialView(viewModel);
}
dto = _service.Create(dto);
TDto dto = _mapper.Map<TDto>(viewModel);
if (viewModel == null || !_criteria(dto))
{
return View(viewModel);
}
dto = _service.Create(dto);
viewModel = _mapper.Map<TVModel>(dto);
viewModel = _mapper.Map<TVModel>(dto);
return Json(new { success = true, redirectUrl = Url.Action("Details", new { id = viewModel.Id }) });
return RedirectToAction("Details", new { id = viewModel.Id });
}
return View(viewModel);
}
#region json format
......
......@@ -59,7 +59,7 @@ namespace WebPresentation.Controllers
[HttpPost]
[ValidateAntiForgeryToken]
[ImageLoadFilter]
public IActionResult Edit(int id, [FromForm] PatientViewModel viewModel)
public async Task<IActionResult> Edit(int id, [FromForm] PatientViewModel viewModel)
{
if (id != viewModel.Id)
{
......@@ -75,7 +75,17 @@ namespace WebPresentation.Controllers
dto = _mapper.Map<PatientDTO>(viewModel);
dto.User.Avatar= viewModel.ImageName;
dto = _patientService.Update(dto);
{
var t = GetCurrentUser();
dto.User.UserName = t.UserName;
dto.User.CreationTime = t.CreationTime;
dto.User.Email = t.Email;
}
//dto.User.Patient = _mapper.Map<Patient>(dto);
//var r =await _userManager.UpdateAsync(dto.User);
// if (!r.Succeeded) {
// return View(viewModel);
// }
}
catch (DbUpdateConcurrencyException)
{
......
......@@ -10,6 +10,8 @@ using WebPresentation.ViewModels;
using AutoMapper;
using System.Collections.Generic;
using ApplicationDomain.Exceptions;
using WebPresentation.Filters.ImageLoad;
using WebPresentation.Filters.ModelStateValidation;
namespace WebPresentation.Controllers
{
......@@ -38,27 +40,24 @@ namespace WebPresentation.Controllers
[HttpPost]
[ValidateAntiForgeryToken]
[StateValidationFilter]
[ImageLoadFilter]
public override IActionResult Create(MedicalStateViewModel medicalState, int id)
{
if (ModelState.IsValid)
{
var uId = GetUserId();
var p = _patientService.GetByUserId(uId).Result.Id;
var patientId = _patientService.GetByUserId(uId).Result.Id;
if (medicalState.PrescriptionTime == DateTime.MinValue )
medicalState.PrescriptionTime = DateTime.Now;
var n= ((IMedicalStateService)_service).AddToPateint(p,_mapper.Map<MedicalStateDTO>(medicalState));
var n= ((IMedicalStateService)_service)
.AddToPateint(patientId, _mapper.Map<MedicalStateDTO>(medicalState));
return RedirectToAction("Details", "MedicalState" , new { Id =n.Id });
}
return View(medicalState);
}
protected override Func<MedicalStateDTO, bool> GetCriteria()
{
var u = _patientService.GetByUserId(GetUserId()).Result.Id;
_criteria = p => p.PatientId == u;
return _criteria;
}
#region json
......@@ -103,7 +102,7 @@ namespace WebPresentation.Controllers
MedicalStateMedicineDTO medicalStateMedicineModel = _mapper.Map<MedicalStateMedicineDTO>(medicalStateMedicine);
try
{
var medical = await _medicalStateService.GetDetails(medicalStateMedicine.MedicineId);
var medical = await _medicalStateService.GetDetails(medicalStateMedicine.MedicalStateId);
if (!_criteria(medical))
return Ok(new { message = "You try to Reomve a medicine for other patient and this is wrong , you shouldn't remove a medicine for others maybe this kill him", result = "faild" });
......@@ -149,5 +148,13 @@ namespace WebPresentation.Controllers
}
#endregion json
protected override Func<MedicalStateDTO, bool> GetCriteria()
{
var u = _patientService.GetByUserId(GetUserId()).Result.Id;
_criteria = p => p.PatientId == u;
return _criteria;
}
}
}
......@@ -7,6 +7,7 @@ using ApplicationCore.DTOs;
using System.Threading.Tasks;
using WebPresentation.ViewModels;
using AutoMapper;
using ApplicationDomain.Exceptions;
namespace WebPresentation.Controllers
{
......@@ -33,18 +34,36 @@ namespace WebPresentation.Controllers
[HttpPost]
public async Task<IActionResult> ReomveIngredient([FromBody] MedicineIngredientDTO medicineIngredientModel)
{
await _ingredientService.RemoveFromMedicine(medicineIngredientModel);
try
{
await _ingredientService.RemoveFromMedicine(medicineIngredientModel);
return Ok(new {message = "removed" ,result ="Successed"});
return Ok(new { message = "The Ingredient Removed Successfully", result = "add" });
}
catch (DomainException e)
{
return Ok(new { message = "Faild", result = e.Message });
}
}
[HttpPost]
public async Task<IActionResult> AddIngredient([FromBody] MedicineIngredientDTO medicineIngredientModel)
{
await _ingredientService.AddToMedicine(medicineIngredientModel);
return Ok(new { message = "added", result = "Successed" });
try
{
await _ingredientService.AddToMedicine(medicineIngredientModel);
return Ok(new { message = "The Ingredient Added Successfully", result = "add" });
}
catch (DomainException e ) {
return Ok(new { message = "Faild", result =e.Message });
}
}
public async Task<IActionResult> GetMedcineIngredient(int id) {
public async Task<IActionResult> GetMedicineIngredient(int id) {
var r = await ((IMedicineService)_service).GetMedicineIngredients(id);
......
......@@ -17,12 +17,9 @@ namespace WebPresentation.Filters.ImageLoad
var imageUploaded = context.ActionArguments.Values.Where(p => p is IImageForm).FirstOrDefault();
var imageService = context.HttpContext.RequestServices.GetService(typeof(IImageService));
if(
(((IImageForm)imageUploaded).ImageFile != null )
&&
(((IImageForm)imageUploaded).ImageFile.Length != 0)){
if(imageUploaded is not null ){
var imagePath = ((IImageService)imageService).SaveImageAsync(((IImageForm)imageUploaded).ImageFile,context.Controller.GetType().Name).Result;
if(imagePath != "")
((IImageForm)imageUploaded).ImageName = imagePath; // You can pass other information as needed
}
......
......@@ -21,7 +21,7 @@ namespace WebPresentation.Filters.ModelStateValidation
{
var model = context.ActionArguments.Values.Where(p=> p is not int ).FirstOrDefault();
var actionName = context.ActionDescriptor.RouteValues["action"];
context.Result = controller.View(actionName, model);
context.Result = controller.PartialView(actionName, model);
return;
}
else
......
......@@ -10,6 +10,11 @@ namespace ApplicationCore.Mappere
{
public ViewModelObjectMapper()
{
CreateMap<ChangePasswordRequest, ChangePasswordViewModel>()
.ForMember(dest => dest.ConfirmPassword, opt => opt.Ignore());
CreateMap<ChangePasswordViewModel, ChangePasswordRequest>();
CreateMap<MedicineViewModel, MedicineDTO>()
.ForMember(dest => dest.Image, opt => opt.MapFrom(src => src.ImageName)) // Map ImageName from MedicineViewModel to Image in MedicineDTO
.ForMember(dest => dest.Ingredients, opt => opt.MapFrom(src => src.Ingredients))
......
......@@ -26,8 +26,15 @@ namespace WebPresentation.Midlewares
catch (Exception ex)
{
await HandleExceptionAsync(httpContext, ex);
}
}
private static Task HandleExceptionAsync(HttpContext context, Exception exception)
{
context.Response.Redirect("/Home/Error");
return Task.CompletedTask;
}
}
}
......@@ -25,10 +25,13 @@ namespace WebPresentation.Services
public async Task<string> SaveImageAsync(IFormFile file,String folderName)
{
if (file is null)
return "";
var uploadsFolderPath = Path.Combine(_uploadsFolderPath, folderName);
var uniqueFileName = Guid.NewGuid().ToString() + "_" + file.FileName;
var filePath = Path.Combine(uploadsFolderPath, uniqueFileName);
if (file.Length > 0)
......
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WebPresentation.ViewModels
{
public class ChangePasswordViewModel
{
[Required]
[DataType(DataType.Password)]
[Display(Name = "Current password")]
public string CurrentPassword { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at most {1} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "New password")]
public string NewPassword { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm new password")]
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
}
......@@ -16,11 +16,11 @@ namespace WebPresentation.ViewModels
[Required]
[MinLength(5)]
public String StateName { get; set; }
[Display(Name = "State Name")]
[Display(Name = "State Description")]
[Required]
public String StateDescription { get; set; }
[Display(Name = "State Name")]
[Display(Name = "Prescription Time")]
[Required]
public DateTime PrescriptionTime { get; set; }
public ICollection<MedicineViewModel> Medicines { get; set; }
......
using System;
using System.ComponentModel.DataAnnotations;
namespace WebPresentation.ViewModels
{
public class CategoryViewModel : BaseViewModel
{
[Display(Name = "Category Name")]
public String Name { get; set; }
}
}
\ No newline at end of file
using System;
using System.ComponentModel.DataAnnotations;
namespace WebPresentation.ViewModels
{
public class MedicineTypeViewModel : BaseViewModel
{
[Display(Name = "Medicine Type ")]
public String TypeName { get; set; }
}
}
\ No newline at end of file
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace WebPresentation.ViewModels
{
public class MedicineViewModel : BaseViewModel , IImageForm
{
[Display(Name ="Trade Name ")]
public String TradeName { get; set; }
[Display(Name = "Scintific Name ")]
public String ScintificName { get; set; }
[Display(Name = "Manufacture Name ")]
public String ManufactureName { get; set; }
[Display(Name = "Side Effect")]
public String SideEffect { get; set; }
public String Description { get; set; }
public int Price { get; set; }
......
......@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
......@@ -14,6 +15,7 @@ namespace WebPresentation.ViewModels
public String UserId { get; set; }
public User User { get; set; }
[Display(Name = "Your BIO ")]
public String BIO { get; set; }
public ICollection<MedicalStateViewModel> MedicalStates { get; set; }
......
@model WebPresentation.ViewModels.ChangePasswordViewModel
<section class="page-section py-5">
<form asp-action="ChangePassword" method="post">
<div class="form-group">
<label asp-for="CurrentPassword"></label>
<input asp-for="CurrentPassword" class="form-control" />
<span asp-validation-for="CurrentPassword" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="NewPassword"></label>
<input asp-for="NewPassword" class="form-control" />
<span asp-validation-for="NewPassword" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ConfirmPassword"></label>
<input asp-for="ConfirmPassword" class="form-control" />
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Change Password</button>
</form>
</section>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
......@@ -83,7 +83,7 @@
<div class="form-group row mb-4">
<div data-mdb-input-init class="form-outline col">
<div data-mdb-input-init class="col">
<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>
......
......@@ -6,7 +6,7 @@
}
<section class="page-section">
<div class="container ">
<div class="container py-5">
<div class="row justify-content-center">
<div class="">
<div class="card shadow-sm">
......
......@@ -15,7 +15,7 @@
ViewData["userName"] = Model.User.FirstName + " " + Model.User.LastName;
ViewBag.Avatar = Model.User.Avatar;
ViewData["Controller"] = "Home";
ViewData["Controller"] = "MedicalState";
ViewBag.owner = Model;
var DummyModel = new MedicalState { StateName="state name" , StateDescription="Description" , PrescriptionTime=DateTime.Now};
......@@ -61,9 +61,8 @@
<div class="icon"><i class="fas fa-heartbeat"></i></div>
<h4> New Medical State</h4>
<p>Click on the Create Button to Create a new Medical State</p>
<a asp-controller="Medicalstate" asp-action="Create" class="btn btn-primary">
Create
</a>
<button class="btn btn-primary ml-2 btn-create">Create </button>
</div>
</div>
......@@ -144,6 +143,7 @@
<h2 class=" text-center text-uppercase text-secondary mb-0">For Account Details : </h2><br />
<a class="btn btn-secondary" asp-action="Details" asp-controller="Home">Detail Your profile</a>
<a class="btn btn-primary" asp-action="Edit" asp-controller="Home">Edit Your profile</a>
<a class="btn btn-primary" asp-action="ChangePassword" asp-controller="Access">Changeyour password </a>
<!-- Icon Divider -->
......@@ -152,26 +152,26 @@
</section>
<!-- Contact Section -->
<section class="page-section" id="Create">
<div class="container">
<!--<section class="page-section" id="Create">
<div class="container">-->
<!-- Contact Section Heading -->
<h2 class="page-section-heading text-center text-uppercase text-secondary mb-0">Create New Medical State</h2>
<!--<h2 class="page-section-heading text-center text-uppercase text-secondary mb-0">Create New Medical State</h2>-->
<!-- Icon Divider -->
<div class="divider-custom">
<!--<div class="divider-custom">
<div class="divider-custom-line"></div>
<div class="divider-custom-icon">
<i class="fas fa-star"></i>
</div>
<div class="divider-custom-line"></div>
</div>
</div>-->
<!-- Contact Section Form -->
<div class="row">
<div class="col-lg-8 mx-auto">
<!--<div class="row">
<div class="col-lg-8 mx-auto">-->
<!-- To configure the contact form email address, go to mail/contact_me.php and update the email address in the PHP file on line 19. -->
<form name="sentMessage" id="contactForm" novalidate="novalidate"
<!--<form name="sentMessage" id="contactForm" novalidate="novalidate"
method="post" asp-controller="MedicalState" asp-action="Create">
<div class="control-group">
<div class="form-group floating-label-form-group controls mb-0 pb-2">
......@@ -204,7 +204,7 @@
</div>
</div>
</section>
</section>-->
<!-- Modals -->
@foreach (var item in Model.MedicalStates)
......
......@@ -2,17 +2,24 @@
@{
ViewData["Title"] = "Create";
Layout = "_AdminLayout";
ViewData["Controller"] = "Ingredient";
}
<section class="page-section" style="background-color: #f4f5f7;">
<div class="modal-header">
<h5 class="modal-title" id="modalEditLabel">Create Ingredient</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card shadow-lg p-3 mb-5 bg-white rounded">
<div class="card-body">
<h1 class="card-title display-4 mb-4 text-center">Create New Ingredient</h1>
<div class="col ">
<div class=" shadow-lg p-3 mb-5 bg-white rounded">
<div class="">
<hr />
<form asp-action="Create" method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
......@@ -36,13 +43,13 @@
</div>
</div>
<div class="text-center">
<a asp-action="Index" class="btn btn-secondary">Back to List</a>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</section>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
......@@ -32,7 +32,8 @@
<div class="col">
<h2 class="mb-4 animate__animated animate__fadeIn">Ingredients List</h2>
<p class="animate__animated animate__fadeIn">
<a asp-action="Create" class="btn btn-primary animate__animated animate__zoomIn">Create New</a>
<button class="btn btn-success ml-2 btn-create">Create New </button>
</p>
<div class="table-responsive animate__animated animate__fadeIn">
<table id="datatablesSimple" class="table table-striped table-bordered">
......
......@@ -7,49 +7,55 @@
}
<section class="page-section" style="background-color: #f4f5f7;">
<div class="container py-5 h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col-12 col-md-8 col-lg-6 mb-4 mb-lg-0">
<div class="card shadow-sm" style="border-radius: .5rem;">
<div class="card-header text-center bg-primary text-white" style="border-top-left-radius: .5rem; border-top-right-radius: .5rem;">
<h4>Create Medical State</h4>
</div>
<div class="card-body">
<form asp-action="Create" asp-controller="MedicalState">
<div asp-validation-summary="ModelOnly" class="alert alert-danger"></div>
<div class="form-group mb-3">
<label asp-for="StateName" class="form-label"></label>
<input asp-for="StateName" class="form-control" />
<span asp-validation-for="StateName" class="text-danger"></span>
</div>
<div class="form-group mb-3">
<label asp-for="PrescriptionTime" class="form-label"></label>
<input asp-for="PrescriptionTime" class="form-control" />
<span asp-validation-for="PrescriptionTime" class="text-danger"></span>
</div>
<div class="form-group mb-4">
<label asp-for="StateDescription" class="form-label"></label>
<input asp-for="StateDescription" class="form-control" />
<span asp-validation-for="StateDescription" class="text-danger"></span>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-block">Create</button>
</div>
</form>
</div>
<div class="card-footer text-center">
<a asp-action="Index" class="btn btn-link">Back to List</a>
<div class="modal-header">
<h5 class="modal-title" id="modalEditLabel">Create Medical Case</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="container h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col-12 ">
<div class="card shadow-sm" style="border-radius: .5rem;">
<div class="card-header text-center bg-primary text-white" style="border-top-left-radius: .5rem; border-top-right-radius: .5rem;">
<h4>Create Medical State</h4>
</div>
<div class="card-body">
<form asp-action="Create" asp-controller="MedicalState">
<div asp-validation-summary="ModelOnly" class="alert alert-danger"></div>
<div class="form-group mb-3">
<label asp-for="StateName" class="form-label"></label>
<input asp-for="StateName" class="form-control" />
<span asp-validation-for="StateName" class="text-danger"></span>
</div>
<div class="form-group mb-3">
<label asp-for="PrescriptionTime" class="form-label"></label>
<input asp-for="PrescriptionTime" class="form-control" />
<span asp-validation-for="PrescriptionTime" class="text-danger"></span>
</div>
<div class="form-group mb-4">
<label asp-for="StateDescription" class="form-label"></label>
<input asp-for="StateDescription" class="form-control" />
<span asp-validation-for="StateDescription" class="text-danger"></span>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-create btn-primary btn-block">Create</button>
</div>
</form>
</div>
<div class="card-footer text-center">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
......@@ -2,7 +2,7 @@
@{
ViewData["Title"] = "Edit";
ViewData["Controller"] = "MedicalState";
}
......@@ -17,9 +17,9 @@
<div class="container h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col p-2">
<div class="card mb-3 shadow-sm" style="border-radius: .5rem;">
<div class=" mb-3 shadow-sm" style="border-radius: .5rem;">
<div class="card-body">
<div class="">
<form asp-action="Edit" asp-controller="MedicalState">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group mb-3">
......
......@@ -8,7 +8,9 @@
<div class="container mt-5">
<div class="row mb-4">
<div class="col text-center">
<h3>Create New <a asp-action="Create" asp-controller="MedicalState" class="btn btn-success ml-2">Create</a></h3>
do you have a new Medical case ?
<button class="btn btn-success ml-2 btn-create" >Create</button>
</div>
</div>
</div>
......@@ -30,11 +32,11 @@
@foreach (var item in Model)
{
<div class="container py-5 h-100">
<div class="container p-4 h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col col-lg-8 mb-4 mb-lg-0">
<div class="card mb-3" style="border-radius: .5rem;">
<div class="row g-0">
<div class="p-4 row g-0">
<div class="col-md-4 gradient-custom text-center text-black"
style="border-top-left-radius: .5rem; border-bottom-left-radius: .5rem;">
......@@ -44,28 +46,23 @@
</div>
<h5>@item.StateName</h5>
<p>Prescriped At : @item.PrescriptionTime</p>
<button class="btn btn-warning btn-edit" data-id="@item.Id">Edit</button>
<button class="btn btn-danger btn-delete" data-id="@item.Id">Delete</button>
<a asp-action="Index">
<i class="far fa-backward">
<button class="btn btn-sm btn-warning btn-edit" data-id="@item.Id">Edit</button>
<button class="btn btn-sm btn-danger btn-delete" data-id="@item.Id">Delete</button>
</i>
Go Back
</a>
</div>
<div class="col-md-8">
<div class="card-body p-4">
<h6>Information</h6>
<hr class="mt-0 mb-4">
<div class="row pt-1">
<div class="col-6 mb-3">
<h6>Description</h6>
<p class="text-muted">@item.StateDescription</p>
<div class="col-12 mb-3">
<h6>
Description :
<span class="text-muted">@item.StateDescription</span>
</h6>
</div>
<div class="col-6 mb-3">
<div class="col-12 mb-3">
<h6>Medicine count :@item.Medicines.Count()</h6>
</div>
</div>
......
......@@ -3,88 +3,96 @@
@{
ViewData["Title"] = "Create";
Layout = "_AdminLayout";
ViewData["Controller"] = "Medicine";
// Layout = "_AdminLayout";
}
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card shadow-sm">
<div class="card-body">
<h1 class="card-title mb-4">Create New Medicine</h1>
<div class="modal-header">
<h5 class="modal-title" id="modalEditLabel">Create New Medicine</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form asp-action="Create" method="post" enctype="multipart/form-data">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group row mb-3">
<div class="col-md-6">
<label asp-for="TradeName" class="control-label">Trade Name</label>
<input asp-for="TradeName" class="form-control" />
<span asp-validation-for="TradeName" class="text-danger"></span>
</div>
<div class="col-md-6">
<label asp-for="ScintificName" class="control-label">Scientific Name</label>
<input asp-for="ScintificName" class="form-control" />
<span asp-validation-for="ScintificName" class="text-danger"></span>
</div>
</div>
<div class="container py-5">
<div class="row justify-content-center">
<div class="col">
<div class=" shadow-sm">
<div class="">
<form asp-action="Create" method="post" enctype="multipart/form-data">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group mb-3">
<label asp-for="Description" class="control-label">Description</label>
<textarea asp-for="Description" rows="4" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<div class="form-group row mb-3">
<div class="col-md-6">
<label asp-for="SideEffect" class="control-label">Side Effects</label>
<input asp-for="SideEffect" class="form-control" />
<span asp-validation-for="SideEffect" class="text-danger"></span>
<div class="form-group row mb-3">
<div class="col-md-6">
<label asp-for="TradeName" class="control-label">Trade Name</label>
<input asp-for="TradeName" class="form-control" />
<span asp-validation-for="TradeName" class="text-danger"></span>
</div>
<div class="col-md-6">
<label asp-for="ScintificName" class="control-label">Scientific Name</label>
<input asp-for="ScintificName" class="form-control" />
<span asp-validation-for="ScintificName" class="text-danger"></span>
</div>
</div>
<div class="col-md-6">
<label asp-for="Dosage" class="control-label">Dosage</label>
<input asp-for="Dosage" class="form-control" />
<span asp-validation-for="Dosage" class="text-danger"></span>
<div class="form-group mb-3">
<label asp-for="Description" class="control-label">Description</label>
<textarea asp-for="Description" rows="4" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
</div>
<div class="form-group row mb-3">
<div class="col-md-6">
<label asp-for="Category.Name" class="control-label">Category</label>
<input asp-for="Category.Name" class="form-control" />
<span asp-validation-for="Category.Name" class="text-danger"></span>
<div class="form-group row mb-3">
<div class="col-md-6">
<label asp-for="SideEffect" class="control-label">Side Effects</label>
<input asp-for="SideEffect" class="form-control" />
<span asp-validation-for="SideEffect" class="text-danger"></span>
</div>
<div class="col-md-6">
<label asp-for="Dosage" class="control-label">Dosage</label>
<input asp-for="Dosage" class="form-control" />
<span asp-validation-for="Dosage" class="text-danger"></span>
</div>
</div>
<div class="col-md-6">
<label asp-for="ManufactureName" class="control-label">Manufacturer</label>
<input asp-for="ManufactureName" class="form-control" />
<span asp-validation-for="ManufactureName" class="text-danger"></span>
<div class="form-group row mb-3">
<div class="col-md-6">
<label asp-for="Category.Name" class="control-label">Category</label>
<input asp-for="Category.Name" class="form-control" />
<span asp-validation-for="Category.Name" class="text-danger"></span>
</div>
<div class="col-md-6">
<label asp-for="ManufactureName" class="control-label">Manufacturer</label>
<input asp-for="ManufactureName" class="form-control" />
<span asp-validation-for="ManufactureName" class="text-danger"></span>
</div>
</div>
</div>
<div class="form-group mb-3">
<label asp-for="ImageFile" class="control-label">Image File</label>
<input asp-for="ImageFile" class="form-control" />
<span asp-validation-for="ImageFile" class="text-danger"></span>
</div>
<div class="form-group mb-3">
<label asp-for="ImageFile" class="control-label">Image File</label>
<input asp-for="ImageFile" class="form-control" />
<span asp-validation-for="ImageFile" class="text-danger"></span>
</div>
<div class="form-group mb-4">
<label asp-for="MedicineType.TypeName" class="control-label">Medicine Type</label>
<input asp-for="MedicineType.TypeName" class="form-control" />
<span asp-validation-for="MedicineType.TypeName" class="text-danger"></span>
</div>
<div class="form-group mb-4">
<label asp-for="MedicineType.TypeName" class="control-label">Medicine Type</label>
<input asp-for="MedicineType.TypeName" class="form-control" />
<span asp-validation-for="MedicineType.TypeName" class="text-danger"></span>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Create</button>
<a asp-action="Index" class="btn btn-secondary ms-2">Back to List</a>
</div>
</form>
<div class="form-group">
<button type="submit" class="btn btn-primary">Create</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
......@@ -30,7 +30,7 @@
<div class="col">
<h2 class="mb-4 animate__animated animate__fadeIn">Medicines Details</h2>
<p class="animate__animated animate__fadeIn">
<a asp-action="Create" class="btn btn-primary animate__animated animate__zoomIn">Create New</a>
<button class="btn btn-success ml-2 btn-create">Create New </button>
</p>
<div class="table-responsive">
<table class="table table-striped table-bordered" id="datatablesSimple">
......@@ -57,9 +57,9 @@
<td>@Html.DisplayFor(modelItem => item.Price)</td>
<td>
<div class="d-flex">
<button class="btn btn-warning btn-edit m-1" data-id="@item.Id">Edit</button>
<button class="btn btn-danger btn-delete m-1 " data-id="@item.Id">Delete</button>
<a asp-action="Details" asp-controller="Medicine" asp-route-id="@item.Id" class="m-1 btn btn-danger" title="Details">Details</a>
<button class="btn btn-sm btn-warning btn-edit m-1" data-id="@item.Id">Edit</button>
<button class="btn btn-sm btn-danger btn-delete m-1 " data-id="@item.Id">Delete</button>
<a asp-action="Details" asp-controller="Medicine" asp-route-id="@item.Id" class="m-1 btn btn-sm btn-info" title="Details">Details</a>
</div>
</td>
</tr>
......
......@@ -12,11 +12,11 @@
<meta name="description" content="" />
<meta name="author" content="" />
<title>DashBoard - @ViewData["Title"]</title>
<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.min.css" rel="stylesheet" />
@*<link href="https://cdn.jsdelivr.net/npm/simple-datatables@7.1.2/dist/style.min.css" rel="stylesheet" />*@
<link href="/css/styles.css" rel="stylesheet" />
<link href="/favicon.png" rel="icon">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
@* <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>*@
<!-- Custom fonts for this theme -->
<link href="~/fonts/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
......@@ -73,7 +73,7 @@
<!-- Patient Managment -->
<a class="nav-link collapsed"
asp-action="Inedx" asp-controller="Patients"
asp-action="Index" asp-controller="Patients"
data-bs-toggle="collapse" data-bs-target="#collapseLayouts" aria-expanded="false" aria-controls="collapseLayouts">
<div class="sb-nav-link-icon"><i class="fas fa-columns"></i></div>
Patients Managment
......@@ -81,13 +81,13 @@
</a>
<div class="collapse" id="collapseLayouts" aria-labelledby="headingOne" data-bs-parent="#sidenavAccordion">
<nav class="sb-sidenav-menu-nested nav">
<a class="nav-link" asp-controller="Patients" asp-action="Create">Add Patient </a>
<a class="nav-link" asp-controller="Patients" asp-action="Index">ALL Patients </a>
</nav>
</div>
<!-- Ingredients Managment -->
<a class="nav-link collapsed" asp-action="Index" asp-controller="Ingredients" data-bs-toggle="collapse" data-bs-target="#ing" aria-expanded="false" aria-controls="collapseLayouts">
<a class="nav-link collapsed" asp-action="Index" asp-controller="Ingredient" data-bs-toggle="collapse" data-bs-target="#ing" aria-expanded="false" aria-controls="collapseLayouts">
<div class="sb-nav-link-icon"><i class="fas fa-columns"></i></div>
Ingredients Manage
<div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
......@@ -148,7 +148,10 @@
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="/js/scripts.js"></script>
<script src="/lib/jquery/dist//jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
@RenderSection("Scripts", required: false);
......@@ -169,6 +172,13 @@
</div>
</div>
</div>
<div class="modal fade" id="modal-create" tabindex="-1" role="dialog" aria-labelledby="modalDeleteLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<!-- Content loaded via AJAX -->
</div>
</div>
</div>
<script>
$(document).ready(function () {
// Load the Edit form in the modal
......@@ -178,16 +188,69 @@
$('#modal-edit').find('.modal-content').load(`/${controller}/Edit/` + id);
$('#modal-edit').modal('show');
});
$(document).on('submit', '#modal-edit form', function (event) {
event.preventDefault();
var form = $(this);
var url = form.attr('action');
var formData = new FormData(this);
$.ajax({
url: url,
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function (response) {
if (response.success) {
// Redirect to the details page if successful
window.location.href = response.redirectUrl;
} else {
// Replace the modal content with the returned form including validation errors
$('#modal-edit').find('.modal-content').html(response);
}
}
});
});
$('.btn-create').on('click', function () {
var controller = `@ViewData["Controller"]`;
$('#modal-create').find('.modal-content').load(`/${controller}/create/` );
$('#modal-create').modal('show');
});
$('.btn-delete').on('click', function () {
var id = $(this).data('id');
var controller = `@ViewData["Controller"]`;
$('#modal-delete').find('.modal-content').load(`/${controller}/Delete/` + id);
$('#modal-delete').modal('show');
});
$(document).on('submit', '#modal-create form', function (event) {
event.preventDefault();
var form = $(this);
var url = form.attr('action');
var formData = new FormData(this);
$.ajax({
url: url,
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function (response) {
if (response.success) {
// Redirect to the details page if successful
window.location.href = response.redirectUrl;
} else {
// Replace the modal content with the returned form including validation errors
$('#modal-create').find('.modal-content').html(response);
}
}
});
});
});
</script>
<!-- Bootstrap core JavaScript -->
<script src="~/js/jquery.min.js"></script>
<script src="~/js/bootstrap.bundle.min.js"></script>
......@@ -195,6 +258,7 @@
<!-- Plugin JavaScript -->
<script src="~/js/jquery.easing.min.js"></script>
<!-- Custom scripts for this template -->
@*<script src="~/js/freelancerAd.min.js"></script>*@
<!-- Custom scripts for this template -->
......
......@@ -45,7 +45,7 @@
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item mx-0 mx-lg-1">
<a class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger" asp-action="Index" asp-controller="MedicalState">Medicines</a>
<a class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger" asp-action="Index" asp-controller="MedicalState">Medicines Cases</a>
</li>
<li class="nav-item mx-0 mx-lg-1">
<a class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger" asp-action="Index" asp-controller="Home">Home</a>
......@@ -140,6 +140,13 @@
</div>
</div>
</div>
<div class="modal fade" id="modal-create" tabindex="-1" role="dialog" aria-labelledby="modalDeleteLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<!-- Content loaded via AJAX -->
</div>
</div>
</div>
<div class="modal fade" id="modal-edit" tabindex="-1" role="dialog" aria-labelledby="modalCreateLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
......@@ -150,11 +157,66 @@
<script>
$(document).ready(function () {
// Load the Edit form in the modal
$('.btn-edit').on('click', function () {
var id = $(this).data('id');
$('.btn-edit').on('click', function () {
var id = $(this).data('id');
var controller = `@ViewData["Controller"]`;
$('#modal-edit').find('.modal-content').load(`/${controller}/Edit/` + id, function () {
$('#modal-edit').modal('show');
});
});
// Function to handle form submission
$(document).on('submit', '#modal-edit form', function (event) {
event.preventDefault();
var form = $(this);
var url = form.attr('action');
var formData = new FormData(this);
$.ajax({
url: url,
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function (response) {
if (response.success) {
// Redirect to the details page if successful
window.location.href = response.redirectUrl;
} else {
// Replace the modal content with the returned form including validation errors
$('#modal-edit').find('.modal-content').html(response);
}
}
});
}); $(document).on('submit', '#modal-create form', function (event) {
event.preventDefault();
var form = $(this);
var url = form.attr('action');
var formData = new FormData(this);
$.ajax({
url: url,
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function (response) {
if (response.success) {
// Redirect to the details page if successful
window.location.href = response.redirectUrl;
} else {
// Replace the modal content with the returned form including validation errors
$('#modal-create').find('.modal-content').html(response);
}
}
});
});
$('.btn-create').on('click', function () {
var controller = `@ViewData["Controller"]`;
$('#modal-edit').find('.modal-content').load(`/${controller}/Edit/` + id);
$('#modal-edit').modal('show');
$('#modal-create').find('.modal-content').load(`/${controller}/create/` );
$('#modal-create').modal('show');
});
$('.btn-delete').on('click', function () {
......
ee5748e123c05b8e601c75f3773a2aa816b62a99
adbd2b4013ece48063887b27035f879c92d79512
15cb97b8a060c155cc9b00ed27a476ac44f14fb8
0da6c7b81becaa0cb2886b1309a5a53838d012f3
......@@ -189,3 +189,4 @@ C:\Users\HASAN\Desktop\Medic\WebPresentation\obj\Debug\net5.0\Razor\Views\Patien
C:\Users\HASAN\Desktop\Medic\WebPresentation\obj\Debug\net5.0\Razor\Views\Patients\Details.cshtml.g.cs
C:\Users\HASAN\Desktop\Medic\WebPresentation\obj\Debug\net5.0\Razor\Views\Patients\Delete.cshtml.g.cs
C:\Users\HASAN\Desktop\Medic\WebPresentation\obj\Debug\net5.0\Razor\Views\Shared\PartialNotFound.cshtml.g.cs
C:\Users\HASAN\Desktop\Medic\WebPresentation\obj\Debug\net5.0\Razor\Views\Access\ChangePassword.cshtml.g.cs
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