コード例 #1
0
        public CampingTripRegistrationForAdminViewModel()
        {
            this.AddDirectionCommand       = new Command(o => AddDirectionToRegistrationTrip());
            this.AddFoodToTripFoodsCommand = new Command(o => AddFoodToRegistrationTripFoods(), o => CanAddFoodToTripFoods());
            this.RegisterTripCommand       = new Command(o => RegistrationTrip());

            this.direction        = new ObservableCollection <DirectionDetails>();
            this.foods            = new ObservableCollection <UIFoodInfo>();
            this.tripRegistration = new CampingTripInfo();
            this.tripRegistration.DepartureDate = DateTime.Now;
            this.tripRegistration.ArrivalDate   = DateTime.Now;
            this.httpClient             = new HttpClient();
            this.httpClient.BaseAddress = new Uri(ConfigurationManager.AppSettings["baseUrl"]);
            ConnectToServer();
            GetUserInfo();
        }
コード例 #2
0
        public void GetAllTripsUserIsJoined()
        {
            var tokenResponse = tokenClient.RequestRefreshTokenAsync(ConfigurationSettings.AppSettings["refreshToken"]).Result;

            httpClient.SetBearerToken(tokenResponse.AccessToken);
            var response = httpClient.GetAsync($"api/MembersOfCampingTrip/{user.Id}").Result;

            var content = response.Content;

            var jsonContent = content.ReadAsStringAsync().Result;

            var tripIds = JsonConvert.DeserializeObject <List <string> >(jsonContent);



            var campingTrips = new ObservableCollection <TripsInProgress>();

            if (tripIds != null)
            {
                foreach (var tripId in tripIds)
                {
                    var tripResponse    = httpClient.GetAsync($"api/CampingTrips/{tripId}").Result;
                    var tripContent     = tripResponse.Content;
                    var tripJsonContent = tripContent.ReadAsStringAsync().Result;
                    var trip            = JsonConvert.DeserializeObject <CampingTrip>(tripJsonContent);


                    var campingtrip = new CampingTripInfo()
                    {
                        Place             = trip.Place,
                        DepartureDate     = trip.DepartureDate,
                        ArrivalDate       = trip.ArrivalDate,
                        CountOfMembers    = trip.CountOfMembers,
                        MinAge            = trip.MinAge,
                        MaxAge            = trip.MaxAge,
                        MinCountOfMembers = trip.MinCountOfMembers,
                        MaxCountOfMembers = trip.MaxCountOfMembers,
                        Direction         = trip.Direction,
                        HasGuide          = trip.HasGuide,
                        HasPhotographer   = trip.HasPhotographer,
                        PriceOfTrip       = trip.PriceOfTrip,
                        ID = trip.ID
                    };
                    if (trip.TypeOfTrip == Kanch.DataModel.TypeOfCampingTrip.Campaign)
                    {
                        campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.Campaign;
                    }
                    else if (trip.TypeOfTrip == Kanch.DataModel.TypeOfCampingTrip.CampingTrip)
                    {
                        campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.CampingTrip;
                    }
                    else
                    {
                        campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.Excursion;
                    }
                    if (trip.Food != null)
                    {
                        campingtrip.Food = new ObservableCollection <FoodInfo>();
                        foreach (var food in trip.Food)
                        {
                            campingtrip.Food.Add(new FoodInfo()
                            {
                                Name            = food.Name,
                                Measure         = food.Measure,
                                MeasurementUnit = food.MeasurementUnit
                            });
                        }
                    }

                    campingtrip.MembersOfCampingTrip = new ObservableCollection <UserInfo>();
                    campingtrip.IAmJoined            = true;

                    var tripInProgress = new TripsInProgress();

                    tripInProgress.CampingTrip   = campingtrip;
                    tripInProgress.RefuseCommand = new Command(Refuse);

                    this.TripsInProgress.Add(tripInProgress);
                }
            }
        }
