コード例 #1
0
        public void RemoveFavoritePlace(User loggedUser, long favoritePlaceId)
        {
            FavoritePlace existingFavoritePlace = loggedUser.FavoritePlaces.Where(fp => fp.Id == favoritePlaceId)
                                                  .Single();

            loggedUser.FavoritePlaces.Remove(existingFavoritePlace);
        }
コード例 #2
0
ファイル: PlaceController.cs プロジェクト: LV284NET/.Net
 public IHttpActionResult DeleteUserFavoritePlace([FromBody] FavoritePlace favoritePlace)
 {
     if (this.placeRepository.DeleteFavoritePlace(favoritePlace.UserId, favoritePlace.PlaceId))
     {
         return(this.Ok());
     }
     return(this.BadRequest());
 }
コード例 #3
0
ファイル: PlaceController.cs プロジェクト: LV284NET/.Net
 public IHttpActionResult AddUserFavoritePlace([FromBody] FavoritePlace favoriteUserPlace)
 {
     if (this.placeRepository.AddFavoritePlace(favoriteUserPlace.UserId, favoriteUserPlace.PlaceId))
     {
         return(this.Ok());
     }
     return(this.Content(HttpStatusCode.BadRequest, "You have already added this place to favourite"));
 }
コード例 #4
0
        // обработка нажатия кнопки добавления
        private async void CreateFavoritePlace(object sender, EventArgs e)
        {
            FavoritePlace     favoritePlace     = new FavoritePlace();
            FavoritePlacePage favoritePlacePage = new FavoritePlacePage();

            favoritePlacePage.BindingContext = favoritePlace;
            await Navigation.PushAsync(favoritePlacePage);
        }
コード例 #5
0
        // обработка нажатия элемента в списке
        private async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            FavoritePlace     selectedFavoritePlace = (FavoritePlace)e.SelectedItem;
            FavoritePlacePage favoritePlacePage     = new FavoritePlacePage();

            favoritePlacePage.BindingContext = selectedFavoritePlace;
            await Navigation.PushAsync(favoritePlacePage);
        }
コード例 #6
0
 private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     if (_dialogType == AddOrEditDialogType.Edit)
     {
         if (_favoritePlace != null)
         {
             ResultFavorite = new FavoritePlace
             {
                 Confidence     = null,
                 Id             = _favoritePlace.Id,
                 FontIconGlyph  = PossibleIconsList[SelectedIconIndex].Glyph,
                 IconFontFace   = PossibleIconsList[SelectedIconIndex].FontFamily.Source,
                 IconFontSize   = PossibleIconsList[SelectedIconIndex].FontSize,
                 StringId       = null,
                 Lat            = _favoritePlace.Lat,
                 Lon            = _favoritePlace.Lon,
                 Name           = _favoritePlace.Name,
                 UserChosenName = NameText,
                 Type           = ModelEnums.PlaceType.FavoritePlace
             };
         }
         else if (FavoriteRoute != null)
         {
             ResultFavorite = new FavoriteRoute
             {
                 Id                   = FavoriteRoute.Id,
                 FontIconGlyph        = PossibleIconsList[SelectedIconIndex].Glyph,
                 IconFontFace         = PossibleIconsList[SelectedIconIndex].FontFamily.Source,
                 IconFontSize         = PossibleIconsList[SelectedIconIndex].FontSize,
                 RouteGeometryStrings = FavoriteRoute.RouteGeometryStrings,
                 RoutePlaces          = FavoriteRoute.RoutePlaces,
                 UserChosenName       = NameText
             };
         }
     }
     else if (_dialogType == AddOrEditDialogType.Add)
     {
         ResultFavorite = new FavoritePlace
         {
             Confidence     = null,
             Id             = Guid.NewGuid(),
             FontIconGlyph  = PossibleIconsList[SelectedIconIndex].Glyph,
             IconFontFace   = PossibleIconsList[SelectedIconIndex].FontFamily.Source,
             IconFontSize   = PossibleIconsList[SelectedIconIndex].FontSize,
             StringId       = null,
             Lat            = SearchBoxPlace.Lat,
             Lon            = SearchBoxPlace.Lon,
             Name           = SearchBoxPlace.Name,
             UserChosenName = NameText,
             Type           = ModelEnums.PlaceType.FavoritePlace,
         };
     }
     this.Hide();
 }
