Advertisement
Guest User

Untitled

a guest
Dec 25th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 3.71 KB | None | 0 0
  1. using System;
  2.  using System.Collections.Generic;
  3.  using System.Data;
  4.  using System.Data.Entity;
  5.  using System.Linq;
  6.  using System.Net;
  7.  using System.Web;
  8.  using System.Web.Mvc;
  9.  using HospitalASP;
  10.  
  11.  namespace HospitalASP.Controllers
  12.  {
  13.  public class DoctorsController : Controller
  14.  {
  15.  private HospitalDBEntities db = new HospitalDBEntities();
  16.  
  17.  // GET: Doctors
  18.  public ActionResult Index()
  19.  {
  20.  var doctors = db.Doctors.Include(d => d.Specification);
  21.  return View(doctors.ToList());
  22.  }
  23.  
  24.  // GET: Doctors/Details/5
  25.  public ActionResult Details(Guid? id)
  26.  {
  27.  if (id == null)
  28.  {
  29.  return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  30.  }
  31.  Doctor doctor = db.Doctors.Find(id);
  32.  if (doctor == null)
  33.  {
  34.  return HttpNotFound();
  35.  }
  36.  return View(doctor);
  37.  }
  38.  
  39.  // GET: Doctors/Create
  40.  public ActionResult Create()
  41.  {
  42.  ViewBag.SpecID = new SelectList(db.Specifications, "SpecID", "SpecName");
  43.  return View();
  44.  }
  45.  
  46.  // POST: Doctors/Create
  47.  // Чтобы защититься от атак чрезмерной передачи данных, включите определенные свойства, для которых следует установить привязку. Дополнительные  
  48.  // сведения см. в статье http://go.microsoft.com/fwlink/?LinkId=317598.
  49.  [HttpPost]
  50.  [ValidateAntiForgeryToken]
  51.  public ActionResult Create([Bind(Include = "DoctorID,SpecID,DoctorFullName,Age,Experience,BirthDate,Cost")] Doctor doctor)
  52.  {
  53.  if (ModelState.IsValid)
  54.  {
  55.  doctor.DoctorID = Guid.NewGuid();
  56.  db.Doctors.Add(doctor);
  57.  db.SaveChanges();
  58.  return RedirectToAction("Index");
  59.  }
  60.  
  61.  ViewBag.SpecID = new SelectList(db.Specifications, "SpecID", "SpecName", doctor.SpecID);
  62.  return View(doctor);
  63.  }
  64.  
  65.  // GET: Doctors/Edit/5
  66.  public ActionResult Edit(Guid? id)
  67.  {
  68.  if (id == null)
  69.  {
  70.  return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  71.  }
  72.  Doctor doctor = db.Doctors.Find(id);
  73.  if (doctor == null)
  74.  {
  75.  return HttpNotFound();
  76.  }
  77.  ViewBag.SpecID = new SelectList(db.Specifications, "SpecID", "SpecName", doctor.SpecID);
  78.  return View(doctor);
  79.  }
  80.  
  81.  // POST: Doctors/Edit/5
  82.  // Чтобы защититься от атак чрезмерной передачи данных, включите определенные свойства, для которых следует установить привязку. Дополнительные  
  83.  // сведения см. в статье http://go.microsoft.com/fwlink/?LinkId=317598.
  84.  [HttpPost]
  85.  [ValidateAntiForgeryToken]
  86.  public ActionResult Edit([Bind(Include = "DoctorID,SpecID,DoctorFullName,Age,Experience,BirthDate,Cost")] Doctor doctor)
  87.  {
  88.  if (ModelState.IsValid)
  89.  {
  90.  db.Entry(doctor).State = EntityState.Modified;
  91.  db.SaveChanges();
  92.  return RedirectToAction("Index");
  93.  }
  94.  ViewBag.SpecID = new SelectList(db.Specifications, "SpecID", "SpecName", doctor.SpecID);
  95.  return View(doctor);
  96.  }
  97.  
  98.  // GET: Doctors/Delete/5
  99.  public ActionResult Delete(Guid? id)
  100.  {
  101.  if (id == null)
  102.  {
  103.  return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  104.  }
  105.  Doctor doctor = db.Doctors.Find(id);
  106.  if (doctor == null)
  107.  {
  108.  return HttpNotFound();
  109.  }
  110.  return View(doctor);
  111.  }
  112.  
  113.  // POST: Doctors/Delete/5
  114.  [HttpPost, ActionName("Delete")]
  115.  [ValidateAntiForgeryToken]
  116.  public ActionResult DeleteConfirmed(Guid id)
  117.  {
  118.  Doctor doctor = db.Doctors.Find(id);
  119.  db.Doctors.Remove(doctor);
  120.  db.SaveChanges();
  121.  return RedirectToAction("Index");
  122.  }
  123.  
  124.  protected override void Dispose(bool disposing)
  125.  {
  126.  if (disposing)
  127.  {
  128.  db.Dispose();
  129.  }
  130.  base.Dispose(disposing);
  131.  }
  132.  }
  133.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement