Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Karrih2 committed Nov 29, 2024
1 parent 5279476 commit fec64b1
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
16 changes: 16 additions & 0 deletions health/AccountController.cs
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);
}
11 changes: 11 additions & 0 deletions health/ApplicationDbContext.cs
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; }
}
29 changes: 29 additions & 0 deletions health/AppointmentController.cs
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);
}
}
32 changes: 32 additions & 0 deletions health/CaregiverAssignmentController.cs
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);
}
}
41 changes: 41 additions & 0 deletions health/PatientController.cs
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));
}
}
15 changes: 15 additions & 0 deletions health/Startup.cs
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();
}
}

0 comments on commit fec64b1

Please sign in to comment.