Commit cbdb40d0 authored by hasan khaddour's avatar hasan khaddour

fix s

parent f329fd46
using ApplicationCore.DomainModel; using ApplicationCore.DomainModel;
using ApplicationCore.Interfaces; using ApplicationCore.Interfaces;
using ApplicationDomain.Entities; using ApplicationDomain.Entities;
using Microsoft.AspNetCore.Authorization; using AutoMapper;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace WebPresentation.Controllers namespace WebPresentation.Controllers
...@@ -15,7 +12,10 @@ namespace WebPresentation.Controllers ...@@ -15,7 +12,10 @@ namespace WebPresentation.Controllers
public class CRUDController<T> : BaseController where T : DomainBase public class CRUDController<T> : BaseController where T : DomainBase
{ {
protected readonly IService<T> _service; protected readonly IService<T> _service;
public CRUDController(UserManager<User> userManager, IService<T> service) public CRUDController(
UserManager<User> userManager,
IService<T> service
)
:base(userManager) :base(userManager)
{ {
...@@ -60,7 +60,7 @@ namespace WebPresentation.Controllers ...@@ -60,7 +60,7 @@ namespace WebPresentation.Controllers
[HttpPost, ActionName("Delete")] [HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken] // [ValidateAntiForgeryToken]
public IActionResult DeleteConfirmed(int id) public IActionResult DeleteConfirmed(int id)
{ {
_service.Delete(id); _service.Delete(id);
......
using ApplicationDomain.Entities; using ApplicationDomain.Entities;
using ApplicationCore.Interfaces.IServices; using ApplicationCore.Interfaces.IServices;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using ApplicationCore.DomainModel; using ApplicationCore.DomainModel;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace WebPresentation.Controllers namespace WebPresentation.Controllers
{ {
...@@ -24,9 +20,11 @@ namespace WebPresentation.Controllers ...@@ -24,9 +20,11 @@ namespace WebPresentation.Controllers
} }
public async Task<IActionResult> GetIngredients()
{
var s = await _service.GetAll();
return Ok(s);
}
} }
} }
...@@ -67,39 +67,96 @@ namespace WebPresentation.Controllers ...@@ -67,39 +67,96 @@ namespace WebPresentation.Controllers
} }
//[HttpGet]
//public IActionResult AddMedicine(int id)
//{
// var all = _medicineService.GetAll();
// ViewBag.MedicalStateId = id;
// return View(all);
//}
//[HttpPost]
//[ActionName("AddMedicine")]
//public IActionResult AddMedicineT(int id, int med)
//{
// _medicineService.AddToMedicalState(new MedicalStateMedicineModel{MedicalStateId=id ,MedicineId=med });
// return RedirectToAction("Details", "MedicalState", new { Id = id });
//}
//[ActionName("RemoveMedicine")]
//public IActionResult RemoveMedicinej(int id, int med)
//{
// _medicineService.RemoveFromMedicalState(new MedicalStateMedicineModel { MedicalStateId = id, MedicineId = med });
// return RedirectToAction("Details", "MedicalState", new { Id = id });
//}
#region json
[HttpGet] [HttpGet]
public IActionResult AddMedicine(int id) public JsonResult GetMedicalStateMedicine(int id) {
{
var all = _medicineService.GetAll(); var r = _medicalStateService.GetDetails(id).Result.Medicines;
ViewBag.MedicalStateId = id; return Json(r);
return View(all);
} }
[HttpPost] [HttpPost]
public IActionResult AddMedicine(int id, int med)
public JsonResult AddMedicine([FromBody]MedicalStateMedicineModel medicalStateMedicineModel)
{ {
_medicineService.AddToMedicalState(new MedicalStateMedicineModel{MedicalStateId=id ,MedicineId=med }); try
{
_medicineService.AddToMedicalState(medicalStateMedicineModel);
return RedirectToAction("Details", "MedicalState", new { Id = id }); return Json("Added");
} }
catch
{
return Json("faild");
}
}
[HttpPost] [HttpPost]
public IActionResult RemoveMedicine(int id, int med) public JsonResult RemoveMedicine([FromBody]MedicalStateMedicineModel medicalStateMedicineModel)
{ {
_medicineService.RemoveFromMedicalState(new MedicalStateMedicineModel { MedicalStateId = id, MedicineId = med }); _medicineService.RemoveFromMedicalState(medicalStateMedicineModel);
return RedirectToAction("Details", "MedicalState", new { Id = id }); return Json("Reomved");
} }
#region json [Authorize(Roles = "patient")]
public async Task<JsonResult> GetDetails(int? id)
{
if (id is null)
{
return Json("");
}
else
{
MedicineModel TModel = await _medicineService.GetDetails((int)id);
if (TModel is null)
return Json("");
return Json(TModel);
}
}
[Authorize(Roles = "patient")]
[HttpGet] [HttpGet]
public JsonResult GetMedicalStateMedicine(int id) {
var r = _medicalStateService.GetDetails(id).Result.Medicines; public JsonResult GetMedicines()
return Json(r); {
var all = _medicineService.GetAll().Result;
return new JsonResult(all);
} }
#endregion json #endregion json
} }
} }
...@@ -4,13 +4,8 @@ using ApplicationCore.Interfaces.IServices; ...@@ -4,13 +4,8 @@ using ApplicationCore.Interfaces.IServices;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using ApplicationCore.DomainModel; using ApplicationCore.DomainModel;
using System.Threading.Tasks;
namespace WebPresentation.Controllers namespace WebPresentation.Controllers
{ {
...@@ -38,101 +33,41 @@ namespace WebPresentation.Controllers ...@@ -38,101 +33,41 @@ namespace WebPresentation.Controllers
[Authorize(Roles = "Admin")] [Authorize(Roles = "Admin")]
public IActionResult AddIngredints(int id ) { [HttpPost]
var s = _ingredientService.GetAll().Result; public IActionResult ReomveIngredient([FromBody] MedicineIngredientModel medicineIngredientModel)
ViewBag.MedicineId = id;
return View(s);
}
[Authorize(Roles = "Admin")]
public IActionResult GetIngredints(int id)
{
var s = _ingredientService.GetAll().Result;
ViewBag.MedicineId = id;
return Ok(s);
}
[Authorize(Roles = "Admin")]
public IActionResult ReomveIngredints(int id ,int ing )
{ {
_ingredientService.RemoveFromMedicine(new MedicineIngredientModel {IngredientId=ing , MedicineId=id }); _ingredientService.RemoveFromMedicine(medicineIngredientModel);
return Ok(new {message = "removed" }); return Ok(new {message = "removed" });
} }
[Authorize(Roles = "Admin")] [Authorize(Roles = "Admin")]
[HttpPost] [HttpPost]
public IActionResult AddIngredintsT( MedicineIngredientModel medicineIngredientModel) public async Task<IActionResult> AddIngredints([FromBody] MedicineIngredientModel medicineIngredientModel)
{ {
_ingredientService.AddToMedicine(medicineIngredientModel); await _ingredientService.AddToMedicine(medicineIngredientModel);
return Ok(new { message = "added"}); return Ok(new { message = "added"});
} }
[Authorize(Roles = "Admin")]
[HttpPost]
public IActionResult AddIngredints(int id , int med ,int ratio )
{
_ingredientService.AddToMedicine(new MedicineIngredientModel {Id=id ,MedicineId=med ,Ratio=ratio });
return RedirectToAction("Details","Medicine", new { Id = med}) ;
}
#region json #region json
[Authorize(Roles ="patient")] //[Authorize(Roles = "Admin")]
public async Task<JsonResult> GetDetails(int? id) //public IActionResult AddIngredints(int id)
{ //{
// var s = _ingredientService.GetAll().Result;
if (id is null) // ViewBag.MedicineId = id;
{ // return View(s);
return Json("");
} //}
else //[Authorize(Roles = "Admin")]
{ //[HttpPost]
MedicineModel TModel = await _service.GetDetails((int)id); //public IActionResult AddIngredints(int id, int med, int ratio)
if (TModel is null) //{
return Json(""); // _ingredientService.AddToMedicine(new MedicineIngredientModel { Id = id, MedicineId = med, Ratio = ratio });
return Json(TModel); // return RedirectToAction("Details", "Medicine", new { Id = med });
} //}
}
[Authorize(Roles = "patient")]
[HttpGet]
public JsonResult GetMedicines()
{
var all = _medicineService.GetAll().Result;
return new JsonResult(all);
}
[Authorize(Roles = "patient")]
[HttpPost]
public JsonResult AddMedicineT(int id, int med)
{
try
{
((IMedicineService)_service).AddToMedicalState(new MedicalStateMedicineModel { MedicalStateId = id, MedicineId = med });
return Json("Added");
}
catch
{
return Json("faild");
}
}
[Authorize(Roles = "patient")]
[HttpPost]
public JsonResult RemoveMedicineJ(int id, int med)
{
((IMedicineService)_service).RemoveFromMedicalState(new MedicalStateMedicineModel { MedicalStateId = id, MedicineId = med });
return Json("Reomved");
}
#endregion json #endregion json
......
...@@ -5,9 +5,9 @@ using WebPresentation.ViewModels; ...@@ -5,9 +5,9 @@ using WebPresentation.ViewModels;
namespace ApplicationCore.Mappere namespace ApplicationCore.Mappere
{ {
public class ObjectMapper : Profile public class ViewModelObjectMapper : Profile
{ {
public ObjectMapper() public ViewModelObjectMapper()
{ {
CreateMap<MedicineViewModel, MedicineModel>() CreateMap<MedicineViewModel, MedicineModel>()
.ForMember(dest => dest.Category, opt => opt.MapFrom(src => src.Category)) .ForMember(dest => dest.Category, opt => opt.MapFrom(src => src.Category))
......
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace WebPresentation.Midlewares
{
public class ExceptionHandler
{
private readonly RequestDelegate _next;
public ExceptionHandler(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext httpContext)
{
try
{
await _next(httpContext);
}
catch (Exception ex)
{
}
}
}
}
...@@ -19,6 +19,7 @@ using ApplicationCore.DomainModel; ...@@ -19,6 +19,7 @@ using ApplicationCore.DomainModel;
using ApplicationCore.Mapper; using ApplicationCore.Mapper;
using System; using System;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using ApplicationCore.Mappere;
namespace WebPresentation namespace WebPresentation
{ {
...@@ -50,7 +51,7 @@ namespace WebPresentation ...@@ -50,7 +51,7 @@ namespace WebPresentation
}); });
services.AddAutoMapper(typeof(ObjectMapper)); services.AddAutoMapper(typeof(ObjectMapper),typeof(ViewModelObjectMapper));
#region ADD Scoped Repository #region ADD Scoped Repository
services.AddScoped(typeof(IUnitOfWork<>),typeof(UnitOfWork<>)); services.AddScoped(typeof(IUnitOfWork<>),typeof(UnitOfWork<>));
...@@ -108,7 +109,16 @@ namespace WebPresentation ...@@ -108,7 +109,16 @@ namespace WebPresentation
options.AccessDeniedPath = "/access/login"; options.AccessDeniedPath = "/access/login";
options.SlidingExpiration = true; options.SlidingExpiration = true;
}); });
services.Configure<IdentityOptions>(options =>
{
// Password settings.
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequiredLength = 6;
options.Password.RequiredUniqueChars = 1;
});
services.AddAuthorization( services.AddAuthorization(
); );
......
...@@ -35,25 +35,26 @@ ...@@ -35,25 +35,26 @@
</div> </div>
<div class="col-10"> <div class="col-10">
<div class="card-body p-4"> <div class="card-body p-4">
<h6>Information</h6> <h6> Information:</h6>
<hr class="mt-0 mb-4"> <hr class="mt-0 mb-4">
<div class="row pt-1"> <div class="row pt-1">
<div class="col-8 mb-3"> <div class="col-6 mb-3">
<h6>Description</h6> <h6>Description</h6>
<p class="text">@Model.StateDescription</p> <p class="text">@Model.StateDescription</p>
</div> </div>
<div class="col-8 mb-3"> <div class="col-4 mb-3">
<h6>Medicines Count:@Model.Medicines.Count()</h6> <h6>Medicines Count:@Model.Medicines.Count()</h6>
<a class="btn btn-primary m-1" asp-controller="MedicalState" asp-action="AddMedicine" asp-route-id="@Model.Id">Add Medicine</a>
<a class="btn btn-primary m-1" asp-controller="MedicalState" asp-action="Edit" asp-route-id="@Model.Id">Edit</a> <a class="btn btn-primary m-1" asp-controller="MedicalState" asp-action="Edit" asp-route-id="@Model.Id">Edit</a>
<a class="btn btn-danger m-1" asp-controller="MedicalState" asp-action="Delete" asp-route-id="@Model.Id">Delete</a> <a class="btn btn-danger m-1" asp-controller="MedicalState" asp-action="Delete" asp-route-id="@Model.Id">Delete</a>
<button class="btn btn-danger" ondblclick='DeleteConfirm("Delete Confirm", "Are you sure you want to delete @Model.StateName From your medical Cases", "Reomve",@Model.Id)'>Delete Confirm</button>
</div> </div>
</div> </div>
<h6>Medicines : </h6> <h6>Medicines : </h6>
<hr class="mt-0 mb-4"> <hr class="mt-0 mb-4">
<div class="row pt-1"> <div class="row pt-1">
<table class="table table-bordered"> <table id="Ingredients_" class="table table-bordered">
<thead> <thead>
<tr> <tr>
<td>#</td> <td>#</td>
...@@ -67,7 +68,7 @@ ...@@ -67,7 +68,7 @@
</tr> </tr>
</thead> </thead>
<tbody id="Ingredients_"> <tbody id="cc">
@foreach (var ing in Model.Medicines) @foreach (var ing in Model.Medicines)
{ {
<tr class=" mb-3"> <tr class=" mb-3">
...@@ -78,7 +79,7 @@ ...@@ -78,7 +79,7 @@
<td>@ing.Dosage</td> <td>@ing.Dosage</td>
<td>@ing.ManufactureName</td> <td>@ing.ManufactureName</td>
<td> <td>
<button class="btn btn-danger" ondblclick="ReomveMedicine(@ing.Id)">Delete</button> <button class="btn btn-danger" ondblclick='DeleteConfirm("Delete Confirm", "Are you sure you want to delete @ing.TradeName From this medical Case" , "ReomveMedicine" ,@ing.Id)'>Delete</button>
<button class="btn btn-primary" onclick="DetailMedicine( @ing.Id)">Details</button> <button class="btn btn-primary" onclick="DetailMedicine( @ing.Id)">Details</button>
</td> </td>
...@@ -90,32 +91,15 @@ ...@@ -90,32 +91,15 @@
<div class="row pt-1"> <div class="row pt-1">
<div class="col-6 mb-3"> <div class="col-6 mb-3">
<h6>Go To list </h6> <h6>Go To list </h6>
<a asp-action="Index">Back to List</a> <a asp-action="Index">GO Back </a>
</div> </div>
</div> </div>
<hr /> <hr />
<div class="row pt-1"> <div class="row pt-1">
<table id="g" class="tabl table-bordered ">
<thead>
<tr class="mb-3">
<td>ID</td>
<td>tradeName</td>
<td>description</td>
<td>price</td>
<td>dosage</td>
<td>Manufacture Name </td>
<td>
Manage
</td>
</tr>
</thead>
<tbody id="medicines-table"></tbody>
</table>
<button onclick="fetchMedicines()" class="btn btn-primary">Get All Medicine </button> <button onclick="fetchMedicines()" class="btn btn-primary">Get All Medicine </button>
</div> </div>
</div> </div>
</div> </div>
...@@ -126,19 +110,54 @@ ...@@ -126,19 +110,54 @@
</div> </div>
</section> </section>
<section class="page-section mb-4 mt-4"> <section style="background-color: #f4f5f7;">
<div class="container h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col">
<div class="row g-0">
<div id="mod"> <div class="row d-flex justify-content-center align-items-center h-100">
<div id="medicines-table">
</div>
</div>
</div>
</div>
</div>
</div> </div>
</section> </section>
@section Scripts { <div class="modal fade" id="item" tabindex="-1" aria-labelledby="label-" role="dialog"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header border-bottom-0">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">
<i class="fas fa-times"></i>
</span>
</button>
</div>
<div class="modal-body text-start p-3">
<h5 class="modal-title text-uppercase mb-5" id="exampleModalLabel">title</h5>
<p class=" mb-5"> message</p>
<hr class="mt-2 mb-4"
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-info" data-dismiss="modal" aria-label="Close">Close</button>
</div>
</div>
</div>
</div>
</div>
@section Scripts {
<script> <script>
async function fetchMedicines() { async function fetchMedicines() {
try { try {
debugger debugger
let response = await fetch('/Medicine/GetMedicines'); // Adjust the endpoint as needed let response = await fetch('/MedicalState/GetMedicines'); // Adjust the endpoint as needed
if (response.ok) { if (response.ok) {
let medicines = await response.json(); let medicines = await response.json();
populateTable(medicines, 'medicines-table'); populateTable(medicines, 'medicines-table');
...@@ -165,12 +184,28 @@ ...@@ -165,12 +184,28 @@
console.error('Fetch error:', error); console.error('Fetch error:', error);
} }
} }
function populateTable(medicines,tableName) { function populateTable(medicines,tableName) {
let tableBody = document.querySelector('#' + tableName); let tableBody = document.querySelector('#' + tableName);
tableBody.innerHTML = ''; // Clear any existing rows tableBody.innerHTML = `
<table class="table">
<thead>
<tr class="mb-3">
<td>ID</td>
<td>tradeName</td>
<td>description</td>
<td>price</td>
<td>dosage</td>
<td>Manufacture Name </td>
<td>
Manage
</td>
</tr>
</thead ><tbody id="b"> </tbody></table>`;
tableBody = document.querySelector('#b');
medicines.forEach(medicine => { medicines.forEach(medicine => {
let row = document.createElement('tr'); let row = document.createElement('tr');
...@@ -206,18 +241,17 @@ ...@@ -206,18 +241,17 @@
tableBody.appendChild(row); tableBody.appendChild(row);
}); });
} }
async function addMedicine(med) { async function addMedicine(med) {
let id =@Model.Id let id =@Model.Id;
try { try {
// showToast('Loading ... ', 'Adding medicine'); showToast('Loading ... ', 'Adding medicine');
let response = await fetch(`/Medicine/AddMedicineT?id=${id}&med=${med}`, { let response = await fetch(`/MedicalState/AddMedicine`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ id: id, med: med }) // Adjust the body as needed body: JSON.stringify({ MedicalStateId: id, MedicineId: med }) // Adjust the body as needed
}); });
if (response.ok) { if (response.ok) {
...@@ -237,7 +271,7 @@ ...@@ -237,7 +271,7 @@
let id =@Model.Id let id =@Model.Id
try { try {
debugger debugger
let response = await fetch(`/Medicine/GetDetails/${med}`, { let response = await fetch(`/MedicalState/GetDetails/${med}`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
...@@ -257,18 +291,18 @@ ...@@ -257,18 +291,18 @@
showToast('Failed to add medicine', 'Error'); showToast('Failed to add medicine', 'Error');
} }
} }
async function ReomveMedicine(med) { async function ReomveMedicine(med) {
let id =@Model.Id let id =@Model.Id
debugger
try { try {
// showToast('Loading ... ', 'Removing medicine'); // showToast('Loading ... ', 'Removing medicine');
let response = await fetch(`/Medicine/RemoveMedicineJ?id=${id}&med=${med}`, { let response = await fetch(`/MedicalState/RemoveMedicine`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ id: id, med: med }) // Adjust the body as needed body: JSON.stringify({ MedicalStateId: id, MedicineId: med }) // Adjust the body as needed
}); });
if (response.ok) { if (response.ok) {
...@@ -286,15 +320,75 @@ ...@@ -286,15 +320,75 @@
showToast('Failed to remove medicine', 'Error'); showToast('Failed to remove medicine', 'Error');
} }
} }
async function DeleteConfirm(id ) { async function Reomve(med) {
debugger
try {
// showToast('Loading ... ', 'Removing medicine');
let response = await fetch(`/MedicalState/Delete/${med}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
});
if (response.ok) {
// let result = await response.json();
document.location.href="/MedicalState/"
showToast('Medicine Reomved successfully', 'Success');
} else {
console.error('Error:', response.statusText);
showToast('Failed to remove medicine', 'Error');
}
} catch (error) {
console.error('Fetch error:', error);
showToast('Failed to remove medicine', 'Error');
}
}
async function DeleteConfirm(title, message, action,param) {
debugger
const modalBody = document.querySelector('#mod');
modalBody.innerHTML = `
<div class="modal fade" id="item" tabindex="-1" aria-labelledby="label-" role="dialog"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header border-bottom-0">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">
<i class="fas fa-times"></i>
</span>
</button>
</div>
<div class="modal-body text-start p-3">
<h5 class="modal-title text-uppercase mb-5" id="exampleModalLabel">${title}</h5>
<p class=" mb-5"> ${message}</p>
<hr class="mt-2 mb-4"
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})">Delete</button>
<button class="btn btn-info" class="close" data-dismiss="modal" aria-label="Close">Close</button>
</div>
</div>
</div>
</div> `;
// Show the modal
const medicineModal = new bootstrap.Modal(document.getElementById('item'));
medicineModal.show();
} }
function showToast(message, title) { function showToast(message, title) {
// const Modal = new bootstrap.Modal(document.getElementById('item')); const Modal = new bootstrap.Modal(document.getElementById('item'));
// Modal.close(); // Modal.close();
// Modal.hide(); if (Modal) Modal.hide();
// Modal.toggle(); // Modal.toggle();
//Modal.dispose(); //Modal.dispose();
const modalBody = document.querySelector('#mod'); const modalBody = document.querySelector('#item');
modalBody.innerHTML = ` modalBody.innerHTML = `
<div class="modal fade" id="item" tabindex="-1" aria-labelledby="label-" role="dialog" <div class="modal fade" id="item" tabindex="-1" aria-labelledby="label-" role="dialog"
aria-hidden="true"> aria-hidden="true">
...@@ -329,6 +423,10 @@ ...@@ -329,6 +423,10 @@
} }
function showModal(message, result) { function showModal(message, result) {
debugger debugger
const Modal = new bootstrap.Modal(document.getElementById('item'));
// Modal.close();
try { Modal.hide(); } catch { }
let m = result["manufactureName"] let m = result["manufactureName"]
console.log(m) console.log(m)
var s = result.medicineIngredients var s = result.medicineIngredients
...@@ -346,7 +444,7 @@ ...@@ -346,7 +444,7 @@
<p class="text-muted mb-0">${s[i].ratio}</p> <p class="text-muted mb-0">${s[i].ratio}</p>
</div> </div>
`} `}
const modalBody = document.querySelector('#mod'); const modalBody = document.querySelector('#item');
modalBody.innerHTML = ` modalBody.innerHTML = `
<div class="modal fade" id="item" tabindex="-1" aria-labelledby="label-" role="dialog" <div class="modal fade" id="item" tabindex="-1" aria-labelledby="label-" role="dialog"
aria-hidden="true"> aria-hidden="true">
...@@ -400,4 +498,4 @@ ...@@ -400,4 +498,4 @@
} }
</script> </script>
} }
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<p class="text-muted">@Model.Description</p> <p class="text-muted">@Model.Description</p>
</div> </div>
<div class="col-6 mb-3"> <div class="col-6 mb-3">
<h6>Medicine Type:@Model.MedicineType?.TypeName</h6> <h6>Type:@Model.MedicineType?.TypeName</h6>
<p class="text-muted">Dosage : @Model.Dosage</p> <p class="text-muted">Dosage : @Model.Dosage</p>
<p class="text-muted">Price : @Model.Price</p> <p class="text-muted">Price : @Model.Price</p>
</div> </div>
...@@ -41,12 +41,13 @@ ...@@ -41,12 +41,13 @@
<h6>Ingredients : </h6> <h6>Ingredients : </h6>
<hr class="mt-0 mb-4"> <hr class="mt-0 mb-4">
<div class="row pt-1"> <div class="row pt-1">
<table class="table table-bordered"> <table id="Ingredients_" class="table table-bordered">
<thead> <thead>
<tr> <tr>
<td>#</td> <td>#</td>
<td>Name</td> <td>Name</td>
<td>Description</td> <td>Description</td>
<td>Manage</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -56,6 +57,10 @@ ...@@ -56,6 +57,10 @@
<td>@(a+=1)</td> <td>@(a+=1)</td>
<td>@ing.Name</td> <td>@ing.Name</td>
<td>@ing.Description</td> <td>@ing.Description</td>
<td>
<button class="btn btn-danger" ondblclick='DeleteConfirm("Delete Confirm", "Are you sure you want to delete @ing.Name From this medicine", "ReomveIngredient",@ing.Id)'>Delete</button>
</td>
</tr> </tr>
} }
</tbody> </tbody>
...@@ -75,8 +80,7 @@ ...@@ -75,8 +80,7 @@
<button class="btn btn-primary" onclick="fetchAll()">Get All Ingredients </button> <button class="btn btn-primary" onclick="fetchAll()">Get All Ingredients </button>
</div> </div>
<div id="t">
</div>
</div> </div>
</div> </div>
...@@ -88,17 +92,23 @@ ...@@ -88,17 +92,23 @@
</div> </div>
</section> </section>
<section class="page-section mb-4 mt-4"> <section class="page-section mb-4 mt-4">
<div class="container h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div id="mod"> <div id="t">
</div>
</div>
</div> </div>
</section> </section>
<div id="mod">
</div>
@section Scripts { @section Scripts {
<script> <script>
async function fetchAll() { async function fetchAll() {
try { try {
debugger debugger
let response = await fetch('/Medicine/GetIngredints'); // Adjust the endpoint as needed let response = await fetch('/Ingredient/GetIngredients'); // Adjust the endpoint as needed
if (response.ok) { if (response.ok) {
let medicines = await response.json(); let medicines = await response.json();
// showModal('',medicines); // showModal('',medicines);
...@@ -112,12 +122,11 @@ ...@@ -112,12 +122,11 @@
console.error('Fetch error:', error); console.error('Fetch error:', error);
} }
} }
async function updateMedicines() { async function updateIngredients() {
let id =@Model.Id let id =@Model.Id;
try { try {
debugger let response = await fetch(`/Ingredient/GetIngredients`); // Adjust the endpoint as needed
let response = await fetch(`/MedicalState/GetMedicalStateMedicine/?id=${id}`); // Adjust the endpoint as needed
if (response.ok) { if (response.ok) {
let medicines = await response.json(); let medicines = await response.json();
populateTable(medicines, 'Ingredients_'); populateTable(medicines, 'Ingredients_');
...@@ -140,6 +149,7 @@ ...@@ -140,6 +149,7 @@
<td>Name</td> <td>Name</td>
<td>Description</td> <td>Description</td>
<td>Manage</td> <td>Manage</td>
</tr> </tr>
</thead ><tbody id="b"> </tbody></table>`; </thead ><tbody id="b"> </tbody></table>`;
...@@ -174,23 +184,57 @@ ...@@ -174,23 +184,57 @@
tableBody.innerHTML += ``; tableBody.innerHTML += ``;
} }
function addIngredient(med) {
const modalBody = document.querySelector('#mod');
modalBody.innerHTML = `
<div class="modal fade" id="item" tabindex="-1" aria-labelledby="label-" role="dialog"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header border-bottom-0">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">
<i class="fas fa-times"></i>
</span>
</button>
</div>
<div class="modal-body text-start p-3">
<h5 class="modal-title text-uppercase mb-5" id="exampleModalLabel">chose the ratio</h5>
async function addIngredient(med) { <p class=" mb-5"> what is the ratio </p>
<input type="number" value=1 id="r">
<hr class="mt-2 mb-4"
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-info" onclick="addIngredientT(${med})">Add</button>
</div>
</div>
</div>
</div> `;
// Show the modal
const medicineModal = new bootstrap.Modal(document.getElementById('item'));
medicineModal.show();
}
async function addIngredientT(med) {
let id =@Model.Id let id =@Model.Id
try { try {
var r; var r = document.getElementById('r').value;
prompt("what is the ratio", r); console.log(r)
let response = await fetch(`/Medicine/AddIngredintsT`, {
let response = await fetch(`/Medicine/AddIngredints`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ ingredientId: ing, medicineId: med ,ratio:r}) // Adjust the body as needed body: JSON.stringify({ IngredientId: med , MedicineId:id ,Ratio:r}) // Adjust the body as needed
}); });
if (response.ok) { if (response.ok) {
let result = await response.json(); let result = await response.json();
updateMedicines(); updateIngredients();
showToast('Medicine added successfully', 'Success'); showToast('Medicine added successfully', 'Success');
} else { } else {
console.error('Error:', response.statusText); console.error('Error:', response.statusText);
...@@ -226,17 +270,17 @@ ...@@ -226,17 +270,17 @@
} }
} }
async function ReomveMedicine(med) { async function ReomveIngredient(med) {
let id =@Model.Id let id =@Model.Id
try { try {
showToast('Loading ... ', 'Removing medicine'); showToast('Loading ... ', 'Removing medicine');
let response = await fetch(`/Medicine/RemoveMedicineJ?id=${id}&med=${med}`, { let response = await fetch(`/Medicine/ReomveIngredient`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ id: id, med: med }) // Adjust the body as needed body: JSON.stringify({ MedicineId: id, IngredientId: med }) // Adjust the body as needed
}); });
if (response.ok) { if (response.ok) {
...@@ -254,9 +298,49 @@ ...@@ -254,9 +298,49 @@
showToast('Failed to remove medicine', 'Error'); showToast('Failed to remove medicine', 'Error');
} }
} }
async function DeleteConfirm(id ) {
async function DeleteConfirm(title, message, action, param) {
debugger
const modalBody = document.querySelector('#mod');
modalBody.innerHTML = `
<div class="modal fade" id="item" tabindex="-1" aria-labelledby="label-" role="dialog"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header border-bottom-0">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">
<i class="fas fa-times"></i>
</span>
</button>
</div>
<div class="modal-body text-start p-3">
<h5 class="modal-title text-uppercase mb-5" id="exampleModalLabel">${title}</h5>
<p class=" mb-5"> ${message}</p>
<hr class="mt-2 mb-4"
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})">Delete</button>
<button class="btn btn-info" class="close" data-dismiss="modal" aria-label="Close">Close</button>
</div>
</div>
</div>
</div> `;
// Show the modal
const medicineModal = new bootstrap.Modal(document.getElementById('item'));
medicineModal.show();
} }
function showToast(message, title) { function showToast(message, title) {
const Modal = new bootstrap.Modal(document.getElementById('item'));
// Modal.close();
try {
Modal.dispose();
} catch { }
const modalBody = document.querySelector('#mod'); const modalBody = document.querySelector('#mod');
modalBody.innerHTML = ` modalBody.innerHTML = `
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Midlewares\Exception Handler\" /> <Folder Include="Filters\" />
<Folder Include="Services Consumers\" /> <Folder Include="Services Consumers\" />
<Folder Include="Views\Patients\" /> <Folder Include="Views\Patients\" />
</ItemGroup> </ItemGroup>
......
#pragma checksum "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "0f715de657dda20a32548f34631b9d9ede67ca8a" #pragma checksum "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "504771db5529b84814966c894e163904dd9e44fe"
// <auto-generated/> // <auto-generated/>
#pragma warning disable 1591 #pragma warning disable 1591
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.Views_Medicine_Details), @"mvc.1.0.view", @"/Views/Medicine/Details.cshtml")] [assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.Views_Medicine_Details), @"mvc.1.0.view", @"/Views/Medicine/Details.cshtml")]
...@@ -46,7 +46,7 @@ using System; ...@@ -46,7 +46,7 @@ using System;
#line default #line default
#line hidden #line hidden
#nullable disable #nullable disable
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"0f715de657dda20a32548f34631b9d9ede67ca8a", @"/Views/Medicine/Details.cshtml")] [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"504771db5529b84814966c894e163904dd9e44fe", @"/Views/Medicine/Details.cshtml")]
[global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"00a5efe30164a0b2b148ed0b3ef352c1f6e80ba1", @"/Views/_ViewImports.cshtml")] [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"00a5efe30164a0b2b148ed0b3ef352c1f6e80ba1", @"/Views/_ViewImports.cshtml")]
public class Views_Medicine_Details : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MedicineModel> public class Views_Medicine_Details : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MedicineModel>
{ {
...@@ -103,7 +103,7 @@ using System; ...@@ -103,7 +103,7 @@ using System;
<div class=""col-md-4 gradient-custom text-center text-black"" <div class=""col-md-4 gradient-custom text-center text-black""
style=""border-top-left-radius: .5rem; border-bottom-left-radius: .5rem;""> style=""border-top-left-radius: .5rem; border-bottom-left-radius: .5rem;"">
"); ");
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("img", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, "0f715de657dda20a32548f34631b9d9ede67ca8a6860", async() => { __tagHelperExecutionContext = __tagHelperScopeManager.Begin("img", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, "504771db5529b84814966c894e163904dd9e44fe6860", async() => {
} }
); );
__Microsoft_AspNetCore_Mvc_Razor_TagHelpers_UrlResolutionTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper>(); __Microsoft_AspNetCore_Mvc_Razor_TagHelpers_UrlResolutionTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper>();
...@@ -145,7 +145,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -145,7 +145,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
#line hidden #line hidden
#nullable disable #nullable disable
WriteLiteral("</p>\r\n "); WriteLiteral("</p>\r\n ");
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("a", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "0f715de657dda20a32548f34631b9d9ede67ca8a9226", async() => { __tagHelperExecutionContext = __tagHelperScopeManager.Begin("a", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "504771db5529b84814966c894e163904dd9e44fe9226", async() => {
WriteLiteral("\r\n <i class=\"far fa-edit mb-5\"></i>\r\n "); WriteLiteral("\r\n <i class=\"far fa-edit mb-5\"></i>\r\n ");
} }
); );
...@@ -193,7 +193,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -193,7 +193,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
#line default #line default
#line hidden #line hidden
#nullable disable #nullable disable
WriteLiteral("</p>\r\n </div>\r\n <div class=\"col-6 mb-3\">\r\n <h6>Medicine Type:"); WriteLiteral("</p>\r\n </div>\r\n <div class=\"col-6 mb-3\">\r\n <h6>Type:");
#nullable restore #nullable restore
#line 36 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 36 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
Write(Model.MedicineType?.TypeName); Write(Model.MedicineType?.TypeName);
...@@ -223,18 +223,19 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -223,18 +223,19 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
<h6>Ingredients : </h6> <h6>Ingredients : </h6>
<hr class=""mt-0 mb-4""> <hr class=""mt-0 mb-4"">
<div class=""row pt-1""> <div class=""row pt-1"">
<table class=""table table-bordered""> <table id=""Ingredients_"" class=""table table-bordered"">
<thead> <thead>
<tr> <tr>
<td>#</td> <td>#</td>
<td>Name</td> <td>Name</td>
<td>Description</td> <td>Description</td>
<td>Manage</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
"); ");
#nullable restore #nullable restore
#line 53 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 54 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
foreach (var ing in Model.Ingredients) foreach (var ing in Model.Ingredients)
{ {
...@@ -243,7 +244,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -243,7 +244,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
#nullable disable #nullable disable
WriteLiteral(" <tr class=\" mb-3\">\r\n <td>"); WriteLiteral(" <tr class=\" mb-3\">\r\n <td>");
#nullable restore #nullable restore
#line 56 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 57 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
Write(a+=1); Write(a+=1);
#line default #line default
...@@ -251,7 +252,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -251,7 +252,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
#nullable disable #nullable disable
WriteLiteral("</td>\r\n <td>"); WriteLiteral("</td>\r\n <td>");
#nullable restore #nullable restore
#line 57 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 58 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
Write(ing.Name); Write(ing.Name);
#line default #line default
...@@ -259,15 +260,46 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -259,15 +260,46 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
#nullable disable #nullable disable
WriteLiteral("</td>\r\n <td>"); WriteLiteral("</td>\r\n <td>");
#nullable restore #nullable restore
#line 58 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 59 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
Write(ing.Description); Write(ing.Description);
#line default #line default
#line hidden #line hidden
#nullable disable #nullable disable
WriteLiteral("</td>\r\n </tr>\r\n"); WriteLiteral("</td>\r\n <td>\r\n <button class=\"btn btn-danger\"");
BeginWriteAttribute("ondblclick", " ondblclick=\'", 3401, "\'", 3537, 16);
WriteAttributeValue("", 3414, "DeleteConfirm(\"Delete", 3414, 21, true);
WriteAttributeValue(" ", 3435, "Confirm\",", 3436, 10, true);
WriteAttributeValue(" ", 3445, "\"Are", 3446, 5, true);
WriteAttributeValue(" ", 3450, "you", 3451, 4, true);
WriteAttributeValue(" ", 3454, "sure", 3455, 5, true);
WriteAttributeValue(" ", 3459, "you", 3460, 4, true);
WriteAttributeValue(" ", 3463, "want", 3464, 5, true);
WriteAttributeValue(" ", 3468, "to", 3469, 3, true);
WriteAttributeValue(" ", 3471, "delete", 3472, 7, true);
#nullable restore
#line 61 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
WriteAttributeValue(" ", 3478, ing.Name, 3479, 9, false);
#line default
#line hidden
#nullable disable
WriteAttributeValue(" ", 3488, "From", 3489, 5, true);
WriteAttributeValue(" ", 3493, "this", 3494, 5, true);
WriteAttributeValue(" ", 3498, "medicine\",", 3499, 11, true);
WriteAttributeValue(" ", 3509, "\"ReomveIngredient\",", 3510, 20, true);
#nullable restore #nullable restore
#line 60 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 61 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
WriteAttributeValue("", 3529, ing.Id, 3529, 7, false);
#line default
#line hidden
#nullable disable
WriteAttributeValue("", 3536, ")", 3536, 1, true);
EndWriteAttribute();
WriteLiteral(">Delete</button>\r\n </td>\r\n\r\n </tr>\r\n");
#nullable restore
#line 65 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
} }
#line default #line default
...@@ -279,7 +311,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -279,7 +311,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
<div class=""row pt-1""> <div class=""row pt-1"">
<div class=""col-6 mb-3""> <div class=""col-6 mb-3"">
"); ");
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("a", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "0f715de657dda20a32548f34631b9d9ede67ca8a16149", async() => { __tagHelperExecutionContext = __tagHelperScopeManager.Begin("a", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "504771db5529b84814966c894e163904dd9e44fe17983", async() => {
WriteLiteral("Back to List"); WriteLiteral("Back to List");
} }
); );
...@@ -295,7 +327,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -295,7 +327,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
Write(__tagHelperExecutionContext.Output); Write(__tagHelperExecutionContext.Output);
__tagHelperExecutionContext = __tagHelperScopeManager.End(); __tagHelperExecutionContext = __tagHelperScopeManager.End();
WriteLiteral("\r\n\r\n </div>\r\n <div class=\"col-6 mb-3\">\r\n "); WriteLiteral("\r\n\r\n </div>\r\n <div class=\"col-6 mb-3\">\r\n ");
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("a", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "0f715de657dda20a32548f34631b9d9ede67ca8a17467", async() => { __tagHelperExecutionContext = __tagHelperScopeManager.Begin("a", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "504771db5529b84814966c894e163904dd9e44fe19301", async() => {
WriteLiteral("Add Ingredients "); WriteLiteral("Add Ingredients ");
} }
); );
...@@ -311,7 +343,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -311,7 +343,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
} }
BeginWriteTagHelperAttribute(); BeginWriteTagHelperAttribute();
#nullable restore #nullable restore
#line 70 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 75 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
WriteLiteral(Model.Id); WriteLiteral(Model.Id);
#line default #line default
...@@ -335,8 +367,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -335,8 +367,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
<button class=""btn btn-primary"" onclick=""fetchAll()"">Get All Ingredients </button> <button class=""btn btn-primary"" onclick=""fetchAll()"">Get All Ingredients </button>
</div> </div>
<div id=""t"">
</div>
</div> </div>
</div> </div>
...@@ -348,11 +379,17 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -348,11 +379,17 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
</div> </div>
</section> </section>
<section class=""page-section mb-4 mt-4""> <section class=""page-section mb-4 mt-4"">
<div class=""container h-100"">
<div class=""row d-flex justify-content-center align-items-center h-100"">
<div id=""mod""> <div id=""t"">
</div>
</div>
</div> </div>
</section> </section>
<div id=""mod"">
</div>
"); ");
DefineSection("Scripts", async() => { DefineSection("Scripts", async() => {
WriteLiteral(@" WriteLiteral(@"
...@@ -360,7 +397,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -360,7 +397,7 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
async function fetchAll() { async function fetchAll() {
try { try {
debugger debugger
let response = await fetch('/Medicine/GetIngredints'); // Adjust the endpoint as needed let response = await fetch('/Ingredient/GetIngredients'); // Adjust the endpoint as needed
if (response.ok) { if (response.ok) {
let medicines = await response.json(); let medicines = await response.json();
// showModal('',medicines); // showModal('',medicines);
...@@ -374,20 +411,19 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -374,20 +411,19 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
console.error('Fetch error:', error); console.error('Fetch error:', error);
} }
} }
async function updateMedicines() { async function updateIngredients() {
let id ="); let id =");
#nullable restore #nullable restore
#line 116 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 126 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
Write(Model.Id); Write(Model.Id);
#line default #line default
#line hidden #line hidden
#nullable disable #nullable disable
WriteLiteral(@" WriteLiteral(@";
try { try {
debugger let response = await fetch(`/Ingredient/GetIngredients`); // Adjust the endpoint as needed
let response = await fetch(`/MedicalState/GetMedicalStateMedicine/?id=${id}`); // Adjust the endpoint as needed
if (response.ok) { if (response.ok) {
let medicines = await response.json(); let medicines = await response.json();
populateTable(medicines, 'Ingredients_'); populateTable(medicines, 'Ingredients_');
...@@ -410,13 +446,14 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -410,13 +446,14 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
<td>Name</td> <td>Name</td>
<td>Description</td> <td>Description</td>
<td>Manage</td> <td>Manage</td>
</tr> </tr>
</thead ><tbody id=""b""> </tbody></table>`; </thead ><tbody id=""b""> </tbody></table>`;
tableB"); tableBody = document.querySelector('#b');
WriteLiteral(@"ody = document.querySelector('#b');
medicines.forEach(medicine => { ");
WriteLiteral(@" medicines.forEach(medicine => {
let row = document.createElement('tr'); let row = document.createElement('tr');
row.classList = ""mb-3"" row.classList = ""mb-3""
...@@ -445,11 +482,46 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -445,11 +482,46 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
tableBody.innerHTML += ``; tableBody.innerHTML += ``;
} }
function addIngredient(med) {
const modalBody = document.querySelector('#mod');
modalBody.i");
WriteLiteral(@"nnerHTML = `
<div class=""modal fade"" id=""item"" tabindex=""-1"" aria-labelledby=""label-"" role=""dialog""
aria-hidden=""true"">
<div class=""modal-dialog"">
<div class=""modal-content"">
<div class=""modal-header border-bottom-0"">
<button type=""button"" class=""close"" data-dismiss=""modal"" aria-label=""Close"">
<span aria-hidden=""true"">
<i class=""fas fa-times""></i>
</span>
</button>
</div>
<div class=""modal-body text-start p-3"">
<h5 class=""modal-title text-uppercase mb-5"" id=""exampleModalLabel"">chose the ratio</h5>
<p class="" mb-5""> what is the ratio </p>
<input type=""number"" value=1 id=""r"">
<hr class=""mt-2 mb-4""
style=""height: 0; back");
WriteLiteral(@"ground-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-info"" onclick=""addIngredientT(${med})"">Add</button>
</div>
</div>
</div>
</div> `;
// Show the modal
const medicineModal = new bootstrap.Modal(document.getElementById('item'));
medicineModal.show();
async function addIngredient(med) {
}
async function addIngredientT(med) {
let id ="); let id =");
#nullable restore #nullable restore
#line 179 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 222 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
Write(Model.Id); Write(Model.Id);
#line default #line default
...@@ -457,19 +529,20 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -457,19 +529,20 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
#nullable disable #nullable disable
WriteLiteral(@" WriteLiteral(@"
try { try {
var r; var r = document.getElementById('r').value;
prompt(""what is the ratio"", r); console.log(r)
let response = await fetch(`/Medicine/AddIngredintsT`, {
let response = await fetch(`/Medicine/AddIngredints`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ ingredientId: ing, medicineId: med ,ratio:r}) // Adjust the body as needed body: JSON.stringify({ IngredientId: med , MedicineId:id ,Ratio:r}) // Adjust the body as needed
}); });
if (response.ok) { if (response.ok) {
let result = await response.json(); let result = await response.json();
updateMedicines(); updateIngredients();
showToast('Medicine added successfully', 'Success'); showToast('Medicine added successfully', 'Success');
} else { } else {
console.error('Error:', response.statusText); console.error('Error:', response.statusText);
...@@ -478,12 +551,10 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -478,12 +551,10 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
} catch (error) { } catch (error) {
console.error('Fetch error:', error); console.error('Fetch error:', error);
showToast('Failed to add medicine', 'Error'); showToast('Failed to add medicine', 'Error');
} ");
} WriteLiteral(" }\r\n }\r\n async function DetailMedicine(med) {\r\n let id =");
");
WriteLiteral(" async function DetailMedicine(med) {\r\n let id =");
#nullable restore #nullable restore
#line 205 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 249 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
Write(Model.Id); Write(Model.Id);
#line default #line default
...@@ -513,10 +584,10 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -513,10 +584,10 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
} }
} }
async function ReomveMedicine(med) { async function ReomveIngredient(med) {
let id ="); let id =");
#nullable restore #nullable restore
#line 230 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml" #line 274 "C:\Users\HASAN\Desktop\Medic\WebPresentation\Views\Medicine\Details.cshtml"
Write(Model.Id); Write(Model.Id);
#line default #line default
...@@ -526,12 +597,12 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -526,12 +597,12 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
try { try {
showToast('Loading ... ', 'Removing medicine'); showToast('Loading ... ', 'Removing medicine');
let response = await fetch(`/Medicine/RemoveMedicineJ?id=${id}&med=${med}`, { let response = await fetch(`/Medicine/ReomveIngredient`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ id: id, med: med }) // Adjust the body as needed body: JSON.stringify({ MedicineId: id, IngredientId: med }) // Adjust the body as needed
}); });
if (response.ok) { if (response.ok) {
...@@ -548,13 +619,55 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -548,13 +619,55 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
console.error('Fetch error:', error); console.error('Fetch error:', error);
showToast('Failed to remove medicine', 'Error'); showToast('Failed to remove medicine', 'Error');
} }
} "); }
");
WriteLiteral(@" WriteLiteral(@"
async function DeleteConfirm(id ) { async function DeleteConfirm(title, message, action, param) {
debugger
const modalBody = document.querySelector('#mod');
modalBody.innerHTML = `
<div class=""modal fade"" id=""item"" tabindex=""-1"" aria-labelledby=""label-"" role=""dialog""
aria-hidden=""true"">
<div class=""modal-dialog"">
<div class=""modal-content"">
<div class=""modal-header border-bottom-0"">
<button type=""button"" class=""close"" data-dismiss=""modal"" aria-label=""Close"">
<span aria-hidden=""true"">
<i class=""fas fa-times""></i>
</span>
</button>
</div>
<div class=""modal-body text-start p-3"">
<h5 class=""modal-title text-uppercase mb-5"" id=""exampleModalLabel"">${title}</h5>
<p class="" mb-5""> ${message}");
WriteLiteral(@"</p>
<hr class=""mt-2 mb-4""
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})"">Delete</button>
<button class=""btn btn-info"" class=""close"" data-dismiss=""modal"" aria-label=""Close"">Close</button>
</div>
</div>
</div>
</div> `;
// Show the modal
const medicineModal = new bootstrap.Modal(document.getElementById('item'));
medicineModal.show();
} }
function showToast(message, title) { function showToast(message, title) {
const Modal = new bootstrap.Modal(document.getElementById('item'));
// Modal.close();
try {
Modal.dispose();
} catch { }
const modalBody = document.querySelector('#mod'); const");
WriteLiteral(@" modalBody = document.querySelector('#mod');
modalBody.innerHTML = ` modalBody.innerHTML = `
<div class=""modal fade"" id=""item"" tabindex=""-1"" aria-labelledby=""label-"" role=""dialog"" <div class=""modal fade"" id=""item"" tabindex=""-1"" aria-labelledby=""label-"" role=""dialog""
aria-hidden=""true""> aria-hidden=""true"">
...@@ -570,11 +683,11 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -570,11 +683,11 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
<div class=""modal-body text-start p-3""> <div class=""modal-body text-start p-3"">
<h5 class=""modal-title text-uppercase mb-5"" id=""exampleModalLabel"">${title}</h5> <h5 class=""modal-title text-uppercase mb-5"" id=""exampleModalLabel"">${title}</h5>
<p class="" mb-5"">"); <p class="" mb-5""> ${message}</p>
WriteLiteral(@" ${message}</p>
<hr class=""mt-2 mb-4"" <hr class=""mt-2 mb-4""
style=""height: 0; background-color: transparent; opacity: .75; border-top: 2px dashed #9e9e9e;""> style=""height: 0; background");
WriteLiteral(@"-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-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>
...@@ -598,9 +711,9 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -598,9 +711,9 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
<tr class="" mb-3""> <tr class="" mb-3"">
<td>${s[i].name}</td> <td>${s[i].name}</td>
"); <td>${s[i].description}</td>
WriteLiteral(@" <td>${s[i].description}</td> ");
<td> WriteLiteral(@" <td>
<button class=""btn btn-info"" onclick=""addIngredient(${s[i].id})"">Add</button> <button class=""btn btn-info"" onclick=""addIngredient(${s[i].id})"">Add</button>
</td> </td>
</tr> </tr>
...@@ -619,10 +732,10 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -619,10 +732,10 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
<i class=""fas fa-times""></i> <i class=""fas fa-times""></i>
</span> </span>
</button> </button>
</di"); </div>
WriteLiteral(@"v>
<div class=""modal-body text-start p-3""> <div class=""modal-body text-start p-3"">
<h5 class=""modal-title text-uppercase mb-5"" id=""exampleModalLabel"">All Ingredients</h5> <h5 class=""modal-title text-upper");
WriteLiteral(@"case mb-5"" id=""exampleModalLabel"">All Ingredients</h5>
<hr class=""mt-2 mb-4"" <hr class=""mt-2 mb-4""
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;"">
...@@ -641,10 +754,10 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false); ...@@ -641,10 +754,10 @@ AddHtmlAttributeValue("", 686, Model.Image, 686, 12, false);
</table> </table>
<hr class=""mt-2 mb-4"" <hr class=""mt-2 mb-4""
"); style=""height: 0; background-color: transparent; opacity: .75; border-top: 2px dashed #9e9e9e;"">
WriteLiteral(@" style=""height: 0; background-color: transparent; opacity: .75; border-top: 2px dashed #9e9e9e;"">
</div> ");
WriteLiteral(@" </div>
<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-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>
......
54259885842f9a679afa2d3e67d7e5f82a2afd4c 706d978fbd9499230d73541f3c16aae883909a4e
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