Пример #1
0
        public void Execute(object parameter)
        {
            FishingLoc loc = (FishingLoc)parameter;

            if (loc != null)
            {
                _viewModel.DeleteLoc(loc);
            }
        }
Пример #2
0
        public async void Execute(object parameter)
        {
            FishingLoc loc = (FishingLoc)parameter;

            if (loc != null)
            {
                await _viewModel.InsertLoc(loc);

                await PopupNavigation.Instance.PopAsync(true);

                //_viewModel.SelectedLocTab = 0;
                //_viewModel.OptionSelectionChangedCommand.Execute(_viewModel.SelectedLocTab);
            }
        }
Пример #3
0
        public bool UpdateLocs()
        {
            try
            {
                var locs = FishingLoc.GetNamedFishingLoc(App.user.IdUser);

                if (locs != null)
                {
                    Locs.Clear();
                    foreach (var loc in locs)
                    {
                        Locs.Add(loc);
                    }
                }
                UpdatePins();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
 public bool DeleteLoc(FishingLoc loc)
 {
     FishingLoc.Delete(loc);
     HomeViewModel.UpdateLocs();
     return(true);
 }
        public async Task <bool> InsertLoc(FishingLoc loc, bool fromFish = false)
        {
            if (loc == null)
            {
                loc = new FishingLoc();
            }
            Coordinate coor = new Coordinate()
            {
                IdCoordinate = Guid.NewGuid().ToString()
            };

            if (LocActivationSwitchState)
            {
                //From geolocator
                try
                {
                    var locator  = CrossGeolocator.Current;
                    var position = await locator.GetPositionAsync();

                    if (position != null)
                    {
                        coor.Lattitude = position.Latitude;
                        coor.Longitude = position.Longitude;
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                //from Selection
                loc.Name       = CurrentLoc.Name;
                loc.PlaceCount = CurrentLoc.PlaceCount;
                loc.Type       = CurrentLoc.Type;

                if (CreatedPins.Count == 1)
                {
                    foreach (var pin in CreatedPins)
                    {
                        coor.Lattitude = pin.Pin.Position.Latitude;
                        coor.Longitude = pin.Pin.Position.Longitude;
                    }
                }
            }
            Waypoint wp = new Waypoint()
            {
                Coordinate = coor, IdWaypoint = Guid.NewGuid().ToString()
            };

            loc.Waypoints.Add(wp);
            if (fromFish)
            {
                loc.Type       = "GPS";
                loc.Name       = null;
                loc.PlaceCount = 0;
            }
            else
            {
                loc.Type       = CurrentLoc.Type;
                loc.Name       = CurrentLoc.Name;
                loc.PlaceCount = CurrentLoc.PlaceCount;
            }

            loc.IdFishingLoc = Guid.NewGuid().ToString();
            loc.User_IdUser  = App.user.IdUser;
            FishingLoc.Insert(loc);
            CurrentLoc = new FishingLoc();
            CreatedPins.Clear();
            HomeViewModel.UpdateLocs();

            return(true);
        }
        public LocationViewModel(HomeViewModel viewModel)
        {
            HomeViewModel = viewModel;

            CurrentLoc = new FishingLoc();
            LocActivationSwitchState = true;
            ListLocationIsVisible    = true;
            AddLocMapVisible         = false;

            CreatedPins         = new ObservableCollection <CustomPin>();
            OnTappingMapCommand = new OnTappingMapCommand(this);
            OnTapAction         = new Action <Position>(data => AddCreatedPin(data));
            RefreshLocCommand   = new RefreshLocCommand(this);
            SaveLocCommand      = new SaveLocCommand(this);
            DeleteLocCommand    = new DeleteLocCommand(this);

            async void getLocation()
            {
                var locator  = CrossGeolocator.Current;
                var position = await locator.GetPositionAsync();

                CurrentMapSpan = new MapSpan(new Position(position.Latitude, position.Longitude), 0.1, 0.1);
            };
            getLocation();

            List <String> lst = new List <String>()
            {
                "locations",
                "stat",
            };

            this.RibbonOptions = lst;

            List <StackLayout> fishOpt = new List <StackLayout>
            {
                new ListLocationBodyView(this),
                new StatLocationBodyView(this)
            };

            this.LocationViewOptions = fishOpt;

            this.OptionSelectionChangedCommand = new Command((obj) =>
            {
                var selectedItemRibbonIndex = obj.ToString();

                HomeViewModel.IsToolbarMenuOpened = false;
                HomeViewModel.IsMenuSlide         = false;
                ListLocationIsVisible             = false;
                AddLocationIsVisible  = false;
                StatLocationIsVisible = false;

                if (selectedItemRibbonIndex == "0")
                {
                    ListLocationIsVisible = true;
                }
                else if (selectedItemRibbonIndex == "1")
                {
                    StatLocationIsVisible = true;
                }
                else
                {
                    AddLocationIsVisible = true;
                }
            });
        }
Пример #7
0
        public async Task <bool> InsertFish(Fish fish)
        {
            if (fish == null)
            {
                fish = new Fish();
            }
            if (fish.Weight > 0 && TypePickerItemSelected != null)
            {
                if (!AutoLocationSwitchState)
                {
                    var locator  = CrossGeolocator.Current;
                    var position = await locator.GetPositionAsync();

                    if (position != null)
                    {
                        //we need to add this new auto generated location to DB
                        fish.FishingLoc = new FishingLoc()
                        {
                            IdFishingLoc = Guid.NewGuid().ToString(),
                            Type         = "GPS",
                            Name         = null,
                            PlaceCount   = 0
                        };
                        fish.FishingLoc.Waypoints.Add(
                            new Waypoint
                        {
                            IdWaypoint = Guid.NewGuid().ToString(),
                            Coordinate = new Coordinate
                            {
                                IdCoordinate = Guid.NewGuid().ToString(),
                                Lattitude    = position.Latitude,
                                Longitude    = position.Longitude
                            }
                        });
                        FishingLoc.Insert(fish.FishingLoc);
                    }
                }
                else
                {
                    if (LocPickerItemSelected != null && ManuLocationSwitchState)
                    {
                        fish.FishingLoc = (FishingLoc)LocPickerItemSelected;
                    }
                    else if (!ManuLocationSwitchState)
                    {
                        fish.FishingLoc = null;
                    }
                }

                if (fish.FishingLoc != null)
                {
                    //When inserted from this method, Locations should have only 1 waypoint so we take this one in reference
                    fish.Waypoint_IdWaypoint = ((from w in fish.FishingLoc.Waypoints select w).ToList().FirstOrDefault()).IdWaypoint;
                }

                //link the fish with the fish type
                fish.FishType        = ((FishType)TypePickerItemSelected);
                fish.CatchedDateTime = DateTime.Now;
                fish.User_IdUser     = App.user.IdUser;
                fish.Bait            = CurrentFish.Bait;
                fish.Weight          = CurrentFish.Weight;
                fish.Length          = CurrentFish.Length;
                fish.IdFish          = Guid.NewGuid().ToString();
                Fish.Insert(fish);
                if (CurrentFish != null)
                {
                    //ResetingAddFields();
                    HomeViewModel.UpdateFishes();
                    return(true);
                }
                return(false);
            }
            else
            {
                await App.Current.MainPage.DisplayAlert("Empty field", "Please fill the type and the weight", "OK");

                return(false);
            }
        }