72 lines
1.7 KiB
C#
72 lines
1.7 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using MileageTraker.Web.Models;
|
|
using MileageTraker.Web.Utility;
|
|
|
|
namespace MileageTraker.Web.Controllers
|
|
{
|
|
[Authorize(Roles = "Administrator, Developer")]
|
|
public class CityController : ControllerBase
|
|
{
|
|
[Authorize(Roles = "Administrator, Developer, Driver")]
|
|
public JsonResult Autocomplete(string term)
|
|
{
|
|
var cities = DataService.GetCitiesAutocomplete(term);
|
|
return Json(cities, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
public ActionResult Index()
|
|
{
|
|
var cities = DataService.GetCities().ToList();
|
|
var t = cities.Select(c => Tuple.Create(c.County, c.Name));
|
|
var groupTuple = CustomExtensions.GroupTuple(t);
|
|
return View(groupTuple);
|
|
}
|
|
|
|
public ActionResult Create(string county)
|
|
{
|
|
var city = new City { County = county };
|
|
return View(city);
|
|
}
|
|
|
|
//[HttpPost]
|
|
//public ActionResult Create([Bind(Exclude = "CityId")]City city)
|
|
//{
|
|
// if (ModelState.IsValid)
|
|
// {
|
|
// DataService.AddCity(city);
|
|
|
|
// TempData["StatusMessage"] = "City " + city.Name + " created";
|
|
// return RedirectToAction("Index");
|
|
// }
|
|
|
|
// return View(city);
|
|
//}
|
|
|
|
//public ActionResult Edit(int id = 0)
|
|
//{
|
|
// var city = DataService.FindCity(id);
|
|
// if (city == null)
|
|
// {
|
|
// TempData["StatusMessage"] = "Purpose " + id + " not found";
|
|
// return RedirectToAction("Index");
|
|
// }
|
|
// return View(city);
|
|
//}
|
|
|
|
//[HttpPost]
|
|
//public ActionResult Edit(City city)
|
|
//{
|
|
// if (ModelState.IsValid)
|
|
// {
|
|
// DataService.UpdateCity(city);
|
|
|
|
// TempData["StatusMessage"] = "Changes to Purpose " + city.Purpose + " saved";
|
|
// return RedirectToAction("Index");
|
|
// }
|
|
// return View(city);
|
|
//}
|
|
}
|
|
}
|