public async Task <PlaceDto> Handle(CreatePlaceCommand request, CancellationToken cancellationToken) { var place = Place.Create(request.Latitude, request.Attitude, request.Name, request.Description, request.Address, request.CategoryId); await _placeRepository.CreateAsync(place); return(new PlaceDto(place.PlaceId)); }
public async Task <string> SavePlaceAsync(PlaceSave resource) { var used = 0; var user = await _unitOfWork.Users.FindByIdAsync(resource.OwnerId); if (user == null) { return("Owner not found"); } var categories = _unitOfWork.Category.Find(e => e.Name.ToLower() == resource.Category).ToList(); var newCategory = categories.Count == 0 ? Category.Create(resource.Category) : categories.First(); var location = Place.Create(user, resource.Name, resource.Description, newCategory, Convert.ToSingle(resource.TicketPrice)); var guids = GeneratePaths(resource.PhotosContentStreams.Count); foreach (var stream in resource.PhotosContentStreams.Select(entry => new MemoryStream(entry.Value))) { FileService.SaveStreamAsFile(Directory.GetCurrentDirectory(), stream, guids[used] + ".png"); location.Photos.Add(Photo.Create(Directory.GetCurrentDirectory() + guids[used] + ".png")); used++; } _unitOfWork.Locations.AddAsync(location); return("Success"); }
public IActionResult Post([FromBody] Place place) { if (place == null) { return(BadRequest()); } var entity = Place.Create(place.Name, place.Rating, place.Address, place.Latitude, place.Longitude, place.OpenNow); _repository.Add(entity); _repository.SaveChanges(); return(Ok(place)); }
public void TestExistsForCgndbKey() { string cgndbKey = "ABCDE"; Place place = new Place(); place.CgndbKey = cgndbKey; place.Create(); Watershed watershed = new Watershed(); watershed.DrainageCode = "01-02-03-04-05-06"; watershed.Place = place; watershed.Create(); Flush(); Assert.IsTrue(Watershed.ExistsForCgndbKey(cgndbKey)); }
public ActionResult Create(PlaceVm vm) { try { if (!ModelState.IsValid) { return(View()); } var model = new Place(); model.Create(vm); return(RedirectToAction("Index")); } catch (Exception ex) { return(View("Error")); } }
public Response <PlaceSave> SaveAsync(PlaceSave resource) { var user = _unitOfWork.Users.Find(e => e.UserId == resource.OwnerId).ToList(); var category = _unitOfWork.Category.Find(e => e.Name == resource.Category).ToList(); if (user.Count != 1) { return(new Response <PlaceSave>("User not found")); } Category newCategory; if (category.Count != 1) { newCategory = Category.Create(resource.Category); _unitOfWork.Category.Add(newCategory); } else { newCategory = category.First(); } var place = Place.Create(user.First(), resource.Name, resource.Description, newCategory, Convert.ToSingle(resource.TicketPrice), resource.Address, resource.Lat, resource.Ltn); var used = 0; var guids = GeneratePaths(resource.PhotosContentStreams.Count); foreach (var stream in resource.PhotosContentStreams.Select(entry => new MemoryStream(entry.Value))) { FileService.SaveStreamAsFile(Path.Combine(Directory.GetCurrentDirectory(), PathFolder), stream, guids[used] + ".png"); // place.Photos.Add(Photo.Create(Directory.GetCurrentDirectory() + guids[used] + ".png")); var photo = Photo.Create(Path.Combine(PathFolder, guids[used] + ".png")); place.Photos.Add(photo); _unitOfWork.Photo.Add(photo); used++; } _unitOfWork.Locations.Add(place); _unitOfWork.Complete(); return(new Response <PlaceSave>(resource)); }
public void TestFindAllByQuery() { string[] placeNames = { "Saint", "Saint John", "Saint John River", "Hammond River", "Fredericton", "Moncton", "Miramichi River" }; for(int i=0; i < placeNames.Length; i++) { Place place = new Place(); place.Name = placeNames[i]; // XXX: this is technically not a valid CGNDB Key but no validation is performed place.CgndbKey = i.ToString(); place.Create(); } Flush(); Assert.AreEqual(3, Place.FindAllByQuery("Saint").Count, "Query for 'Saint'"); Assert.AreEqual(3, Place.FindAllByQuery("saint").Count, "Query for 'saint'"); Assert.AreEqual(1, Place.FindAllByQuery("Fredericton").Count, "Query for 'Fredericton'"); Assert.AreEqual(2, Place.FindAllByQuery("M").Count, "Query for 'M' returned"); Assert.AreEqual(0, Place.FindAllByQuery("John").Count, "Query for 'John'"); Assert.AreEqual(0, Place.FindAllByQuery("River").Count, "Query for 'River'"); Assert.AreEqual(3, Place.FindAllByQuery(" Saint").Count, "Query for ' Saint'"); Assert.AreEqual(1, Place.FindAllByQuery("Hammond River ").Count, "Query for 'Hammond River '"); }
/* * TODO: First pass: parse out existing things, the place we're in and decorators * Second pass: search for places in the world to make links * Third pass: More robust logic to avoid extra merging later */ private IEnumerable <IContext> ParseSpeech(IEntity observer, IEntity actor, IList <Tuple <string, bool> > words) { /* * hello * hi there * did you go to the store * what are you doing there * I saw a red ball in the living room */ var returnList = new List <IContext>(); IPlace currentPlace = (IPlace)observer.Position; var brandedWords = BrandWords(observer, actor, words, currentPlace); var allOtherPlaces = DataCache.GetAll <IPlace>().Where(place => place != currentPlace); var linkedPlaces = new List <IPlace>(); foreach (var place in allOtherPlaces) { if (brandedWords.ContainsKey(place.Name)) { continue; } brandedWords.Remove(place.Name); linkedPlaces.Add(place); } var targetWord = string.Empty; //No valid nouns to make the target? Pick the last one if (!brandedWords.Any(ctx => ctx.Value == null)) { targetWord = brandedWords.LastOrDefault().Key; } else { targetWord = brandedWords.LastOrDefault(ctx => ctx.Value == null).Key; } brandedWords.Remove(targetWord); var descriptors = new List <IDescriptor>(); foreach (var adjective in brandedWords.Where(ctx => ctx.Value == null || ctx.Value?.GetType() == typeof(Descriptor))) { if (adjective.Value != null) { descriptors.Add((Descriptor)adjective.Value); } else { descriptors.Add(new Descriptor() { Name = adjective.Key }); } } returnList.AddRange(descriptors); if (observer == currentPlace) { //Make a new place if (!allOtherPlaces.Any(place => place.Name.Equals(targetWord, StringComparison.InvariantCultureIgnoreCase))) { var newPlace = new Place(DataStore, DataCache, Logger); newPlace.Name = targetWord; newPlace.LinkedPlaces.Add(currentPlace); newPlace.Create(); currentPlace.LinkPlace(newPlace); } //Add the place links and places foreach (var place in linkedPlaces.Where(pl => !currentPlace.LinkedPlaces.Contains(pl))) { currentPlace.LinkPlace(place); } currentPlace.Save(); } return(returnList); }
public void TestFindByCgndbKey() { string cgndbKey = "ABCDE"; Place place = new Place(); place.CgndbKey = cgndbKey; place.Create(); Watershed watershed = new Watershed(); watershed.DrainageCode = "01-02-03-04-05-06"; watershed.Place = place; watershed.Create(); Flush(); Watershed foundWatershed = Watershed.FindByCgndbKey(cgndbKey); Assert.AreEqual(watershed, foundWatershed); Assert.AreEqual(place, foundWatershed.Place); }
public void GetPlacesIasi(string givenType) { SearchPlaceType type = SearchPlaceType.Cafe; if (givenType == "airport") { type = SearchPlaceType.Airport; } else if (givenType == "atm") { type = SearchPlaceType.Atm; } else if (givenType == "bank") { type = SearchPlaceType.Bank; } else if (givenType == "beautysalon") { type = SearchPlaceType.BeautySalon; } else if (givenType == "bookstore") { type = SearchPlaceType.BookStore; } else if (givenType == "cafe") { type = SearchPlaceType.Cafe; } else if (givenType == "carwash") { type = SearchPlaceType.CarWash; } else if (givenType == "church") { type = SearchPlaceType.Church; } else if (givenType == "gasstation") { type = SearchPlaceType.GasStation; } else if (givenType == "gym") { type = SearchPlaceType.Gym; } else if (givenType == "hospital") { type = SearchPlaceType.Hospital; } else if (givenType == "library") { type = SearchPlaceType.Library; } else if (givenType == "club") { type = SearchPlaceType.NightClub; } else if (givenType == "park") { type = SearchPlaceType.Park; } else if (givenType == "restaurant") { type = SearchPlaceType.Restaurant; } else if (givenType == "school") { type = SearchPlaceType.School; } else if (givenType == "mall") { type = SearchPlaceType.ShoppingMall; } else if (givenType == "university") { type = SearchPlaceType.University; } else if (givenType == "zoo") { type = SearchPlaceType.Zoo; } var request = new PlacesNearBySearchRequest { Location = new Location(47.1584549, 27.601441), Radius = 5000, Type = type, Key = "AIzaSyDIBvIu8PiqdBewk342wTL7B9M-ym5bK84" }; var result = GooglePlaces.NearBySearch.Query(request); Place place = new Place(); foreach (var it in result.Results) { Place placeToInsert = place.Create(it.PlaceId, it.Name, it.Geometry.Location.Latitude, it.Geometry.Location.Longitude, it.Rating, it.Vicinity, it.IconUrl); _context.Add(placeToInsert); } }
public void TestExistsForCgndbKeyOrAltCgndbKeyWhenWaterbodyHasAltCgndbKey() { string altCgndbKey = "ABCDE"; Place place = new Place(); place.CgndbKey = altCgndbKey; place.Create(); WaterBody waterbody = new WaterBody(); waterbody.AltPlace = place; waterbody.Create(); Flush(); Assert.IsTrue(WaterBody.ExistsForCgndbKeyOrAltCgndbKey(altCgndbKey)); }
public void TestFindByCgndbKeyOrAltCgndbKeyWhenWaterbodyHasCgndbKey() { string cgndbKey = "ABCDE"; Place place = new Place(); place.CgndbKey = cgndbKey; place.Create(); WaterBody waterbody = new WaterBody(); waterbody.Place = place; waterbody.Create(); Flush(); WaterBody foundWaterbody = WaterBody.FindByCgndbKeyOrAltCgndbKey(cgndbKey); Assert.AreEqual(waterbody, foundWaterbody); Assert.AreEqual(place, foundWaterbody.Place); }
private void comboBoxPlace_SelectedIndexChanged(object sender, EventArgs e) { string my_selected = comboBoxPlace.SelectedItem.ToString(); string my_location = m_LoggedInUser.Location.Name.ToString(); Place place = Place.Create(my_selected, my_location); }