コード例 #3
0
        public void GetAllInProgressTrips()
        {
            var response = httpClient.GetAsync("api/CampingTrips").Result;

            var content = response.Content;

            var jsonContent = content.ReadAsStringAsync().Result;

            var trips = JsonConvert.DeserializeObject <List <CampingTrip> >(jsonContent);

            var campingTrips = new ObservableCollection <TripsInProgress>();

            if (trips != null)
            {
                foreach (var trip in trips)
                {
                    var campingtrip = new CampingTripInfo()
                    {
                        Place             = trip.Place,
                        DepartureDate     = trip.DepartureDate,
                        ArrivalDate       = trip.ArrivalDate,
                        CountOfMembers    = trip.CountOfMembers,
                        MinAge            = trip.MinAge,
                        MaxAge            = trip.MaxAge,
                        MinCountOfMembers = trip.MinCountOfMembers,
                        MaxCountOfMembers = trip.MaxCountOfMembers,
                        Direction         = trip.Direction,
                        HasGuide          = trip.HasGuide,
                        HasPhotographer   = trip.HasPhotographer,
                        ID          = trip.ID,
                        PriceOfTrip = trip.PriceOfTrip
                    };
                    if (trip.TypeOfTrip == Kanch.DataModel.TypeOfCampingTrip.Campaign)
                    {
                        campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.Campaign;
                    }
                    else if (trip.TypeOfTrip == Kanch.DataModel.TypeOfCampingTrip.CampingTrip)
                    {
                        campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.CampingTrip;
                    }
                    else
                    {
                        campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.Excursion;
                    }
                    if (trip.Food != null)
                    {
                        campingtrip.Food = new ObservableCollection <FoodInfo>();
                        foreach (var food in trip.Food)
                        {
                            campingtrip.Food.Add(new FoodInfo()
                            {
                                Name            = food.Name,
                                Measure         = food.Measure,
                                MeasurementUnit = food.MeasurementUnit
                            });
                        }
                    }

                    var tripInProgress = new TripsInProgress();

                    tripInProgress.CampingTrip = campingtrip;

                    this.TripsInProgress.Add(tripInProgress);
                }
            }
        }
コード例 #4
0
        public void GetAllInProgressTrips()
        {
            var tokenResponse = tokenClient.RequestRefreshTokenAsync(ConfigurationManager.AppSettings["refreshToken"]).Result;

            httpClient.SetBearerToken(tokenResponse.AccessToken);
            var response = httpClient.GetAsync("api/CampingTrips").Result;

            var content = response.Content;

            var jsonContent = content.ReadAsStringAsync().Result;

            var trips = JsonConvert.DeserializeObject <List <CampingTrip> >(jsonContent);

            var campingTrips = new ObservableCollection <TripsInProgress>();

            if (trips != null)
            {
                foreach (var trip in trips)
                {
                    var zeroTime = new DateTime(1, 1, 1);

                    var span = DateTime.Now - this.user.DateOfBirth;

                    var userAge = (zeroTime + span).Year - 1;

                    if (userAge >= trip.MinAge && userAge <= trip.MaxAge)
                    {
                        var campingtrip = new CampingTripInfo()
                        {
                            Place             = trip.Place,
                            DepartureDate     = trip.DepartureDate,
                            ArrivalDate       = trip.ArrivalDate,
                            CountOfMembers    = trip.CountOfMembers,
                            MinAge            = trip.MinAge,
                            MaxAge            = trip.MaxAge,
                            MinCountOfMembers = trip.MinCountOfMembers,
                            MaxCountOfMembers = trip.MaxCountOfMembers,
                            Direction         = trip.Direction,
                            HasGuide          = trip.HasGuide,
                            HasPhotographer   = trip.HasPhotographer,
                            PriceOfTrip       = trip.PriceOfTrip,
                            ID = trip.ID
                        };
                        if (trip.TypeOfTrip == Kanch.DataModel.TypeOfCampingTrip.Campaign)
                        {
                            campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.Campaign;
                        }
                        else if (trip.TypeOfTrip == Kanch.DataModel.TypeOfCampingTrip.CampingTrip)
                        {
                            campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.CampingTrip;
                        }
                        else
                        {
                            campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.Excursion;
                        }
                        if (trip.Food != null)
                        {
                            campingtrip.Food = new ObservableCollection <FoodInfo>();
                            foreach (var food in trip.Food)
                            {
                                campingtrip.Food.Add(new FoodInfo()
                                {
                                    Name            = food.Name,
                                    Measure         = food.Measure,
                                    MeasurementUnit = food.MeasurementUnit
                                });
                            }
                        }

                        campingtrip.MembersOfCampingTrip = new ObservableCollection <UserInfo>();

                        if (trip.MembersOfCampingTrip != null)
                        {
                            foreach (var member in trip.MembersOfCampingTrip)
                            {
                                if (member.Id == this.user.Id)
                                {
                                    campingtrip.IAmJoined = true;
                                }
                                campingtrip.MembersOfCampingTrip.Add(new UserInfo
                                {
                                    Id = member.Id
                                });
                            }
                        }

                        if (trip.CountOfMembers >= trip.MaxCountOfMembers)
                        {
                            campingtrip.CanIJoin = false;
                        }


                        if (!campingtrip.IAmJoined)
                        {
                            campingtrip.CanIJoin = true;
                        }

                        var tripInProgress = new TripsInProgress();

                        tripInProgress.CampingTrip   = campingtrip;
                        tripInProgress.JoinCommand   = new Command(Join);
                        tripInProgress.RefuseCommand = new Command(Refuse);

                        this.TripsInProgress.Add(tripInProgress);
                    }
                }
            }
        }