コード例 #7
0
 public int SaveItem(FavoritePlace item)
 {
     if (item.Id != 0)
     {
         database.Update(item);
         return(item.Id);
     }
     else
     {
         return(database.Insert(item));
     }
 }
コード例 #8
0
        public IActionResult Create([FromForm] FavoritePlace place)
        {
            if (place == null)
            {
                return(BadRequest());
            }

            _context.FavoritePlaces.Add(place);
            _context.SaveChanges();

            return(CreatedAtRoute("Get", new { id = place.id }, place));
        }
コード例 #9
0
        public AddOrEditFavoriteDialog(IFavorite favoriteToEdit) : this()
        {
            _dialogType = AddOrEditDialogType.Edit;
            var favoriteAsPlace = favoriteToEdit as IPlace;

            if (favoriteAsPlace != null)
            {
                SearchBoxPlace = favoriteAsPlace;
            }
            NameText             = favoriteToEdit.UserChosenName;
            _editDialogIconGlyph = favoriteToEdit.FontIconGlyph;
            _editDialogIconFont  = favoriteToEdit.IconFontFace;
            FavoriteRoute        = favoriteToEdit as FavoriteRoute;
            _favoritePlace       = favoriteToEdit as FavoritePlace;
        }
コード例 #10
0
        public FavoritePlace AddFavoritePlace([FromBody] UserIdName userIdName)
        {
            string userId    = userIdName.userId;
            string placeName = userIdName.name;
            GraphClientConnection graphClient   = new GraphClientConnection();
            FavoritePlace         favoritePlace = new FavoritePlace();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            string matchQuery         = "(user:User{id:'" + userId + "'})-[like:LIKE]->(favoritePlace:Place{name:'" + placeName + "'})";
            var    favoritePlaceQuery = graphClient.client.Cypher
                                        .Match(matchQuery)
                                        .Return((favoritePlace) => new {
                FavoritePlace = favoritePlace.As <FavoritePlace>()
            })
                                        .Results;

            if (favoritePlaceQuery.Count() == 1) // relation between nodes exist already, so, you need to delete that relation
            {
                graphClient.client.Cypher
                .Match(matchQuery)
                .Delete("like")
                .ExecuteWithoutResults();
                //204
                return(null);
            }

            var newFavoritePlaceQuery = graphClient.client.Cypher
                                        .Match("(user:User{id:'" + userId + "'}),(favoritePlace:Place{name:'" + placeName + "'})")
                                        .Create("(user)-[:LIKE]->(favoritePlace)")
                                        .Return((favoritePlace) => new {
                FavoritePlace = favoritePlace.As <FavoritePlace>()
            })
                                        .Results;

            favoritePlace.name     = newFavoritePlaceQuery.ToList()[0].FavoritePlace.name;
            favoritePlace.address  = newFavoritePlaceQuery.ToList()[0].FavoritePlace.address;
            favoritePlace.imageUrl = newFavoritePlaceQuery.ToList()[0].FavoritePlace.imageUrl;
            return(favoritePlace);
        }
コード例 #11
0
        public async Task <HttpResponseMessage> AddOrUpdateFavoritePlace([FromBody] FavoritePlace value)
        {
            string token = GetHeader("token");

            if (token == null || (token != null && !TokenManager.ValidateToken(token)))
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            User loggedUser = usersService.GetLoggedUser(token);

            long returnedId = usersService.AddOrUpdateFavoritePlace(loggedUser, value);

            if (returnedId == -2)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, returnedId));
        }
