public ApiResult SaveMap(NovicellMapBuilderMapsModel model) { var result = new ApiResult(); try { result.Success = true; using (_db) { _db.Save(model); } } catch (Exception e) { result.Success = false; result.ErrorMessage = e.Message; } return(result); }
public ApiResult CreateNewMap(string name) { var result = new ApiResult(); try { result.Success = true; using (_db) { name = name.Trim(); var alias = StaticHelper.UppercaseWordsAndRemoveWhiteSpace(name.Replace("(", string.Empty).Replace(")", string.Empty)); var sql = string.Format("SELECT * FROM {0}", StaticHelper.GetMapsTableName()); var allMaps = _db.Query <NovicellMapBuilderMapsModel>(sql).ToList(); var mapName = allMaps.FirstOrDefault(x => x.Name == name); var mapAlias = allMaps.FirstOrDefault(x => x.Alias == alias); var tmpName = name; var match = true; var i = 1; while (match) { if (mapName != null) { tmpName = name + " (" + i + ")"; alias = StaticHelper.UppercaseWordsAndRemoveWhiteSpace(tmpName.Replace("(", string.Empty).Replace(")", string.Empty)); mapName = allMaps.FirstOrDefault(x => x.Name == tmpName); mapAlias = allMaps.FirstOrDefault(x => x.Alias == alias); i++; } else if (mapAlias != null) { var tmpNameTwo = name + " (" + i + ")"; alias = StaticHelper.UppercaseWordsAndRemoveWhiteSpace(tmpNameTwo.Replace("(", string.Empty).Replace(")", string.Empty)); mapAlias = allMaps.FirstOrDefault(x => x.Alias == alias); i++; } else { name = tmpName; match = false; } } var model = new NovicellMapBuilderMapsModel { Name = name, Alias = alias, InitialZoom = 7, MinZoom = 7, MaxZoom = 18, Style = "[]", DefaultIconStyle = "{\"url\":\"/App_Plugins/NcMapBuilder/Images/map-pin.png\",\"Width\":30,\"Height\":40}", ClusterStyle = "[{\"anchor\": [0, 0], \"textColor\":\"white\",\"url\":\"/App_Plugins/NcMapBuilder/Images/m1.png\",\"width\":53,\"height\":52}," + "{\"anchor\": [0, 0], \"textColor\":\"white\",\"url\":\"/App_Plugins/NcMapBuilder/Images/m2.png\",\"width\":56,\"height\":55}," + "{\"anchor\": [0, 0], \"textColor\":\"white\",\"url\":\"/App_Plugins/NcMapBuilder/Images/m3.png\",\"width\":66,\"height\":65}," + "{\"anchor\": [0, 0], \"textColor\":\"white\",\"url\":\"/App_Plugins/NcMapBuilder/Images/m4.png\",\"width\":78,\"height\":77}," + "{\"anchor\": [0, 0], \"textColor\":\"white\",\"url\":\"/App_Plugins/NcMapBuilder/Images/m5.png\",\"width\":90,\"height\":89}]", Center = "55.89736311199348,10.856373806359898", UseGeoLocation = true, UseInfoWindows = true, InfoWindowWidth = 300, InfoWindowName = "Default", Draggable = true, UseZoomControl = true, UseMapTypeControl = true, UseStreetViewControl = true, ScrollWheelEnabled = true, UseHybridMap = false }; result.Data = _db.Insert(model); } } catch (Exception e) { result.Success = false; result.ErrorMessage = e.Message; } return(result); }