Posted on 24/09/2015 14:32:58
Hi Rasmus
I think you can - here is the code behind the button:
Protected Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateGeoLocations.ServerClick
Dim locations As New Generic.List(Of LocationItem)
Dim ids As New Generic.List(Of Integer)
For Each item As System.Web.UI.WebControls.ListItem In GroupIDs.Items
If item.Selected Then
Dim id As Integer
Integer.TryParse(item.Value, id)
If id > 0 Then
ids.Add(id)
End If
End If
Next
Dim includeEmptyAdresses As Boolean = Base.ChkBoolean(Request("includeEmptyAdresses"))
Dim groups As Modules.UserManagement.GroupCollection = Modules.UserManagement.Group.GetGroupsByID(ids)
For Each group As Modules.UserManagement.Group In groups
Dim status As Dynamicweb.SystemTools.Maps.GeoLocationStatus
If includeEmptyAdresses Or Not String.IsNullOrEmpty(Dynamicweb.SystemTools.Maps.GetGetLocationAddress(group)) Then
status = Dynamicweb.SystemTools.Maps.SetGeoLocationFromGoogleMapsAPI(group)
If status = Dynamicweb.SystemTools.Maps.GeoLocationStatus.Updated Then
Try
group.Save()
Catch ex As Exception
End Try
End If
locations.Add(LocationItem.Create(group, status))
End If
For Each user As Modules.UserManagement.User In group.Users
If includeEmptyAdresses Or Not String.IsNullOrEmpty(Dynamicweb.SystemTools.Maps.GetGetLocationAddress(user)) Then
status = Dynamicweb.SystemTools.Maps.SetGeoLocationFromGoogleMapsAPI(user)
If status = Dynamicweb.SystemTools.Maps.GeoLocationStatus.Updated Then
Try
''' User.Save fails if Username is not set
user.Save()
Catch ex As Exception
End Try
End If
locations.Add(LocationItem.Create(user, status))
End If
Next
Next
RenderLocations(locations)
End Sub
Friend Class LocationItem
Public Property Location As Modules.Maps.Maps.Location
Public Property FormattedAddress As String
Public Property Status As String
Public ReadOnly Property Name As String
Get
If Not Location Is Nothing AndAlso Not String.IsNullOrEmpty(Location.Name) Then
Return Location.Name
End If
Return "(no name)"
End Get
End Property
Public ReadOnly Property Lat As Double
Get
If Not Location Is Nothing Then
Return Location.Lat
End If
Return 0
End Get
End Property
Public ReadOnly Property Lng As Double
Get
If Not Location Is Nothing Then
Return Location.Lng
End If
Return 0
End Get
End Property
Public Shared Function Create(group As Modules.UserManagement.Group, status As Dynamicweb.SystemTools.Maps.GeoLocationStatus) As LocationItem
Return New LocationItem() With {
.Location = Modules.Maps.Maps.Location.Create(group),
.FormattedAddress = Dynamicweb.SystemTools.Maps.GetGetLocationAddress(group),
.Status = status.ToString()
}
End Function
Public Shared Function Create(user As Modules.UserManagement.User, status As Dynamicweb.SystemTools.Maps.GeoLocationStatus) As LocationItem
Return New LocationItem() With {
.Location = Modules.Maps.Maps.Location.Create(user),
.FormattedAddress = Dynamicweb.SystemTools.Maps.GetGetLocationAddress(user),
.Status = status.ToString()
}
End Function
End Class