コード例 #5
0
        private CampingTripInfo GetTrip(string campingTripId, string refreshToken)
        {
            var tokenResponse = tokenClient.RequestRefreshTokenAsync(refreshToken).Result;

            httpClient.SetBearerToken(tokenResponse.AccessToken);

            var response = httpClient.GetAsync($"api/CampingTrips/{campingTripId}").Result;

            var tripJson = response.Content.ReadAsStringAsync().Result;

            var trip = JsonConvert.DeserializeObject <CampingTrip>(tripJson);

            var tripInfo = new CampingTripInfo()
            {
                ID                = trip.ID,
                Place             = trip.Place,
                ArrivalDate       = trip.ArrivalDate,
                DepartureDate     = trip.DepartureDate,
                Direction         = trip.Direction,
                CountOfMembers    = trip.CountOfMembers,
                MinAge            = trip.MinAge,
                MaxAge            = trip.MaxAge,
                MinCountOfMembers = trip.MinCountOfMembers,
                MaxCountOfMembers = trip.MaxCountOfMembers,
                HasGuide          = trip.HasGuide,
                HasPhotographer   = trip.HasPhotographer,
                PriceOfTrip       = trip.PriceOfTrip
            };

            if (trip.OrganizationType == Kanch.DataModel.TypeOfOrganization.OrderByAdmin)
            {
                tripInfo.OrganizationType = DataModel.TypeOfOrganization.OrderByAdmin;
            }
            else
            {
                tripInfo.OrganizationType = DataModel.TypeOfOrganization.OrderByUser;
            }

            if (trip.TypeOfTrip == Kanch.DataModel.TypeOfCampingTrip.Campaign)
            {
                tripInfo.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.Campaign;
            }
            else if (trip.TypeOfTrip == Kanch.DataModel.TypeOfCampingTrip.CampingTrip)
            {
                tripInfo.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.CampingTrip;
            }
            else
            {
                tripInfo.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.Excursion;
            }
            if (trip.Food != null)
            {
                tripInfo.Food = new ObservableCollection <FoodInfo>();
                foreach (var food in trip.Food)
                {
                    tripInfo.Food.Add(new FoodInfo()
                    {
                        Name            = food.Name,
                        Measure         = food.Measure,
                        MeasurementUnit = food.MeasurementUnit
                    });
                }
            }

            tripInfo.Organizer = new UserInfo()
            {
                Id          = trip.Organizer.Id,
                FirstName   = trip.Organizer.FirstName,
                LastName    = trip.Organizer.LastName,
                UserName    = trip.Organizer.UserName,
                Email       = trip.Organizer.Email,
                PhoneNumber = trip.Organizer.PhoneNumber,
                DateOfBirth = trip.Organizer.DateOfBirth,
                Gender      = trip.Organizer.Gender,
                Image       = ImageConverter.ConvertImageToImageSource(trip.Organizer.Image) ?? ImageConverter.DefaultProfilePicture(trip.Organizer.Gender)
            };


            if (trip.Driver != null)
            {
                tripInfo.Driver = new DriverInfo
                {
                    Id          = trip.Driver.Id,
                    FirstName   = trip.Driver.FirstName,
                    LastName    = trip.Driver.LastName,
                    Email       = trip.Driver.Email,
                    Gender      = trip.Driver.Gender,
                    PhoneNumber = trip.Driver.PhoneNumber,
                    Image       = ImageConverter.ConvertImageToImageSource(trip.Driver.Image) ?? ImageConverter.DefaultProfilePicture(trip.Driver.Gender),
                    DateOfBirth = trip.Driver.DateOfBirth
                };
            }

            if (trip.Guide != null)
            {
                tripInfo.Guide = new GuideInfo
                {
                    Id          = trip.Guide.Id,
                    FirstName   = trip.Guide.FirstName,
                    LastName    = trip.Guide.LastName,
                    Email       = trip.Guide.Email,
                    Gender      = trip.Guide.Gender,
                    PhoneNumber = trip.Guide.PhoneNumber,
                    Image       = ImageConverter.ConvertImageToImageSource(trip.Guide.Image) ?? ImageConverter.DefaultProfilePicture(trip.Guide.Gender),
                    DateOfBirth = trip.Guide.DateOfBirth
                };
            }

            if (trip.Photographer != null)
            {
                tripInfo.Photographer = new PhotographerInfo
                {
                    Id          = trip.Photographer.Id,
                    FirstName   = trip.Photographer.FirstName,
                    LastName    = trip.Photographer.LastName,
                    Email       = trip.Photographer.Email,
                    Gender      = trip.Photographer.Gender,
                    PhoneNumber = trip.Photographer.PhoneNumber,
                    Image       = ImageConverter.ConvertImageToImageSource(trip.Photographer.Image) ?? ImageConverter.DefaultProfilePicture(trip.Photographer.Gender),
                    DateOfBirth = trip.Photographer.DateOfBirth
                };
            }

            return(tripInfo);
        }
