using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MvcApplication1.Models; namespace MvcApplication1.Controllers { public class CustomerController : BaseController { private PagingModel GetCustomers(string term) { var list = CustomerModel.GetAll(); if (!string.IsNullOrEmpty(term)) list = list.Where(c => c.LastName.Contains(term) || c.Name.Contains(term)).ToList(); var paging = new PagingModel(); paging.ResultList = list; return paging; } public JsonResult GetCustomersJson(string term) { var list = GetCustomers(term).ResultList; return Json(list.Select(c => new { label = c.Name }).Distinct().ToList(), JsonRequestBehavior.AllowGet); } public ActionResult Index(PagingModel paging) { var list = GetCustomers(paging.SearchTerm); return View(list); } public ActionResult Grid(string term) { return PartialView(GetCustomers(term).ResultList); } // // GET: /Customer/Details/5 public ActionResult Details(int id) { return View(); } // // GET: /Customer/Create public ActionResult Create() { if (Request.IsAjaxRequest()) return PartialView(); return View(); } // // POST: /Customer/Create [HttpPost] public ActionResult Create(CustomerModel model) { if (ModelState.IsValid) { // TODO: Add insert logic here CustomerModel.Add(model); return RedirectToAction("Index"); } return View(model); } // // GET: /Customer/Edit/5 public ActionResult Edit(int id) { var model = CustomerModel.GetAll().Where(c => c.Id == id).FirstOrDefault(); return View(model); } // // POST: /Customer/Edit/5 [HttpPost] public ActionResult Edit(CustomerModel model) { if (ModelState.IsValid) { // TODO: Add insert logic here CustomerModel.Edit(model); return RedirectToAction("Index"); } return View(model); } // // GET: /Customer/Delete/5 public ActionResult Delete(int id) { return View(); } // // POST: /Customer/Delete/5 [HttpPost] public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here return RedirectToAction("Index"); } catch { return View(); } } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)