public static parking_location MapBuildingForCreate(CarParkBuildingModel model) { var entity = new parking_location(); MapBuildingForEdit(model, entity); return(entity); }
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)); } }
public ActionResult Edit([Bind(Include = "Id,CityId,Name,Address,ImageLocation,Description,Longitude,Latitude,SortOrder")] CarParkBuildingModel model) { using (log4net.NDC.Push("Edit Building POST")) { _logger.Info("Check if model is valid"); if (ModelState.IsValid) { _logger.Info("Model is valid, save building"); var entityRecord = _entities.parking_location.FirstOrDefault(x => x.Id == model.Id); MvcModelToDatabaseModelMapper.MapBuildingForEdit(model, entityRecord); try { _logger.Info("Save building"); _entities.SaveChanges(); } catch (Exception ex) { _logger.Warn("building could not be updated", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } _logger.Warn("Model is not valid, cannot save building"); 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)); }
public static void MapBuildingForEdit(CarParkBuildingModel model, parking_location entity) { entity.Name = model.Name; entity.SortOrder = model.SortOrder; entity.Address = model.Address; entity.CityId = model.CityId; entity.Description = model.Description; if (model.Latitude != null && model.Latitude != "") { entity.Latitude = model.Latitude.ToString().Trim(); } else { entity.Latitude = model.Latitude; } if (model.Longitude != null && model.Longitude != "") { entity.Longitude = model.Longitude.ToString().Trim(); } else { entity.Longitude = model.Longitude; } }