Add required city field
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.Attributes;
|
||||
using MileageTraker.Web.Models;
|
||||
using MileageTraker.Web.Utility;
|
||||
|
||||
@@ -8,13 +9,13 @@ 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);
|
||||
}
|
||||
return Json(cities, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
@@ -26,46 +27,36 @@ namespace MileageTraker.Web.Controllers
|
||||
|
||||
public ActionResult Create(string county)
|
||||
{
|
||||
var city = new City { County = 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);
|
||||
[ActionLog]
|
||||
[HttpPost]
|
||||
public ActionResult Create([Bind(Exclude = "CityId")] City city)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
DataService.AddCity(city);
|
||||
|
||||
// TempData["StatusMessage"] = "City " + city.Name + " created";
|
||||
// return RedirectToAction("Index");
|
||||
// }
|
||||
TempData["StatusMessage"] = "City " + city.Name + " created";
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
// return View(city);
|
||||
//}
|
||||
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);
|
||||
//}
|
||||
public JsonResult CityNameAvailable(string name)
|
||||
{
|
||||
var city = DataService.FindCityByName(name);
|
||||
return Json(city == null, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
//[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);
|
||||
//}
|
||||
}
|
||||
[Authorize(Roles = "Administrator, Developer, Driver")]
|
||||
public JsonResult CityNameExists(string cityname)
|
||||
{
|
||||
var city = DataService.FindCityByName(cityname);
|
||||
return Json(city != null, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,6 +270,16 @@ namespace MileageTraker.Web.Controllers
|
||||
Action = GetFixLink(viewModel)
|
||||
}, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
// verify city exists
|
||||
if (DataService.FindCityByName(log.CityName) == null)
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
Status = ImportStatus.Failure.ToString(),
|
||||
Message = "City must exist in system",
|
||||
Action = GetFixLink(viewModel)
|
||||
}, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
// SAVE IT!
|
||||
DataService.AddLog(log);
|
||||
|
||||
@@ -350,6 +350,16 @@ namespace MileageTraker.Web.Controllers
|
||||
Action = GetFixLink(viewModel)
|
||||
}, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
// verify city exists
|
||||
if (DataService.FindCityByName(log.CityName) == null)
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
Status = ImportStatus.Failure.ToString(),
|
||||
Message = "City must exist in system",
|
||||
Action = GetFixLink(viewModel)
|
||||
}, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
// SAVE IT!
|
||||
DataService.AddLog(log);
|
||||
|
||||
Reference in New Issue
Block a user