コード例 #12
0
        public long AddOrUpdateFavoritePlace(User loggedUser, FavoritePlace favoritePlace)
        {
            long returnedId;

            try
            {
                FavoritePlace existingFavoritePlace = loggedUser.FavoritePlaces.Where(fp => fp.Id == favoritePlace.Id)
                                                      .Single();
                existingFavoritePlace.Name     = favoritePlace.Name;
                existingFavoritePlace.Type     = favoritePlace.Type;
                existingFavoritePlace.Location = favoritePlace.Location;
                returnedId = -1;
            }
            catch
            {
                returnedId = loggedUser.AddFavoritePlace(favoritePlace);
            }

            return(returnedId);
        }
コード例 #13
0
ファイル: TripFormViewModel.cs プロジェクト: pingzing/trippit
        private void PinnedFavoriteClicked(IFavorite favorite)
        {
            FavoritePlace place = favorite as FavoritePlace;

            if (place != null)
            {
                ToPlace = place;
            }

            FavoriteRoute route = favorite as FavoriteRoute;

            if (route != null)
            {
                FromPlace = route.RoutePlaces.First();
                ToPlace   = route.RoutePlaces.Last();
            }
            if (PlanTripCommand.CanExecute(null))
            {
                PlanTrip();
            }
        }
コード例 #14
0
        public string ChangeFavorite([FromBody] ChangeFavoriteModel model)
        {
            try
            {
                using (var context = new AppContext())
                {
                    var favorites = context.FavoritePlaces.Where(u => u.phoneNumber == model.phoneNumber & u.buildingId == model.buildingId).ToList();
                    if (favorites.Count == 0)
                    {
                        FavoritePlace favorite = new FavoritePlace()
                        {
                            phoneNumber = model.phoneNumber,
                            buildingId  = model.buildingId,
                            attribute   = 1
                        };

                        context.FavoritePlaces.Add(favorite);
                        context.SaveChanges();
                        return("true");
                    }
                    else
                    {
                        if (favorites[0].attribute == 0)
                        {
                            favorites[0].attribute = 1;
                        }
                        else
                        {
                            favorites[0].attribute = 0;
                        }
                        context.SaveChanges();
                        return("true");
                    }
                }
            }
            catch
            {
                return("Ошибка подключения");
            }
        }
コード例 #15
0
        private async void AddToFavoriteButton_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            e.Handled = true;

            FavoritePlace existingFavorite = (await _favoritesService.GetFavoritesAsync()).FirstOrDefault(x => x == SelectedPlace) as FavoritePlace;

            if (existingFavorite != null)
            {
                _favoritesService.RemoveFavorite(existingFavorite);
                SelectedPlace = new Place
                {
                    Confidence = SelectedPlace.Confidence,
                    Lat        = SelectedPlace.Lat,
                    Lon        = SelectedPlace.Lon,
                    Id         = SelectedPlace.Id,
                    Name       = SelectedPlace.Name,
                    StringId   = SelectedPlace.StringId,
                    Type       = PlaceType.Address
                };
                return;
            }

            var newFavoritePlace = new FavoritePlace
            {
                FontIconGlyph  = FontIconGlyphs.FilledStar,
                Id             = Guid.NewGuid(),
                IconFontFace   = ((FontFamily)App.Current.Resources[Constants.SymbolThemeFontResource]).Source,
                IconFontSize   = Constants.SymbolFontSize,
                Lat            = SelectedPlace.Lat,
                Lon            = SelectedPlace.Lon,
                Name           = SelectedPlace.Name,
                Type           = PlaceType.FavoritePlace,
                UserChosenName = SelectedPlace.Name
            };

            _favoritesService.AddFavorite(newFavoritePlace);
            SelectedPlace = newFavoritePlace;
        }
コード例 #16
0
        public IActionResult Update(long id, [FromForm] FavoritePlace place)
        {
            if (place == null || place.id != id)
            {
                return(BadRequest());
            }

            var newPlace = _context.FavoritePlaces.FirstOrDefault(t => t.id == id);

            if (newPlace == null)
            {
                return(NotFound());
            }

            newPlace.lat     = place.lat;
            newPlace.lng     = place.lng;
            newPlace.name    = place.name;
            newPlace.address = place.address;
            newPlace.icon    = place.icon;

            _context.FavoritePlaces.Update(newPlace);
            _context.SaveChanges();
            return(new NoContentResult());
        }