Commit cbdb40d0 authored by hasan khaddour's avatar hasan khaddour

fix s

parent f329fd46
using ApplicationCore.DomainModel;
using ApplicationCore.Interfaces;
using ApplicationDomain.Entities;
using Microsoft.AspNetCore.Authorization;
using AutoMapper;
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
......@@ -15,7 +12,10 @@ namespace WebPresentation.Controllers
public class CRUDController<T> : BaseController where T : DomainBase
{
protected readonly IService<T> _service;
public CRUDController(UserManager<User> userManager, IService<T> service)
public CRUDController(
UserManager<User> userManager,
IService<T> service
)
:base(userManager)
{
......@@ -60,7 +60,7 @@ namespace WebPresentation.Controllers
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
// [ValidateAntiForgeryToken]
public IActionResult DeleteConfirmed(int id)
{
_service.Delete(id);
......
using ApplicationDomain.Entities;
using ApplicationCore.Interfaces.IServices;
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 ApplicationCore.DomainModel;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
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
}
//[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]
public IActionResult AddMedicine(int id)
{
var all = _medicineService.GetAll();
ViewBag.MedicalStateId = id;
return View(all);
public JsonResult GetMedicalStateMedicine(int id) {
var r = _medicalStateService.GetDetails(id).Result.Medicines;
return Json(r);
}
[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]
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]
public JsonResult GetMedicalStateMedicine(int id) {
var r = _medicalStateService.GetDetails(id).Result.Medicines;
return Json(r);
public JsonResult GetMedicines()
{
var all = _medicineService.GetAll().Result;
return new JsonResult(all);
}
#endregion json
}
}
......@@ -4,13 +4,8 @@ using ApplicationCore.Interfaces.IServices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
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 System.Threading.Tasks;
namespace WebPresentation.Controllers
{
......@@ -35,104 +30,44 @@ namespace WebPresentation.Controllers
}
[Authorize(Roles = "Admin")]
public IActionResult AddIngredints(int id ) {
var s = _ingredientService.GetAll().Result;
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 )
[HttpPost]
public IActionResult ReomveIngredient([FromBody] MedicineIngredientModel medicineIngredientModel)
{
_ingredientService.RemoveFromMedicine(new MedicineIngredientModel {IngredientId=ing , MedicineId=id });
_ingredientService.RemoveFromMedicine(medicineIngredientModel);
return Ok(new {message = "removed" });
}
[Authorize(Roles = "Admin")]
[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"});
}
[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
[Authorize(Roles ="patient")]
public async Task<JsonResult> GetDetails(int? id)
{
if (id is null)
{
return Json("");
}
else
{
MedicineModel TModel = await _service.GetDetails((int)id);
if (TModel is null)
return Json("");
return Json(TModel);
}
}
[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");
}
//[Authorize(Roles = "Admin")]
//public IActionResult AddIngredints(int id)
//{
// var s = _ingredientService.GetAll().Result;
// ViewBag.MedicineId = id;
// return View(s);
//}
//[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 });
//}
#endregion json
......
......@@ -5,9 +5,9 @@ using WebPresentation.ViewModels;
namespace ApplicationCore.Mappere
{
public class ObjectMapper : Profile
public class ViewModelObjectMapper : Profile
{
public ObjectMapper()
public ViewModelObjectMapper()
{
CreateMap<MedicineViewModel, MedicineModel>()
.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;
using ApplicationCore.Mapper;
using System;
using Microsoft.AspNetCore.Http;
using ApplicationCore.Mappere;
namespace WebPresentation
{
......@@ -50,7 +51,7 @@ namespace WebPresentation
});
services.AddAutoMapper(typeof(ObjectMapper));
services.AddAutoMapper(typeof(ObjectMapper),typeof(ViewModelObjectMapper));
#region ADD Scoped Repository
services.AddScoped(typeof(IUnitOfWork<>),typeof(UnitOfWork<>));
......@@ -108,7 +109,16 @@ namespace WebPresentation
options.AccessDeniedPath = "/access/login";
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(
);
......
......@@ -27,7 +27,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Midlewares\Exception Handler\" />
<Folder Include="Filters\" />
<Folder Include="Services Consumers\" />
<Folder Include="Views\Patients\" />
</ItemGroup>
......
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