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 ContactManagement.Models;
- namespace ContactManagement.Controllers
- {
- public class Contacts : Controller
- {
- private RifatContactEntities db = new RifatContactEntities();
- // GET: Contacts
- public ActionResult Index()
- {
- return View(db.Contacts.ToList());
- }
- // GET: Contacts/Details/5
- public ActionResult Details(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Contact contact = db.Contacts.Find(id);
- if (contact == null)
- {
- return HttpNotFound();
- }
- return View(contact);
- }
- // GET: Contacts/Create
- public ActionResult Create()
- {
- return View();
- }
- // POST: Contacts/Create
- // To protect from overposting attacks, enable the specific properties you want to bind to, for
- // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Create([Bind(Include = "ID,First_Name,Last_Name,Phone_Number,Email,Category")] Contact contact)
- {
- if (ModelState.IsValid)
- {
- db.Contacts.Add(contact);
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- return View(contact);
- }
- // GET: Contacts/Edit/5
- public ActionResult Edit(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Contact contact = db.Contacts.Find(id);
- if (contact == null)
- {
- return HttpNotFound();
- }
- return View(contact);
- }
- // POST: Contacts/Edit/5
- // To protect from overposting attacks, enable the specific properties you want to bind to, for
- // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit([Bind(Include = "ID,First_Name,Last_Name,Phone_Number,Email,Category")] Contact contact)
- {
- if (ModelState.IsValid)
- {
- db.Entry(contact).State = EntityState.Modified;
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- return View(contact);
- }
- // GET: Contacts/Delete/5
- public ActionResult Delete(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Contact contact = db.Contacts.Find(id);
- if (contact == null)
- {
- return HttpNotFound();
- }
- return View(contact);
- }
- // POST: Contacts/Delete/5
- [HttpPost, ActionName("Delete")]
- [ValidateAntiForgeryToken]
- public ActionResult DeleteConfirmed(int id)
- {
- Contact contact = db.Contacts.Find(id);
- db.Contacts.Remove(contact);
- 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