public ActionResult Create([Bind(Include = "Id,CityId,Name,Address,ImageLocation,Description,Longitude,Latitude,SortOrder")] CarParkBuildingModel model) { using (log4net.NDC.Push("Create building post")) { _logger.Info("Save specific building"); _logger.Info(model); if (ModelState.IsValid) { _logger.Info("Model is valid, map to entity model"); var entityModel = MvcModelToDatabaseModelMapper.MapBuildingForCreate(model); _entities.parking_location.Add(entityModel); try { _entities.SaveChanges(); } catch (Exception ex) { _logger.Warn("Saving of building entity failed", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } return(View(model)); } }
// GET: Building/Create public ActionResult Create() { var model = new CarParkBuildingModel(); model.SortOrder = (_entities.parking_location.Max(x => x.SortOrder) ?? 0) + 100; MvcModelToDatabaseModelMapper.MapBuildingForCreate(model); PopulateCitiesInViewBag(0); return(View(model)); }