//GET protected override DriverResult Editor(MapPart part, dynamic shapeHelper) { var mapsSettings = _orchardServices.WorkContext.CurrentSite.As <MapsSiteSettingsPart>(); var shapeName = "Parts_Map_Edit"; var templateName = "Parts/Map"; if (mapsSettings.MapsProvider == MapsProviders.OpenStreetMap) { shapeName = "Parts_OsmMap_Edit"; templateName = "Parts/OsmMap"; } var mapEdit = new MapEditModel { MapProvider = mapsSettings.MapsProvider, MapTiles = mapsSettings.MapsTiles, MaxZoom = mapsSettings.MaxZoom, GoogleApiKey = mapsSettings.GoogleApiKey, Map = part, DecimalSeparator = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator // #GM 2015-09-15 }; return(ContentShape(shapeName, () => shapeHelper.EditorTemplate(TemplateName: templateName, Model: mapEdit, Prefix: Prefix))); }
public JsonResult Edit(MapEditModel model) { var objectId = ObjectId.GenerateNewId(); if (!string.IsNullOrEmpty(model.ID) && !ObjectId.TryParse(model.ID, out objectId)) { return(Json(new { Code = 300, Msg = "ID不合法。" })); } if (string.IsNullOrEmpty(model.Name)) { return(Json(new { Code = 300, Msg = "名称不允许为空。" })); } var mongo = new MongoHelper(); var pinyin = PinYinHelper.GetTotalPinYin(model.Name); var filter = Builders <BsonDocument> .Filter.Eq("ID", objectId); var update1 = Builders <BsonDocument> .Update.Set("Name", model.Name); var update2 = Builders <BsonDocument> .Update.Set("TotalPinYin", pinyin.TotalPinYin); var update3 = Builders <BsonDocument> .Update.Set("FirstPinYin", pinyin.FirstPinYin); UpdateDefinition <BsonDocument> update5; if (string.IsNullOrEmpty(model.Category)) { update5 = Builders <BsonDocument> .Update.Unset("Category"); } else { update5 = Builders <BsonDocument> .Update.Set("Category", model.Category); } var update = Builders <BsonDocument> .Update.Combine(update1, update2, update3, update5); mongo.UpdateOne(Constant.MapCollectionName, filter, update); return(Json(new { Code = 200, Msg = "保存成功!" })); }
//POST protected override DriverResult Editor(MapPart part, IUpdateModel updater, dynamic shapeHelper) { var partSettings = part.Settings.GetModel <MapPartSettings>(); var mapEdit = new MapEditModel { Map = part }; updater.TryUpdateModel(mapEdit, Prefix, null, null); if (partSettings.Required && (mapEdit.Map.Latitude + mapEdit.Map.Longitude) == 0) { updater.AddModelError("MapPartIsRequired", T("A point on the map is required.")); } return(Editor(part, shapeHelper)); }
public async Task <IActionResult> Put([FromBody] MapEditModel model) { var mapping = new Func <Map, Task <Map> >(async(entity) => { entity.Name = model.Name; entity.Description = model.Description; entity.PackageName = model.PackageName; entity.UnCookedAssetId = model.UnCookedAssetId; entity.FileAssetId = model.FileAssetId; if (!string.IsNullOrWhiteSpace(model.IconAssetId)) { entity.Icon = model.IconAssetId; } entity.Dependencies = model.Dependencies; entity.Properties = model.Properties; entity.Color = model.Color; return(await Task.FromResult(entity)); }); return(await _PutRequest(model.Id, mapping)); }