Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Midterm2.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace Midterm2.Controllers
- {
- public class PatientController : Controller
- {
- Context db = new Context();
- // GET: Patient
- public ActionResult Index()
- {
- return View();
- }
- public ActionResult Login(string Username, string Password)
- {
- if (Username == "ibu" && Password == "admin")
- {
- return RedirectToAction("List");
- }
- else
- return View("Index");
- }
- public ActionResult List()
- {
- List<Patient> p = db.Patients.Include("Doctor").ToList();
- ViewData["patients"] = p;
- return View();
- }
- public ActionResult Create()
- {
- List<Patient> p = db.Patients.Include("Doctor").ToList();
- ViewData["patients"] = p;
- List<Doctor> d = db.Doctors.ToList();
- ViewData["doctors"] = d;
- return View();
- }
- public ActionResult SavePatient(string Firstname, string Lastname, string BirthPlace, DateTime DateOfBirth, int DoctorId)
- {
- //List<Patient> pa = db.Patients.Include("Doctor").ToList();
- //ViewData["patients"] = pa;
- bool Active = true;
- Patient p = new Patient
- {
- Firstname = Firstname,
- Lastname = Lastname,
- BirthPlace = BirthPlace,
- Active = Active,
- DateOfBirth = DateOfBirth,
- DoctorId = DoctorId
- };
- db.Patients.Add(p);
- db.SaveChanges();
- return RedirectToAction("List");
- }
- public ActionResult Delete(int PatientId)
- {
- Patient p = db.Patients.Find(PatientId);
- db.Patients.Remove(p);
- db.SaveChanges();
- return RedirectToAction("List");
- }
- public ActionResult Edit(int PatientId)
- {
- Patient p = db.Patients.Find(PatientId);
- ViewData["patient"] = p;
- List<Doctor> d = db.Doctors.ToList();
- ViewData["doctors"] = d;
- return View();
- }
- public ActionResult UpdatePatient(int PatientId, bool Active, string Firstname, string Lastname, string BirthPlace, DateTime DateOfBirth, int DoctorId)
- {
- Patient p = db.Patients.Find(PatientId);
- if (p != null)
- {
- p.Firstname = Firstname;
- p.Lastname = Lastname;
- p.BirthPlace = BirthPlace;
- p.DateOfBirth = DateOfBirth;
- p.Active = Active;
- p.DoctorId = DoctorId;
- }
- db.SaveChanges();
- return RedirectToAction("List");
- }
- }
- }
- /////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace Midterm2.Models
- {
- public class Doctor
- {
- public int Id { get; set; }
- public string Firstname { get; set; }
- public string Lastname { get; set; }
- }
- }
- //////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Web;
- namespace Midterm2.Models
- {
- public class Patient
- {
- public int Id { get; set; }
- public string Firstname { get; set; }
- public string Lastname { get; set; }
- public DateTime DateOfBirth { get; set; }
- [DefaultValue(true)]
- public bool Active { get; set; }
- public string BirthPlace { get; set; }
- public int DoctorId { get; set; }
- public Doctor Doctor { get; set; }
- public Patient()
- {
- Active = true;
- }
- }
- }
- //////////////////////////////////////////////////////
- using Midterm2.Models;
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Linq;
- using System.Web;
- namespace Midterm2
- {
- public class Context : DbContext
- {
- public Context() : base("Hospital")
- {
- }
- public DbSet<Patient> Patients { get; set; }
- public DbSet<Doctor> Doctors { get; set; }
- }
- }
- ///////////////////////////////////////////////
- @using Midterm2.Models
- @{
- ViewBag.Title = "Create";
- List<Doctor> d = ViewData["doctors"] as List<Doctor>;
- }
- <h2>Add Patient</h2>
- <form action="SavePatient" method="post">
- <table>
- <tr>
- <td>Firstname</td>
- <td><input type="text" name="Firstname" class="form-control" /></td>
- </tr>
- <tr>
- <td>Lastname</td>
- <td><input type="text" name="Lastname" class="form-control" /></td>
- </tr>
- <tr>
- <td>Date of Birth</td>
- <td><input type="date" name="DateOfBirth" class="form-control" /></td>
- </tr>
- <tr>
- <td>Birth place</td>
- <td><input type="text" name="BirthPlace" class="form-control" /></td>
- </tr>
- <tr>
- <td>Doctor</td>
- <td>
- <select name="DoctorId" class="form-control">
- @foreach (var item in d)
- {
- <option value=@item.Id>@item.Firstname @item.Lastname</option>
- }
- </select>
- </td>
- </tr>
- <tr>
- <td><input type="submit" name="Save" class="btn btn-success" /></td>
- </tr>
- </table>
- </form>
- ///////////////////////////////////////////
- @using Midterm2.Models
- @using Midterm2.Controllers
- @model Midterm2.Models.Patient
- @{
- ViewBag.Title = "EditPatient";
- Patient p = ViewData["patient"] as Patient;
- List<Doctor> d = ViewData["doctors"] as List<Doctor>;
- // List<b> active = ViewData["active"] as List<b>;
- bool ValueT = true;
- bool ValueF = false;
- }
- <h2>Edit Patient : @p.Firstname @p.Lastname</h2>
- <form action="UpdatePatient" method="post">
- <input type="hidden" name="PatientId" value="@p.Id" />
- <table>
- <tr>
- <td>Firstname</td>
- <td><input type="text" name="Firstname" class="form-control" /></td>
- </tr>
- <tr>
- <td>Lastname</td>
- <td><input type="text" name="Lastname" class="form-control" /></td>
- </tr>
- <tr>
- <td>Date of Birth</td>
- <td><input type="date" name="DateOfBirth" class="form-control" /></td>
- </tr>
- <tr>
- <td>Birth place</td>
- <td><input type="text" name="BirthPlace" class="form-control" /></td>
- </tr>
- <tr>
- <td>Doctor</td>
- <td>
- <select name="DoctorId" class="form-control">
- @foreach (var item in d)
- {
- <option value=@item.Id>@item.Firstname @item.Lastname</option>
- }
- </select>
- </td>
- </tr>
- <tr>
- <td>Active</td>
- <td>
- <select name="Active" class="form-control">
- <option value = @ValueT>Active</option>
- <option value = @ValueF>Not-Active</option>
- </select>
- </td>
- </tr>
- <tr>
- <td><input type="submit" name="Save Changes" class="btn btn-success" /></td>
- </tr>
- </table>
- </form>
- //////////////////////////////////////////////////////////
- @{
- ViewBag.Title = "Index";
- }
- <div class="container">
- <div class="row">
- <div class="col-md-2 col-md-offset-2">
- <img src="https://cdn4.iconfinder.com/data/icons/general27/png/128/administrator.png" alt="Alternate Text" />
- </div>
- <div class="col-md-3">
- <h4 class="text-center">Welcome to</h4>
- <h1 class="text-left">IBU Hospital</h1>
- <br />
- </div>
- @*<div class="col-md-3">
- <h1>IBU Hospital</h1>
- </div>*@
- </div>
- </div>
- <form action="Login" method="post">
- <table>
- <tr class="text-right">
- <td class="col-md-4">Username</td>
- <td class="col-md-4"><input type="text" name="Username" class="form-control" /></td>
- </tr>
- <tr class="text-right">
- <td class="col-md-4">Password</td>
- <td class="col-md-4"><input type="password" name="Password" class="form-control" /></td>
- </tr>
- <tr>
- <td class="col-md-4"></td>
- <td class="col-md-4 col-md-offset-4">
- <input type="submit" name="Submit" class="btn btn-success" />
- </td>
- </tr>
- </table>
- </form>
- ////////////////////////////////////////////////////////
- @using Midterm2.Models
- @{
- ViewBag.Title = "List";
- List<Patient> p = ViewData["patients"] as List<Patient>;
- }
- <h2>Patient List</h2>
- <br />
- <a href="/Patient/Create" class="btn btn-success" name="New Patient">New Patient </a>
- <br />
- <form>
- <table class="table">
- <thead>
- <tr>
- <td>Firstname</td>
- <td>Lastname</td>
- <td>Active</td>
- <td>Birth Place</td>
- <td>Date of Birth</td>
- <td>Doctor</td>
- <td>Actions</td>
- </tr>
- </thead>
- <tbody>
- @foreach (var item in p)
- {
- <tr>
- <td>@item.Firstname</td>
- <td>@item.Lastname</td>
- <td>@item.Active</td>
- <td>@item.BirthPlace</td>
- <td>@item.DateOfBirth</td>
- <td>@item.Doctor.Firstname @item.Doctor.Lastname</td>
- <td>
- <a href="~/Patient/Edit?PatientId=@item.Id" name="Edit">Edit</a> |
- <a href="~/Patient/Delete?PatientId=@item.Id" name="Delete">Delete</a>
- </td>
- </tr>
- }
- </tbody>
- <tr>
- <td><a href="~/Patient/Index" class="btn btn-success" name="Logout">Logout</a></td>
- </tr>
- </table>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement