Exemple #1
0
        public async Task <bool> InsertSession(Session session)
        {
            //Checking which location param has been selected
            if (!LocParamSessionSwitchState || (LocParamSessionSwitchState && LocTrackingSessionSwitchState))
            {
                //starting getting current location
                var locator  = CrossGeolocator.Current;
                var position = await locator.GetPositionAsync();

                //create coordinates
                Coordinate coor = new Coordinate()
                {
                    IdCoordinate = Guid.NewGuid().ToString(), Lattitude = position.Latitude, Longitude = position.Longitude
                };
                Waypoint wp = new Waypoint()
                {
                    IdWaypoint = Guid.NewGuid().ToString(), Coordinate = coor,
                };
                session.FishingLoc = new FishingLoc()
                {
                    IdFishingLoc = Guid.NewGuid().ToString(), Name = "GPS", Waypoints = new List <Waypoint>()
                    {
                        wp
                    }
                };
            }
            else
            {
                session.FishingLoc = (FishingLoc)SessionLocPickerSelectedItem;
            }

            //Checking which time param has been selected
            if (TimeParamSessionSwitchState)
            {
                session.Starts    = CurrentSession.Starts;
                session.Ends      = CurrentSession.Ends;
                session.IsRunning = false;
            }
            else
            {
                session.Starts    = DateTime.Now;
                session.IsRunning = true;
            }
            session.IdSession           = Guid.NewGuid().ToString();
            session.User_IdUserCreation = App.user.IdUser;
            Session.Insert(session);
            CurrentSession = session;
            if (CurrentSession != null)
            {
                HomeViewModel.UpdateSessions();
                if (CurrentSession.IsRunning)
                {
                    HomeViewModel.RunningSession = CurrentSession;
                    HomeViewModel.StartSession();
                }

                return(true);
            }
            return(false);
        }
Exemple #2
0
        public async Task <bool> InsertFishInSession(Fish fish)
        {
            if (fish.Weight > 0 && TypePickerItemSelected != null)
            {
                if (HomeViewModel.RunningSession.FishingLoc != null)
                {
                    if (HomeViewModel.RunningSession.FishingLoc.Name != "GPS")
                    {
                        //known location
                        CurrentFish.FishingLoc_IdFishingLoc = HomeViewModel.RunningSession.FishingLoc_IdFishingLoc;
                    }
                    else
                    {
                        //get current Loc
                        var locator  = CrossGeolocator.Current;
                        var position = await locator.GetPositionAsync();

                        if (position != null)
                        {
                            //add the waypoint to the fishing Loc in the session & in the Fish
                            Waypoint wp = new Waypoint
                            {
                                IdWaypoint = Guid.NewGuid().ToString(),
                                Coordinate = new Coordinate
                                {
                                    IdCoordinate = Guid.NewGuid().ToString(),
                                    Lattitude    = position.Latitude,
                                    Longitude    = position.Longitude
                                }
                            };
                            HomeViewModel.RunningSession.FishingLoc.Waypoints.Add(wp);
                            CurrentFish.Waypoint_IdWaypoint = wp.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.Session_IdSession = HomeViewModel.RunningSession.IdSession;
                HomeViewModel.RunningSession.Fishes.Add(fish);
                Session.InsertFullSession(HomeViewModel.RunningSession);
                //ResetingAddFields();
                HomeViewModel.UpdateFishes();
                HomeViewModel.UpdateSessions();
            }
            return(true);
        }