Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace HolidayTracker.Controllers
- // GET: HolidayRequestForms
- public ActionResult Index()
- {
- var holidayRequestForms = db.HolidayRequestForms.Include(h => h.Employee);
- return View(holidayRequestForms.ToList());
- }
- // GET: HolidayRequestForms/Details/5
- public ActionResult Details(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- HolidayRequestForm holidayRequestForm = db.HolidayRequestForms.Find(id);
- if (holidayRequestForm == null)
- {
- return HttpNotFound();
- }
- return View(holidayRequestForm);
- }
- // GET: HolidayRequestForms/Create
- public ActionResult Create()
- {
- ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "FullName");
- return View();
- }
- // POST: HolidayRequestForms/Create
- // To protect from overposting attacks, please enable the specific properties you want to bind to, for
- // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Create([Bind(Include = "RequestID,EmployeeID,StartDate,FinishDate,HoursTaken,Comments,YearCreated,MonthCreated,DayCreated,YearOfHoliday,Approved")] HolidayRequestForm holidayRequestForm)
- {
- if (ModelState.IsValid)
- {
- db.HolidayRequestForms.Add(holidayRequestForm);
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "FullName", holidayRequestForm.EmployeeID);
- return View(holidayRequestForm);
- }
- // GET: HolidayRequestForms/Edit/5
- public ActionResult Edit(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- HolidayRequestForm holidayRequestForm = db.HolidayRequestForms.Find(id);
- if (holidayRequestForm == null)
- {
- return HttpNotFound();
- }
- ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "FullName", holidayRequestForm.EmployeeID);
- return View(holidayRequestForm);
- }
- // POST: HolidayRequestForms/Edit/5
- // To protect from overposting attacks, please enable the specific properties you want to bind to, for
- // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit([Bind(Include = "RequestID,EmployeeID,StartDate,FinishDate,HoursTaken,Comments,YearCreated,MonthCreated,DayCreated,YearOfHoliday,Approved")] HolidayRequestForm holidayRequestForm)
- {
- if (ModelState.IsValid)
- {
- db.Entry(holidayRequestForm).State = EntityState.Modified;
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "FullName", holidayRequestForm.EmployeeID);
- return View(holidayRequestForm);
- }
- // GET: HolidayRequestForms/Delete/5
- public ActionResult Delete(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- HolidayRequestForm holidayRequestForm = db.HolidayRequestForms.Find(id);
- if (holidayRequestForm == null)
- {
- return HttpNotFound();
- }
- return View(holidayRequestForm);
- }
- // POST: HolidayRequestForms/Delete/5
- [HttpPost, ActionName("Delete")]
- [ValidateAntiForgeryToken]
- public ActionResult DeleteConfirmed(int id)
- {
- HolidayRequestForm holidayRequestForm = db.HolidayRequestForms.Find(id);
- db.HolidayRequestForms.Remove(holidayRequestForm);
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- public static MvcHtmlString DisplayWithBreaksFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
- {
- var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
- var model = html.Encode(metadata.Model).Replace("rn", "<br />rn");
- if (String.IsNullOrEmpty(model))
- return MvcHtmlString.Empty;
- return MvcHtmlString.Create(model);
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- }
Add Comment
Please, Sign In to add comment