Commit 451f93a6 authored by hasan khaddour's avatar hasan khaddour

fix automapper and add api

parent 2dbdf248
...@@ -9,7 +9,7 @@ namespace ApplicationCore.DomainModel ...@@ -9,7 +9,7 @@ namespace ApplicationCore.DomainModel
public class MedicalStateModel : DomainBase public class MedicalStateModel : DomainBase
{ {
public int PatientId { get; set; } public int PatientId { get; set; }
public PatientModel Patient { get; set; } // public PatientModel Patient { get; set; }
public String StateName { get; set; } public String StateName { get; set; }
public String StateDescription { get; set; } public String StateDescription { get; set; }
public DateTime PrescriptionTime { get; set; } public DateTime PrescriptionTime { get; set; }
......
...@@ -29,15 +29,16 @@ namespace ApplicationCore.Mapper ...@@ -29,15 +29,16 @@ namespace ApplicationCore.Mapper
CreateMap<Ingredient, IngredientModel>().ReverseMap(); CreateMap<Ingredient, IngredientModel>().ReverseMap();
CreateMap<MedicalState, MedicalStateModel>() CreateMap<MedicalState, MedicalStateModel>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id)) .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Patient, opt => opt.MapFrom(src => src.Patient)) // .ForMember(dest => dest.Patient, opt => opt.MapFrom(src => src.Patient))
.ForMember(dest => dest.Medicines, opt => opt.MapFrom(src => src.Medicines)); .ForMember(dest => dest.Medicines, opt => opt.MapFrom(src => src.Medicines));
; ;
CreateMap<MedicalStateModel, MedicalState>() CreateMap<MedicalStateModel, MedicalState>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id)) .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Patient, opt => opt.MapFrom(src => src.Patient)) // .ForMember(dest => dest.Patient, opt => opt.MapFrom(src => src.Patient))
.ForMember(dest => dest.Medicines, opt => opt.MapFrom(src => src.Medicines)) .ForMember(dest => dest.Medicines, opt => opt.MapFrom(src => src.Medicines))
.ForMember(s=>s.MedicalStateMedicines , op=>op.Ignore()); .ForMember(s=>s.MedicalStateMedicines , op=>op.Ignore())
.ForMember(s => s.Patient, op => op.Ignore());
CreateMap<Category, CategoryModel>(); CreateMap<Category, CategoryModel>();
CreateMap<CategoryModel, Category>() CreateMap<CategoryModel, Category>()
...@@ -46,7 +47,6 @@ namespace ApplicationCore.Mapper ...@@ -46,7 +47,6 @@ namespace ApplicationCore.Mapper
CreateMap<MedicineType, MedicineTypeModel>().ReverseMap(); CreateMap<MedicineType, MedicineTypeModel>().ReverseMap();
CreateMap<MedicalStateMedicine, MedicalStateMedicineModel>().ReverseMap(); CreateMap<MedicalStateMedicine, MedicalStateMedicineModel>().ReverseMap();
CreateMap<DomainBase, EntityBase>().ReverseMap();
} }
} }
......
using ApplicationCore.Interfaces.IServices;
using ApplicationDomain.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebPresentation.Controllers
{
[Route("api/[controller]")]
[ApiController]
[AllowAnonymous]
public class MedicalStateApiController : BaseController
{
private readonly IPatientService _patientService;
private readonly IMedicalStateService _Service;
public MedicalStateApiController(
IMedicalStateService medicineService,
IPatientService patientService,
UserManager<User> userManager)
:base(userManager)
{
_patientService = patientService;
_Service = medicineService;
}
public async Task<IActionResult> GetAll()
{
string u = GetUserId();
var pId = _patientService.GetAll().Result.Where(p => p.User.Id == u).FirstOrDefault().Id;
var meds = _Service.GetAllPatientMedicalStates(pId);
return Ok(meds);
}
[HttpGet("{id}")]
public async Task<IActionResult> GetById(int id)
{
var medicine = await _Service.GetDetails(id);
if (medicine == null)
{
return NotFound();
}
return Ok(medicine);
}
}
}
...@@ -11,102 +11,16 @@ using ApplicationCore.DomainModel; ...@@ -11,102 +11,16 @@ using ApplicationCore.DomainModel;
namespace WebPresentation.Controllers namespace WebPresentation.Controllers
{ {
[Authorize] [Authorize]
public abstract class BaseController<T> : Controller where T : DomainBase public abstract class BaseController : Controller
{ {
protected readonly UserManager<User> _userManager; protected readonly UserManager<User> _userManager;
protected readonly IService<T> _service; public BaseController(UserManager<User> userManager ) {
public BaseController(UserManager<User> userManager , IService<T> service) {
_userManager = userManager; _userManager = userManager;
_service = service;
} }
// Details
//
public virtual IActionResult Details(int? id ) {
if (id is null)
{
return NotFound();
}
else {
T TModel = _service.GetDetails((int)id).Result;
if (TModel is null)
return NotFound();
return View(TModel);
}
}
public IActionResult Delete(int id)
{
var TModel = _service.GetDetails(id);
if (TModel == null)
{
return NotFound();
}
return View(TModel);
}
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public IActionResult DeleteConfirmed(int id)
{
_service.Delete(id);
return RedirectToAction("Index" );
}
// GET: Projects/Edit/5
public IActionResult Edit(int? id)
{
if (id == null)
{
return NotFound();
}
T tModel = _service.GetDetails((int)id).Result;
if (tModel == null)
{
return NotFound();
}
return View(tModel);
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Edit(int id, T tModel)
{
if (id != tModel.Id)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
tModel= _service.Update(tModel);
}
catch (DbUpdateConcurrencyException)
{
return NotFound() ;
}
return RedirectToAction("Index");
}
return View(tModel);
}
#region Current User Details #region Current User Details
public User GetCurrentUser() { protected User GetCurrentUser() {
User usr = GetCurrentUserAsync().Result; User usr = GetCurrentUserAsync().Result;
return usr; return usr;
} }
...@@ -114,12 +28,12 @@ namespace WebPresentation.Controllers ...@@ -114,12 +28,12 @@ namespace WebPresentation.Controllers
{ {
return _userManager.GetUserAsync(User); return _userManager.GetUserAsync(User);
} }
public String GetUserName() { protected String GetUserName() {
return GetCurrentUser().UserName; return GetCurrentUser().UserName;
} }
public String GetUserId() { protected String GetUserId() {
return GetCurrentUser().Id; return GetCurrentUser().Id;
} }
......
using ApplicationCore.DomainModel;
using ApplicationCore.Interfaces;
using ApplicationDomain.Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebPresentation.Controllers
{
public class CRUDController<T> : BaseController where T : DomainBase
{
protected readonly IService<T> _service;
public CRUDController(UserManager<User> userManager, IService<T> service)
:base(userManager)
{
_service = service;
}
public virtual IActionResult Details(int? id)
{
if (id is null)
{
return View("NotFound");
}
else
{
T TModel = _service.GetDetails((int)id).Result;
if (TModel is null)
return View("NotFound");
return View(TModel);
}
}
public IActionResult Delete(int id)
{
var TModel = _service.GetDetails(id);
if (TModel == null)
{
return View("NotFound");
}
return View(TModel);
}
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public IActionResult DeleteConfirmed(int id)
{
_service.Delete(id);
return RedirectToAction("Index");
}
// GET: Projects/Edit/5
public IActionResult Edit(int? id)
{
if (id == null)
{
return View("NotFound");
}
T tModel = _service.GetDetails((int)id).Result;
if (tModel == null)
{
return View("NotFound");
}
return View(tModel);
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Edit(int id, T tModel)
{
if (id != tModel.Id)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
tModel = _service.Update(tModel);
}
catch (DbUpdateConcurrencyException)
{
return View("Error");
}
return RedirectToAction("Index");
}
return View(tModel);
}
}
}
...@@ -16,15 +16,14 @@ namespace WebPresentation.Controllers ...@@ -16,15 +16,14 @@ namespace WebPresentation.Controllers
{ {
[Authorize(Roles ="patient")] [Authorize(Roles ="patient")]
public class HomeController : BaseController<PatientModel> public class HomeController : BaseController
{ {
private readonly IPatientService _patientService; private readonly IPatientService _patientService;
public HomeController( public HomeController(
UserManager<User> userManager, UserManager<User> userManager,
IPatientService patientService, IPatientService patientService
IMedicineService medicineService ):base(userManager)
):base(userManager,patientService)
{ {
_patientService = patientService; _patientService = patientService;
...@@ -51,7 +50,7 @@ namespace WebPresentation.Controllers ...@@ -51,7 +50,7 @@ namespace WebPresentation.Controllers
} }
public override IActionResult Details(int? id ) { public IActionResult Details(int? id ) {
return View(_getCurrentPatient()); return View(_getCurrentPatient());
......
...@@ -13,7 +13,7 @@ using ApplicationCore.DomainModel; ...@@ -13,7 +13,7 @@ using ApplicationCore.DomainModel;
namespace WebPresentation.Controllers namespace WebPresentation.Controllers
{ {
[Authorize(Roles = "Admin")] [Authorize(Roles = "Admin")]
public class IngredientController : BaseController<IngredientModel> public class IngredientController : CRUDController<IngredientModel>
{ {
private readonly IIngredientService _ingredientService; private readonly IIngredientService _ingredientService;
......
...@@ -14,7 +14,7 @@ namespace WebPresentation.Controllers ...@@ -14,7 +14,7 @@ namespace WebPresentation.Controllers
{ {
[Authorize(Roles = "patient")] [Authorize(Roles = "patient")]
public class MedicalStateController : BaseController<MedicalStateModel> public class MedicalStateController : CRUDController<MedicalStateModel>
{ {
private readonly IMedicalStateService _medicalStateService; private readonly IMedicalStateService _medicalStateService;
private readonly IPatientService _patientService; private readonly IPatientService _patientService;
......
...@@ -14,7 +14,7 @@ using ApplicationCore.DomainModel; ...@@ -14,7 +14,7 @@ using ApplicationCore.DomainModel;
namespace WebPresentation.Controllers namespace WebPresentation.Controllers
{ {
public class MedicineController : BaseController<MedicineModel> public class MedicineController : CRUDController<MedicineModel>
{ {
private readonly IIngredientService _ingredientService; private readonly IIngredientService _ingredientService;
private readonly IMedicineService _medicineService; private readonly IMedicineService _medicineService;
......
...@@ -11,7 +11,7 @@ using WebPresentation.ViewModel.Identity; ...@@ -11,7 +11,7 @@ using WebPresentation.ViewModel.Identity;
namespace WebPresentation.Controllers namespace WebPresentation.Controllers
{ {
public class PatientsController : BaseController<PatientModel> public class PatientsController : CRUDController<PatientModel>
{ {
private readonly IMedicalStateService _medicalStateService; private readonly IMedicalStateService _medicalStateService;
private readonly IPatientService _patientService; private readonly IPatientService _patientService;
......
...@@ -3,7 +3,7 @@ using ApplicationDomain.Entities; ...@@ -3,7 +3,7 @@ using ApplicationDomain.Entities;
using AutoMapper; using AutoMapper;
using WebPresentation.ViewModels; using WebPresentation.ViewModels;
namespace ApplicationCore.Mapper namespace ApplicationCore.Mappere
{ {
public class ObjectMapper : Profile public class ObjectMapper : Profile
{ {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"profiles": { "profiles": {
"IIS Express": { "IIS Express": {
"commandName": "IISExpress", "commandName": "IISExpress",
"launchBrowser": true, "launchBrowser": false,
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }
......
...@@ -16,6 +16,7 @@ using AutoMapper; ...@@ -16,6 +16,7 @@ using AutoMapper;
using ApplicationDomain.Abstraction; using ApplicationDomain.Abstraction;
using ApplicationDomain.Repositories; using ApplicationDomain.Repositories;
using ApplicationCore.DomainModel; using ApplicationCore.DomainModel;
using ApplicationCore.Mapper;
namespace WebPresentation namespace WebPresentation
{ {
...@@ -34,8 +35,17 @@ namespace WebPresentation ...@@ -34,8 +35,17 @@ namespace WebPresentation
services.AddScoped<DbContext, MedicDbContext>(); services.AddScoped<DbContext, MedicDbContext>();
services.AddScoped<Mapper>(); services.AddScoped<Mapper>();
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
services.AddAutoMapper(typeof(ApplicationCore.Mapper.ObjectMapper)); services.AddAutoMapper(typeof(ObjectMapper));
#region ADD Scoped Repository #region ADD Scoped Repository
services.AddScoped(typeof(IUnitOfWork<>),typeof(UnitOfWork<>)); services.AddScoped(typeof(IUnitOfWork<>),typeof(UnitOfWork<>));
services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>)); services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>));
...@@ -99,6 +109,7 @@ namespace WebPresentation ...@@ -99,6 +109,7 @@ namespace WebPresentation
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
} }
app.UseCors("CorsPolicy");
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
...@@ -117,6 +128,8 @@ namespace WebPresentation ...@@ -117,6 +128,8 @@ namespace WebPresentation
endpoints.MapControllerRoute( endpoints.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
}); });
} }
} }
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<input hidden value="@ViewBag.id" name="pId" /> <input hidden value="@ViewBag.id" name="pId" />
<input type="submit" value="Save" class="btn btn-primary" /> <input type="submit" value="Save" class="btn btn-primary" />
</div> </div>
<input hidden value="@Model.PatientId" asp-for="@Model.PatientId" />
</form> </form>
<a asp-action="Index">Back to List</a> <a asp-action="Index">Back to List</a>
......
@{
Layout = "";
}
<style>
import url('https://fonts.googleapis.com/css?family=Montserrat:400,600,700');
import url('https://fonts.googleapis.com/css?family=Catamaran:400,800');
.error-container {
text-align: center;
font-size: 106px;
font-family: 'Catamaran', sans-serif;
font-weight: 800;
margin: 70px 15px;
}
.error-container > span {
display: inline-block;
position: relative;
}
.error-container > span.four {
width: 136px;
height: 43px;
border-radius: 999px;
background:
linear-gradient(140deg, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.07) 43%, transparent 44%, transparent 100%),
linear-gradient(105deg, transparent 0%, transparent 40%, rgba(0, 0, 0, 0.06) 41%, rgba(0, 0, 0, 0.07) 76%, transparent 77%, transparent 100%),
linear-gradient(to right, #d89ca4, #e27b7e);
}
.error-container > span.four:before,
.error-container > span.four:after {
content: '';
display: block;
position: absolute;
border-radius: 999px;
}
.error-container > span.four:before {
width: 43px;
height: 156px;
left: 60px;
bottom: -43px;
background:
linear-gradient(128deg, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.07) 40%, transparent 41%, transparent 100%),
linear-gradient(116deg, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.07) 50%, transparent 51%, transparent 100%),
linear-gradient(to top, #99749D, #B895AB, #CC9AA6, #D7969E, #E0787F);
}
.error-container > span.four:after {
width: 137px;
height: 43px;
transform: rotate(-49.5deg);
left: -18px;
bottom: 36px;
background: linear-gradient(to right, #99749D, #B895AB, #CC9AA6, #D7969E, #E0787F);
}
.error-container > span.zero {
vertical-align: text-top;
width: 156px;
height: 156px;
border-radius: 999px;
background: linear-gradient(-45deg, transparent 0%, rgba(0, 0, 0, 0.06) 50%, transparent 51%, transparent 100%),
linear-gradient(to top right, #99749D, #99749D, #B895AB, #CC9AA6, #D7969E, #ED8687, #ED8687);
overflow: hidden;
animation: bgshadow 5s infinite;
}
.error-container > span.zero:before {
content: '';
display: block;
position: absolute;
transform: rotate(45deg);
width: 90px;
height: 90px;
background-color: transparent;
left: 0px;
bottom: 0px;
background:
linear-gradient(95deg, transparent 0%, transparent 8%, rgba(0, 0, 0, 0.07) 9%, transparent 50%, transparent 100%),
linear-gradient(85deg, transparent 0%, transparent 19%, rgba(0, 0, 0, 0.05) 20%, rgba(0, 0, 0, 0.07) 91%, transparent 92%, transparent 100%);
}
.error-container > span.zero:after {
content: '';
display: block;
position: absolute;
border-radius: 999px;
width: 70px;
height: 70px;
left: 43px;
bottom: 43px;
background: #FDFAF5;
box-shadow: -2px 2px 2px 0px rgba(0, 0, 0, 0.1);
}
.screen-reader-text {
position: absolute;
top: -9999em;
left: -9999em;
}
keyframes bgshadow {
0% {
box-shadow: inset -160px 160px 0px 5px rgba(0, 0, 0, 0.4);
}
45% {
box-shadow: inset 0px 0px 0px 0px rgba(0, 0, 0, 0.1);
}
55% {
box-shadow: inset 0px 0px 0px 0px rgba(0, 0, 0, 0.1);
}
100% {
box-shadow: inset 160px -160px 0px 5px rgba(0, 0, 0, 0.4);
}
}
/* demo stuff */
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
background-color: #FDFAF5;
margin-bottom: 50px;
}
html, button, input, select, textarea {
font-family: 'Montserrat', Helvetica, sans-serif;
color: #bbb;
}
h1 {
text-align: center;
margin: 30px 15px;
}
.zoom-area {
max-width: 490px;
margin: 30px auto 30px;
font-size: 19px;
text-align: center;
}
.link-container {
text-align: center;
}
a.more-link {
text-transform: uppercase;
font-size: 13px;
background-color: #de7e85;
padding: 10px 15px;
border-radius: 0;
color: #fff;
display: inline-block;
margin-right: 5px;
margin-bottom: 5px;
line-height: 1.5;
text-decoration: none;
margin-top: 50px;
letter-spacing: 1px;
}
</style>
<section class="page-section">
<h1>404 Error Page #2</h1>
<p class="zoom-area"><b>CSS</b> animations to make a cool 404 page. </p>
<section class="error-container">
<span class="four"><span class="screen-reader-text">4</span></span>
<span class="zero"><span class="screen-reader-text">0</span></span>
<span class="four"><span class="screen-reader-text">4</span></span>
</section>
<div class="link-container">
<a target="_blank" href="https://www.silocreativo.com/en/creative-examples-404-error-css/" class="more-link">Visit the original article</a>
</div>
</section>
\ No newline at end of file
2235de95d31ff21c4c102fa011906991886ed4c9 3469560838cd75d70e568e4424234b353b628d37
0f87441b6f32c7123a80c471b0eaca934bec84ff 6d6d7ad7e9f211e7963b9ffcc1db8a09754cbf0c
...@@ -180,3 +180,4 @@ C:\Users\HASAN\Desktop\Medic\WebPresentation\bin\Debug\net5.0\AutoMapper.dll ...@@ -180,3 +180,4 @@ C:\Users\HASAN\Desktop\Medic\WebPresentation\bin\Debug\net5.0\AutoMapper.dll
C:\Users\HASAN\Desktop\Medic\WebPresentation\bin\Debug\net5.0\AutoMapper.Extensions.Microsoft.DependencyInjection.dll C:\Users\HASAN\Desktop\Medic\WebPresentation\bin\Debug\net5.0\AutoMapper.Extensions.Microsoft.DependencyInjection.dll
C:\Users\HASAN\Desktop\Medic\WebPresentation\obj\Debug\net5.0\Razor\Views\Home\Edit.cshtml.g.cs C:\Users\HASAN\Desktop\Medic\WebPresentation\obj\Debug\net5.0\Razor\Views\Home\Edit.cshtml.g.cs
C:\Users\HASAN\Desktop\Medic\WebPresentation\obj\Debug\net5.0\Razor\Views\Home\Details.cshtml.g.cs C:\Users\HASAN\Desktop\Medic\WebPresentation\obj\Debug\net5.0\Razor\Views\Home\Details.cshtml.g.cs
C:\Users\HASAN\Desktop\Medic\WebPresentation\obj\Debug\net5.0\Razor\Views\Shared\NotFound.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