From fec64b1fe0114e57c2264228502c0c071acd2a39 Mon Sep 17 00:00:00 2001 From: "Harish Karri (karrih2)" Date: Fri, 29 Nov 2024 16:01:58 +0000 Subject: [PATCH] Add files via upload --- health/AccountController.cs | 16 ++++++++++ health/ApplicationDbContext.cs | 11 +++++++ health/AppointmentController.cs | 29 +++++++++++++++++ health/CaregiverAssignmentController.cs | 32 +++++++++++++++++++ health/PatientController.cs | 41 +++++++++++++++++++++++++ health/Startup.cs | 15 +++++++++ 6 files changed, 144 insertions(+) create mode 100644 health/AccountController.cs create mode 100644 health/ApplicationDbContext.cs create mode 100644 health/AppointmentController.cs create mode 100644 health/CaregiverAssignmentController.cs create mode 100644 health/PatientController.cs create mode 100644 health/Startup.cs diff --git a/health/AccountController.cs b/health/AccountController.cs new file mode 100644 index 0000000..f893378 --- /dev/null +++ b/health/AccountController.cs @@ -0,0 +1,16 @@ +public async Task 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); +} diff --git a/health/ApplicationDbContext.cs b/health/ApplicationDbContext.cs new file mode 100644 index 0000000..777952d --- /dev/null +++ b/health/ApplicationDbContext.cs @@ -0,0 +1,11 @@ +public class ApplicationDbContext : IdentityDbContext +{ + public ApplicationDbContext(DbContextOptions options) + : base(options) + { } +} + +public class ApplicationUser : IdentityUser +{ + public string FullName { get; set; } +} diff --git a/health/AppointmentController.cs b/health/AppointmentController.cs new file mode 100644 index 0000000..6b011e0 --- /dev/null +++ b/health/AppointmentController.cs @@ -0,0 +1,29 @@ +public class AppointmentController : Controller +{ + private readonly ApplicationDbContext _context; + + public AppointmentController(ApplicationDbContext context) + { + _context = context; + } + + // Schedule Appointment + [HttpPost] + public async Task 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); + } +} diff --git a/health/CaregiverAssignmentController.cs b/health/CaregiverAssignmentController.cs new file mode 100644 index 0000000..d9214d4 --- /dev/null +++ b/health/CaregiverAssignmentController.cs @@ -0,0 +1,32 @@ +public class CaregiverAssignmentController : Controller +{ + private readonly ApplicationDbContext _context; + + public CaregiverAssignmentController(ApplicationDbContext context) + { + _context = context; + } + + // Assign Caregiver + [HttpPost] + public async Task 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); + } +} diff --git a/health/PatientController.cs b/health/PatientController.cs new file mode 100644 index 0000000..75fe2c4 --- /dev/null +++ b/health/PatientController.cs @@ -0,0 +1,41 @@ +public class PatientController : Controller +{ + private readonly ApplicationDbContext _context; + + public PatientController(ApplicationDbContext context) + { + _context = context; + } + + // Add Patient + [HttpPost] + public async Task 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 Delete(int id) + { + var patient = await _context.Patients.FindAsync(id); + if (patient != null) + { + _context.Patients.Remove(patient); + await _context.SaveChangesAsync(); + } + return RedirectToAction(nameof(Index)); + } +} diff --git a/health/Startup.cs b/health/Startup.cs new file mode 100644 index 0000000..e4ba177 --- /dev/null +++ b/health/Startup.cs @@ -0,0 +1,15 @@ +public class Startup +{ + public void ConfigureServices(IServiceCollection services) + { + services.AddDbContext(options => + options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); + + services.AddIdentity() + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); + + services.AddControllersWithViews(); + services.AddRazorPages(); + } +}