Example #1
0
        public async void Save()
        {
            if (Busy)
            {
                return;
            }

            Busy = true;

            if (string.IsNullOrEmpty(Text))
            {
                SaveFailed?.Invoke(this, "Reason is required.");
                Busy = false;
                return;
            }

            var reason = await Services.Host.ReasonService.SaveReason(new Reason()
            {
                Text = Text
            });

            if (string.IsNullOrEmpty(reason.Id))
            {
                SaveFailed?.Invoke(this, "Reason was not saved.");
                Busy = false;
                return;
            }

            SaveComplete?.Invoke(this, EventArgs.Empty);
            Busy = false;

            Device.StartTimer(TimeSpan.FromSeconds(1), Wait);
        }
        public async void Save()
        {
            if (Busy)
            {
                return;
            }

            Busy = true;

            if (string.IsNullOrEmpty(Vehicle.Id))
            {
                SaveFailed?.Invoke(this, "Vehicle is required");
                Busy = false;
                return;
            }

            if (Reason == "Required")
            {
                SaveFailed?.Invoke(this, "Reason is required.");
                Busy = false;
                return;
            }

            if (Authenticated)
            {
                if (string.IsNullOrEmpty(Company.Id))
                {
                    SaveFailed?.Invoke(this, "Company is required.");
                    Busy = false;
                    return;
                }
            }

            var journey = new Journey()
            {
                Company    = Company,
                Date       = Date,
                Invoiced   = Invoiced,
                Passengers = Passengers,
                Reason     = Reason,
                Vehicle    = Vehicle
            };

            foreach (var w in Services.Host.TrackerService.CurrentWaypoints.OrderBy(w => w.Step))
            {
                journey.Waypoints.Add(w);
            }

            journey.Distance = await journey.CalculateDistance();

            var result = await Services.Host.JourneyService.SaveJourney(journey);

            Saved?.Invoke(this, EventArgs.Empty);
            Busy = false;
        }
Example #3
0
 private void OnSave(string errorMessage)
 {
     if (string.IsNullOrEmpty(errorMessage))
     {
         SaveSuccessful?.Invoke();
     }
     else
     {
         SaveFailed?.Invoke(errorMessage);
     }
 }
Example #4
0
        public async void Save()
        {
            if (Busy)
            {
                return;
            }

            Busy = true;

            if (string.IsNullOrEmpty(FirstName) || string.IsNullOrEmpty(FirstName))
            {
                SaveFailed?.Invoke(this, "First and Last Name are required.");
                Busy = false;
                return;
            }

            if (string.IsNullOrEmpty(Email))
            {
                SaveFailed?.Invoke(this, "Email is required.");
                Busy = false;
                return;
            }

            if (string.IsNullOrEmpty(Address.PlaceId))
            {
                SaveFailed?.Invoke(this, "Address is required.");
                Busy = false;
                return;
            }

            var result = await Services.Host.UserService.UpdateDetails(FirstName, LastName, Email, Address.PlaceId);

            if (result.Error)
            {
                SaveFailed?.Invoke(this, result.Message);
                Busy = false;
            }

            SaveComplete?.Invoke(this, EventArgs.Empty);
            Busy = false;
        }
        public async void Save()
        {
            if (Busy)
            {
                return;
            }

            Busy = true;

            if (string.IsNullOrEmpty(OriginAddress.PlaceId))
            {
                SaveFailed?.Invoke(this, "Origin is required.");
                Device.StartTimer(TimeSpan.FromSeconds(1), Wait);
                return;
            }

            if (string.IsNullOrEmpty(DestinationAddress.PlaceId))
            {
                SaveFailed?.Invoke(this, "Destination is required.");
                Device.StartTimer(TimeSpan.FromSeconds(1), Wait);
                return;
            }

            if (string.IsNullOrEmpty(Vehicle.Id))
            {
                SaveFailed?.Invoke(this, "Vehicle is required");
                Device.StartTimer(TimeSpan.FromSeconds(1), Wait);
                return;
            }

            if (Reason == "Required")
            {
                SaveFailed?.Invoke(this, "Reason is required.");
                Device.StartTimer(TimeSpan.FromSeconds(1), Wait);
                return;
            }

            if (Authenticated)
            {
                if (string.IsNullOrEmpty(Company.Id))
                {
                    SaveFailed?.Invoke(this, "Company is required.");
                    Device.StartTimer(TimeSpan.FromSeconds(1), Wait);
                    return;
                }
            }

            var originWaypoint = new Waypoint()
            {
                PlaceId   = OriginAddress.PlaceId,
                Latitude  = OriginAddress.Latitude,
                Longitude = OriginAddress.Longitude,
                Label     = OriginAddress.Label,
                Step      = 0
            };
            var destinationWaypoint = new Waypoint()
            {
                PlaceId   = DestinationAddress.PlaceId,
                Latitude  = DestinationAddress.Latitude,
                Longitude = DestinationAddress.Longitude,
                Label     = DestinationAddress.Label,
                Step      = 1
            };

            var journey = new Journey()
            {
                Company    = Company,
                Date       = Date,
                Invoiced   = Invoiced,
                Passengers = Passengers,
                Reason     = Reason,
                Vehicle    = Vehicle
            };

            journey.Waypoints.Add(originWaypoint);
            journey.Waypoints.Add(destinationWaypoint);

            journey.Distance = await journey.CalculateDistance();

            var result = await Services.Host.JourneyService.SaveJourney(journey);

            Saved?.Invoke(this, EventArgs.Empty);
            Device.StartTimer(TimeSpan.FromSeconds(1), Wait);
        }