Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
Medic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hasan.bahjat
Medic
Commits
68b48a2c
Commit
68b48a2c
authored
May 27, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upd. controller
parent
8de31697
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
9 deletions
+81
-9
BaseController.cs
WebPresentation/Controllers/BaseController.cs
+38
-0
HomeController.cs
WebPresentation/Controllers/HomeController.cs
+20
-6
MedicineController.cs
WebPresentation/Controllers/MedicineController.cs
+23
-3
No files found.
WebPresentation/Controllers/BaseController.cs
0 → 100644
View file @
68b48a2c
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
;
}
}
}
WebPresentation/Controllers/HomeController.cs
View file @
68b48a2c
...
@@ -17,7 +17,7 @@ namespace WebPresentation.Controllers
...
@@ -17,7 +17,7 @@ namespace WebPresentation.Controllers
{
{
[
Authorize
]
[
Authorize
]
public
class
HomeController
:
Controller
public
class
HomeController
:
Base
Controller
{
{
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,10 +39,10 @@ namespace WebPresentation.Controllers
...
@@ -38,10 +39,10 @@ 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
()
{
{
...
...
WebPresentation/Controllers/MedicineController.cs
View file @
68b48a2c
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
:
Base
Controller
{
{
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"
)]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment