public HttpResponseMessage AddLocation(LocationNew loc) { Location _loc = new Location(); _loc.Location_Banner = "Images/location.jpg"; _loc.Location_Info = loc.Info; _loc.Location_Name = loc.Name; _loc.Location_Latitude = loc.Latitude; _loc.Location_Longtitude = loc.Longtitude; _loc.LocationType_ID = loc.TypeId; _db.Locations.Add(_loc); _db.SaveChanges(); var list = new List <Location>(); list.Add(_loc); return(Request.CreateResponse(HttpStatusCode.OK, getLocations(coord, list, -1))); }
public HttpResponseMessage UpdateLocation(int locationId, LocationNew loc) { var location = _db.Locations.FirstOrDefault(p => p.Location_ID == locationId); if (location == null) { return(Request.CreateResponse(HttpStatusCode.NoContent, "")); } else { location.Location_Name = loc.Name; location.LocationType_ID = loc.TypeId; location.Location_Latitude = loc.Latitude; location.Location_Longtitude = loc.Longtitude; location.Location_Info = loc.Info; _db.Entry <Location>(location).State = EntityState.Modified; _db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, location)); } }
public void GetLocations() { var locations = _locationService.GetLocationTree(); if (locations != null && locations.Any()) { AllLocations = locations.ToList(); Locations = new List <Location>(); LocationsObservableCollection = new ObservableCollection <LocationNew>(); var parentLocation = locations.Where(p => p.ParentLocationId == 0).ToList(); if (parentLocation != null && parentLocation.Any()) { foreach (var item in parentLocation) { var location = new Location(); var locationnew = new LocationNew(); location.LocationId = item.LocationId; location.LocationName = item.LocationName; location.IsSelected = item.IsSelected; location.IsEnabled = item.IsEnabled; location.ParentLocationId = item.ParentLocationId; Locations.Add(location); locationnew.LocationId = item.LocationId; locationnew.LocationName = item.LocationName; locationnew.IsSelected = item.IsSelected; locationnew.IsEnabled = item.IsEnabled; locationnew.ParentLocationId = item.ParentLocationId; LocationsObservableCollection.Add(locationnew); locations.Remove(item); GenerateSubLocation(locationnew, locations); } } } }
private void GenerateSubLocation(LocationNew location, List <Location> lstLocation) { var subLocation = lstLocation.Where(p => p.ParentLocationId == location.LocationId); if (subLocation != null && subLocation.Any()) { location.SubLocations = new List <LocationNew>(); foreach (var item in subLocation) { item.Level = location.Level + 1; var locationnew = new LocationNew(); locationnew.LocationId = item.LocationId; locationnew.LocationName = item.LocationName; locationnew.IsSelected = item.IsSelected; locationnew.IsEnabled = item.IsEnabled; locationnew.ParentLocationId = item.ParentLocationId; locationnew.Level = item.Level; location.SubLocations.Add(locationnew); location.HasSubLocations = true; GenerateSubLocation(locationnew, lstLocation); } } }