-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public async Task<IActionResult> Register(RegisterViewModel model) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; | ||
var result = await _userManager.CreateAsync(user, model.Password); | ||
|
||
if (result.Succeeded) | ||
{ | ||
await _signInManager.SignInAsync(user, isPersistent: false); | ||
return RedirectToAction("Index", "Home"); | ||
} | ||
AddErrors(result); | ||
} | ||
return View(model); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class ApplicationDbContext : IdentityDbContext<ApplicationUser> | ||
{ | ||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) | ||
: base(options) | ||
{ } | ||
} | ||
|
||
public class ApplicationUser : IdentityUser | ||
{ | ||
public string FullName { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
public class AppointmentController : Controller | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public AppointmentController(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
// Schedule Appointment | ||
[HttpPost] | ||
public async Task<IActionResult> ScheduleAppointment(Appointment appointment) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
_context.Appointments.Add(appointment); | ||
await _context.SaveChangesAsync(); | ||
return RedirectToAction("Index"); | ||
} | ||
return View(appointment); | ||
} | ||
|
||
// View Appointments | ||
public IActionResult Index() | ||
{ | ||
var appointments = _context.Appointments.ToList(); | ||
return View(appointments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
public class CaregiverAssignmentController : Controller | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public CaregiverAssignmentController(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
// Assign Caregiver | ||
[HttpPost] | ||
public async Task<IActionResult> AssignCaregiver(int patientId, int caregiverId) | ||
{ | ||
var assignment = new CaregiverAssignment | ||
{ | ||
PatientId = patientId, | ||
CaregiverId = caregiverId, | ||
AssignmentDate = DateTime.Now | ||
}; | ||
|
||
_context.CaregiverAssignments.Add(assignment); | ||
await _context.SaveChangesAsync(); | ||
return RedirectToAction("Index"); | ||
} | ||
|
||
// Track Assignments | ||
public IActionResult Index() | ||
{ | ||
var assignments = _context.CaregiverAssignments.Include(a => a.Patient).Include(a => a.Caregiver).ToList(); | ||
return View(assignments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
public class PatientController : Controller | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public PatientController(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
// Add Patient | ||
[HttpPost] | ||
public async Task<IActionResult> AddPatient(Patient patient) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
_context.Add(patient); | ||
await _context.SaveChangesAsync(); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
return View(patient); | ||
} | ||
|
||
// View Patients | ||
public IActionResult Index() | ||
{ | ||
var patients = _context.Patients.ToList(); | ||
return View(patients); | ||
} | ||
|
||
// Update or Delete Patient | ||
public async Task<IActionResult> Delete(int id) | ||
{ | ||
var patient = await _context.Patients.FindAsync(id); | ||
if (patient != null) | ||
{ | ||
_context.Patients.Remove(patient); | ||
await _context.SaveChangesAsync(); | ||
} | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class Startup | ||
{ | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddDbContext<ApplicationDbContext>(options => | ||
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); | ||
|
||
services.AddIdentity<ApplicationUser, IdentityRole>() | ||
.AddEntityFrameworkStores<ApplicationDbContext>() | ||
.AddDefaultTokenProviders(); | ||
|
||
services.AddControllersWithViews(); | ||
services.AddRazorPages(); | ||
} | ||
} |