コード例 #6
0
        private CampingTrip TripConverter(CampingTripInfo campingTrip)
        {
            var trip = new CampingTrip()
            {
                ID                = campingTrip.ID,
                Place             = campingTrip.Place,
                DepartureDate     = campingTrip.DepartureDate,
                ArrivalDate       = campingTrip.ArrivalDate,
                MinAge            = campingTrip.MinAge,
                MaxAge            = campingTrip.MaxAge,
                MaxCountOfMembers = campingTrip.MaxCountOfMembers,
                MinCountOfMembers = campingTrip.MinCountOfMembers,
                HasGuide          = campingTrip.HasGuide,
                HasPhotographer   = campingTrip.HasPhotographer,
                OrganizationType  = Kanch.DataModel.TypeOfOrganization.OrderByAdmin,
                Organizer         = new User()
                {
                    Id = campingTrip.Organizer.Id
                },
                PriceOfTrip             = campingTrip.PriceOfTrip,
                CountOfMembers          = campingTrip.CountOfMembers,
                Direction               = campingTrip.Direction,
                IsRegistrationCompleted = campingTrip.IsRegistrationCompleted,
            };

            if (campingTrip.TypeOfTrip == ProfileComponents.DataModel.TypeOfCampingTrip.Campaign)
            {
                trip.TypeOfTrip = Kanch.DataModel.TypeOfCampingTrip.Campaign;
            }
            else if (campingTrip.TypeOfTrip == ProfileComponents.DataModel.TypeOfCampingTrip.CampingTrip)
            {
                trip.TypeOfTrip = Kanch.DataModel.TypeOfCampingTrip.CampingTrip;
            }
            else
            {
                trip.TypeOfTrip = Kanch.DataModel.TypeOfCampingTrip.Excursion;
            }

            if (campingTrip.Driver != null)
            {
                trip.Driver = new Driver {
                    Id = campingTrip.Driver.Id
                };
            }

            if (campingTrip.Guide != null)
            {
                trip.Guide = new Guide {
                    Id = campingTrip.Guide.Id
                };
            }

            if (campingTrip.Photographer != null)
            {
                trip.Photographer = new Photographer {
                    Id = campingTrip.Photographer.Id
                };
            }

            trip.MembersOfCampingTrip = new List <User>();

            if (campingTrip.MembersOfCampingTrip != null)
            {
                foreach (var member in campingTrip.MembersOfCampingTrip)
                {
                    trip.MembersOfCampingTrip.Add(new User
                    {
                        Id = member.Id
                    });
                }
            }

            if (campingTrip.Food != null)
            {
                trip.Food = new List <Food>();

                foreach (var food in campingTrip.Food)
                {
                    trip.Food.Add(new Food()
                    {
                        Name            = food.Name,
                        Measure         = food.Measure,
                        MeasurementUnit = food.MeasurementUnit
                    });
                }
            }
            return(trip);
        }
