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(
); );
......
...@@ -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>
......
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