// GET: Cities/Delete/5 public ActionResult Delete(int id) { using (log4net.NDC.Push("Delete_Building")) { if (id <= 0) { _logger.Warn("Id cannot be less than 1, bad request"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = _entities.parking_location.FirstOrDefault(x => x.Id == id); if (entity == null) { _logger.Warn("Building could not be found, not found "); return(HttpNotFound()); } _logger.Info("Building found, mapping to view model to editing purposes"); var city = _entities.cities.FirstOrDefault(x => x.id == entity.CityId); if (city != null) { _logger.Info("City found " + entity.CityId); ViewBag.CityName = city.name; return(View(MvcModelToDatabaseModelMapper.MapBuildingForDisplay(entity))); } else { _logger.Warn("City not found - CityId=" + entity.CityId); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } } }
// GET: Building/Details/5 public ActionResult Details(int id) { using (log4net.NDC.Push("Building_Detail_View")) { if (id <= 0) { _logger.Warn("Id cannot be less than 1, sending back bad request"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = _entities.parking_location.FirstOrDefault(x => x.Id == id); if (entity == null) { _logger.Warn("Building could not be found, id = " + id); return(HttpNotFound()); } _logger.Info("Building found create view model and send across to view"); var model = MvcModelToDatabaseModelMapper.MapBuildingForDisplay(entity); var city = _entities.cities.FirstOrDefault(x => x.id == entity.CityId); if (city != null) { _logger.Info("City found " + entity.CityId); ViewBag.CityName = city.name; return(View(model)); } else { _logger.Warn("City not found - CityId=" + entity.CityId); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } } }
// GET: Building public ActionResult Index() { using (log4net.NDC.Push("Buildings_Index_View")) { _logger.Info("Getting a list of all buildings in sort order"); var building = _entities.parking_location .OrderBy(x => x.SortOrder) .ToList() .Select(x => MvcModelToDatabaseModelMapper.MapBuildingForDisplay(x)) .ToList(); ViewBag.Cities = _entities.cities.ToDictionary(x => x.id, x => x.name); return(View(building)); } }