コード例 #7
0
        public void GetAllUnconfirmedTrips()
        {
            var tokenResponse = tokenClient.RequestRefreshTokenAsync(ConfigurationManager.AppSettings["refreshToken"]).Result;

            httpClient.SetBearerToken(tokenResponse.AccessToken);
            var response = httpClient.GetAsync("api/UserRegisteredTripsManagement").Result;

            var content = response.Content;

            var jsonContent = content.ReadAsStringAsync().Result;

            var trips = JsonConvert.DeserializeObject <List <CampingTrip> >(jsonContent);

            var campingTrips = new ObservableCollection <UnconfirmedTrips>();

            if (trips != null)
            {
                foreach (var trip in trips)
                {
                    var campingtrip = new CampingTripInfo()
                    {
                        ID              = trip.ID,
                        Place           = trip.Place,
                        DepartureDate   = trip.DepartureDate,
                        ArrivalDate     = trip.ArrivalDate,
                        CountOfMembers  = trip.CountOfMembers,
                        MinAge          = trip.MinAge,
                        MaxAge          = trip.MaxAge,
                        Direction       = trip.Direction,
                        HasGuide        = trip.HasGuide,
                        HasPhotographer = trip.HasPhotographer
                    };
                    if (trip.TypeOfTrip == Kanch.DataModel.TypeOfCampingTrip.Campaign)
                    {
                        campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.Campaign;
                    }
                    else if (trip.TypeOfTrip == Kanch.DataModel.TypeOfCampingTrip.CampingTrip)
                    {
                        campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.CampingTrip;
                    }
                    else
                    {
                        campingtrip.TypeOfTrip = ProfileComponents.DataModel.TypeOfCampingTrip.Excursion;
                    }
                    if (trip.Food != null)
                    {
                        campingtrip.Food = new ObservableCollection <FoodInfo>();
                        foreach (var food in trip.Food)
                        {
                            campingtrip.Food.Add(new FoodInfo()
                            {
                                Name            = food.Name,
                                Measure         = food.Measure,
                                MeasurementUnit = food.MeasurementUnit
                            });
                        }
                    }
                    campingtrip.Organizer = new UserInfo()
                    {
                        FirstName   = trip.Organizer.FirstName,
                        LastName    = trip.Organizer.LastName,
                        UserName    = trip.Organizer.UserName,
                        Email       = trip.Organizer.Email,
                        PhoneNumber = trip.Organizer.PhoneNumber,
                        DateOfBirth = trip.Organizer.DateOfBirth,
                        Gender      = trip.Organizer.Gender,
                        Image       = ImageConverter.ConvertImageToImageSource(trip.Organizer.Image) ?? ImageConverter.DefaultProfilePicture(trip.Organizer.Gender)
                    };


                    var unconfirmTrip = new HelperClasses.UnconfirmedTrips();

                    unconfirmTrip.CampingTrip    = campingtrip;
                    unconfirmTrip.Trip           = trip;
                    unconfirmTrip.ConfirmCommand = new Command(Confirm);
                    unconfirmTrip.IgnoreCommand  = new Command(Ignore);

                    this.UnconfirmedTrips.Add(unconfirmTrip);
                }
            }
        }