Commit 68b48a2c authored by hasan khaddour's avatar hasan khaddour

upd. controller

parent 8de31697
using ApplicationCore.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebPresentation.Controllers
{
[Authorize]
public abstract class BaseController : Controller
{
private readonly UserManager<User> _userManager;
public BaseController(UserManager<User> userManager) {
_userManager = userManager;
}
public User GetCurrentUser() {
User usr = GetCurrentUserAsync().Result;
return usr;
}
private Task<User> GetCurrentUserAsync()
{
return _userManager.GetUserAsync(User);
}
public String GetUserName() {
return GetCurrentUser().UserName;
}
public String GetUserId() {
return GetCurrentUser().Id;
}
}
}
...@@ -17,7 +17,7 @@ namespace WebPresentation.Controllers ...@@ -17,7 +17,7 @@ namespace WebPresentation.Controllers
{ {
[Authorize] [Authorize]
public class HomeController : Controller public class HomeController : BaseController
{ {
private readonly PatientService _patientService; private readonly PatientService _patientService;
private readonly MedicineService _medicineService; private readonly MedicineService _medicineService;
...@@ -25,9 +25,10 @@ namespace WebPresentation.Controllers ...@@ -25,9 +25,10 @@ namespace WebPresentation.Controllers
private readonly User _user; private readonly User _user;
private readonly Patient _patient; private readonly Patient _patient;
public HomeController(UserManager<User> userManager,IUnitOfWork<Patient> patientUnitOfWork, IUnitOfWork<Medicine> medicineUnitOfWork) public HomeController(UserManager<User> userManager,IUnitOfWork<Patient> patientUnitOfWork, IUnitOfWork<Medicine> medicineUnitOfWork):base(userManager)
{ {
_userManager = userManager; _userManager = userManager;
_patientService = new PatientService(patientUnitOfWork,medicineUnitOfWork); _patientService = new PatientService(patientUnitOfWork,medicineUnitOfWork);
// var userid = _userManager.GetUserAsync(User); // var userid = _userManager.GetUserAsync(User);
_medicineService = new MedicineService(medicineUnitOfWork); _medicineService = new MedicineService(medicineUnitOfWork);
...@@ -38,11 +39,11 @@ namespace WebPresentation.Controllers ...@@ -38,11 +39,11 @@ namespace WebPresentation.Controllers
public IActionResult Index() public IActionResult Index()
{ {
var userId = _userManager.GetUserId(User); var u = GetCurrentUser();
// var s = User.Claims.Where(u => u.Type == "UserName"); var userId = GetUserId();
var ownesr = _patientService.getAll(u=>u.User , u => u.Medicines).Where(u => u.User.Id == userId).FirstOrDefault(); var ownesr = _patientService.getAll(u=>u.User , u => u.Medicines).Where(u => u.User.Id == userId).FirstOrDefault();
return View(ownesr); return View(ownesr);
} }
...@@ -55,9 +56,22 @@ namespace WebPresentation.Controllers ...@@ -55,9 +56,22 @@ namespace WebPresentation.Controllers
return View(); return View();
} }
public IActionResult MedicinesGalary(int id) { public IActionResult AddMedicine(int id) {
var userId = _userManager.GetUserId(User);
var patient = _patientService.getAll(u => u.User, u => u.Medicines)
.Where(u => u.User.Id ==userId ).FirstOrDefault();
var m =_medicineService.GetMedicineDetails(id);
_patientService.AddMedicine(patient.Id, m);
return RedirectToAction("Index","Home");
}
public IActionResult MedicinesGalary() {
return View(_medicineService.GetAllMedicines()); return View(_medicineService.GetAllMedicines());
} }
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()
{ {
......
using ApplicationCore.Entities; using ApplicationCore.Entities;
using ApplicationCore.Interfaces; using ApplicationCore.Interfaces;
using ApplicationCore.Services.IngredientService;
using ApplicationCore.Services.MedicineService; using ApplicationCore.Services.MedicineService;
using ApplicationCore.Services.PatientService; using ApplicationCore.Services.PatientService;
using ApplicationCore.ViewModel; using ApplicationCore.ViewModel;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
...@@ -15,14 +17,18 @@ using System.Threading.Tasks; ...@@ -15,14 +17,18 @@ using System.Threading.Tasks;
namespace WebPresentation.Controllers namespace WebPresentation.Controllers
{ {
[Authorize(Roles ="Admin")] [Authorize(Roles ="Admin")]
public class MedicineController : Controller public class MedicineController : BaseController
{ {
private readonly IngredientService _ingredientService;
private readonly MedicineService _medicineService; private readonly MedicineService _medicineService;
private readonly PatientService _patientService; private readonly PatientService _patientService;
public MedicineController(IUnitOfWork<Patient> patientUnitOfWork, IUnitOfWork<Medicine> medicineUnitOfWork) public MedicineController(UserManager<User> userManager,
IUnitOfWork<Patient> patientUnitOfWork,
IUnitOfWork<Medicine> medicineUnitOfWork,
IUnitOfWork<Ingredient>ingredientUnitOfWork):base(userManager)
{ {
_ingredientService =new IngredientService( ingredientUnitOfWork);
_medicineService = new MedicineService( medicineUnitOfWork); _medicineService = new MedicineService( medicineUnitOfWork);
_patientService = new PatientService(patientUnitOfWork,medicineUnitOfWork); _patientService = new PatientService(patientUnitOfWork,medicineUnitOfWork);
...@@ -142,6 +148,20 @@ namespace WebPresentation.Controllers ...@@ -142,6 +148,20 @@ namespace WebPresentation.Controllers
return View(project); return View(project);
} }
public IActionResult AddIngredints(int id ) {
var s = _ingredientService.GetAllIngredients();
ViewBag.MedicineId = id;
return View(s);
}
[HttpPost]
public IActionResult AddIngredints(int id , int med ,int ratio )
{
var s = _ingredientService.GetIngredientDetails(id);
_medicineService.AddIngredient(med, ratio, s);
return RedirectToAction("Details","Medicine", new { Id = med}) ;
}
// POST: Projects/Delete/5 // POST: Projects/Delete/5
[HttpPost, ActionName("Delete")] [HttpPost, ActionName("Delete")]
......
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