/// <summary> /// Adds a location region. /// </summary> /// <param name="newLocationRegion">The new location region.</param> /// <returns> /// <c>true</c>: If the location was added /// <c>false</c>: If the location already exists /// </returns> public bool AddLocationRegion(GeoAuthLocationRegion newLocationRegion) { if (!LocationExists(newLocationRegion.RegionName)) { //add the item to the table geoAuthAppDB.LocationRegion.InsertOnSubmit(newLocationRegion); //Save the changes geoAuthAppDB.SubmitChanges(); //name didn't exist so we added it return(true); } else { return(false); } }
/// <summary> /// Handles the Click event of the AddRegion control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param> /// <author>Andrew From (fromx010)</author> private void AddRegion_Click(object sender, RoutedEventArgs e) { clearErrorMessages(); //error messages string alreadyExistsInDB = "A Location with that name already exists"; double dRadius; string locationName = txtBoxLocationName.Text; string sLatitude = watcher.Position.Location.Latitude.ToString("0.000"); string sLongitude = watcher.Position.Location.Longitude.ToString("0.000"); double dLatitude = watcher.Position.Location.Latitude; double dLongitude = watcher.Position.Location.Longitude; if (!String.IsNullOrEmpty(txtBoxLocationName.Text)) { if (String.IsNullOrEmpty(txtBoxLocationRadius.Text)) { //Create the locationRegion object for the table GeoAuthLocationRegion newLocationRegion = new GeoAuthLocationRegion { RegionName = locationName, Latitude = dLatitude, Longitude = dLongitude }; if (geoAuthDBView.AddLocationRegion(newLocationRegion)) { //Make the API call GeoAuthApi.AddRegionRequest regionRequest = new AddRegionRequest(); regionRequest.AddRegion(sLatitude, sLongitude, locationName, getCurrentDateTime(), null); //Update the UI on the result regionRequest.AddRegionStatus += (send, evt) => { if (evt.Error == null) { lblErrors.Text = evt.Result; } }; } else { lblErrors.Text = alreadyExistsInDB; } } else if (Double.TryParse(txtBoxLocationRadius.Text, out dRadius)) { //Create the locationRegion object for the table GeoAuthLocationRegion newLocationRegion = new GeoAuthLocationRegion { RegionName = locationName, Latitude = dLatitude, Longitude = dLongitude, Radius = dRadius }; if (geoAuthDBView.AddLocationRegion(newLocationRegion)) { //Make the API call GeoAuthApi.AddRegionRequest regionRequest = new AddRegionRequest(); regionRequest.AddRegion(sLatitude, sLongitude, locationName, getCurrentDateTime(), dRadius.ToString()); //Update the UI on the result regionRequest.AddRegionStatus += (send, evt) => { if (evt.Error == null) { lblErrors.Text = evt.Result; } }; } else { lblErrors.Text = alreadyExistsInDB; } } else { lblErrors.Text = "Could not convert Radius to number"; } } else { lblErrors.Text = "Please enter a name"; } }