Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.Entity;
- using System.Linq;
- using System.Net;
- using System.Web;
- using System.Web.Mvc;
- using HospitalASP;
- namespace HospitalASP.Controllers
- {
- public class DoctorsController : Controller
- {
- private HospitalDBEntities db = new HospitalDBEntities();
- // GET: Doctors
- public ActionResult Index()
- {
- var doctors = db.Doctors.Include(d => d.Specification);
- return View(doctors.ToList());
- }
- // GET: Doctors/Details/5
- public ActionResult Details(Guid? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Doctor doctor = db.Doctors.Find(id);
- if (doctor == null)
- {
- return HttpNotFound();
- }
- return View(doctor);
- }
- // GET: Doctors/Create
- public ActionResult Create()
- {
- ViewBag.SpecID = new SelectList(db.Specifications, "SpecID", "SpecName");
- return View();
- }
- // POST: Doctors/Create
- // Чтобы защититься от атак чрезмерной передачи данных, включите определенные свойства, для которых следует установить привязку. Дополнительные
- // сведения см. в статье http://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Create([Bind(Include = "DoctorID,SpecID,DoctorFullName,Age,Experience,BirthDate,Cost")] Doctor doctor)
- {
- if (ModelState.IsValid)
- {
- doctor.DoctorID = Guid.NewGuid();
- db.Doctors.Add(doctor);
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- ViewBag.SpecID = new SelectList(db.Specifications, "SpecID", "SpecName", doctor.SpecID);
- return View(doctor);
- }
- // GET: Doctors/Edit/5
- public ActionResult Edit(Guid? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Doctor doctor = db.Doctors.Find(id);
- if (doctor == null)
- {
- return HttpNotFound();
- }
- ViewBag.SpecID = new SelectList(db.Specifications, "SpecID", "SpecName", doctor.SpecID);
- return View(doctor);
- }
- // POST: Doctors/Edit/5
- // Чтобы защититься от атак чрезмерной передачи данных, включите определенные свойства, для которых следует установить привязку. Дополнительные
- // сведения см. в статье http://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit([Bind(Include = "DoctorID,SpecID,DoctorFullName,Age,Experience,BirthDate,Cost")] Doctor doctor)
- {
- if (ModelState.IsValid)
- {
- db.Entry(doctor).State = EntityState.Modified;
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- ViewBag.SpecID = new SelectList(db.Specifications, "SpecID", "SpecName", doctor.SpecID);
- return View(doctor);
- }
- // GET: Doctors/Delete/5
- public ActionResult Delete(Guid? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Doctor doctor = db.Doctors.Find(id);
- if (doctor == null)
- {
- return HttpNotFound();
- }
- return View(doctor);
- }
- // POST: Doctors/Delete/5
- [HttpPost, ActionName("Delete")]
- [ValidateAntiForgeryToken]
- public ActionResult DeleteConfirmed(Guid id)
- {
- Doctor doctor = db.Doctors.Find(id);
- db.Doctors.Remove(doctor);
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement