예제 #1
0
        private async void BtnSumbit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtBox_HotelName.Text) || string.IsNullOrEmpty(txtBox_Address.Text))
            {
                MessageBox.Show("Fields can't e empty", "OK");
                return;
            }
            var result = await(new APIService("city").GetById <CityDTO>((int)cmbBox_CityName.SelectedValue));

            if (result == null)
            {
                return;
            }

            var request = new HotelInsertRequest
            {
                CityId       = result.Id,
                HotelName    = txtBox_HotelName.Text,
                HotelAddress = txtBox_Address.Text
            };

            using (var ms = new MemoryStream())
            {
                hotelPicture.Image.Save(ms, hotelPicture.Image.RawFormat);
                request.Picture = ms.ToArray();
            }


            HotelDTO res = null;

            if (!_id.HasValue)
            {
                res = await _service.Insert <HotelDTO>(request);
            }
            else
            {
                res = await _service.Update <HotelDTO>(_id, request);
            }
            string message = (res != null)?"Successsufully added new hotel":"Error: can't add new hotel";

            MessageBox.Show(message);
        }
예제 #2
0
        private async Task MakeRating(object dynamicObject)
        {
            try
            {
                RatingRequestModel myRequest = (RatingRequestModel)dynamicObject;

                int userID    = (await _userService.Get <List <UserDTO> >(new UserSearchRequest {
                    UserName = APIService.Username
                })).FirstOrDefault(_ => _.UserName == APIService.Username).Id;
                var newRating = new RatingInsertRequest
                {
                    HotelRating     = myRequest.HotelRating,
                    TransportRating = myRequest.TransportRating,
                    RatingDate      = DateTime.Now,
                    ReservationId   = myRequest.ReservationId,
                    UserId          = userID
                };
                var reservation = await _reservationService.GetById <ReservationDTO>(myRequest.ReservationId);

                if (reservation.StartTripDate != default(DateTime))
                {
                    if (reservation.StartTripDate > DateTime.Now)
                    {
                        await Application.Current.MainPage.DisplayAlert("Info", "Trip has not happend yet", "OK");

                        return;
                    }
                }


                var tOffer = await _tOfferService.GetById <TransportOfferDTO>(reservation.TransportOfferId);

                var hOffer = await _hOfferService.GetById <HotelOfferDTO>(reservation.HotelOfferId);

                var hotel = await _hotelService.GetById <HotelDTO>(hOffer.HotelId);

                var tCompany = await _tCompanyService.GetById <TransportCompanyDTO>(tOffer.TransportCompanyId);

                bool sameRatings = (await _ratingService.Get <List <RatingDTO> >(new RatingSearchRequest {
                })).Any(_ => _.HotelId == hotel.Id && tCompany.Id == _.TransportCompanyId &&
                        _.UserId == userID);
                if (sameRatings)
                {
                    await Application.Current.MainPage.DisplayAlert("Info", "You can't rate same reservation again", "OK");

                    return;
                }

                newRating.TransportCompanyId = tCompany.Id;
                newRating.HotelId            = hotel.Id;


                var res = await _ratingService.Insert <RatingDTO>(newRating);

                if (res != null)
                {
                    var allHotelOffers = await _hOfferService.Get <List <HotelOfferDTO> >(new HotelOfferSearchRequest { HotelId = hotel.Id });

                    var allTransportOffers = await _tCompanyService.Get <List <TransportOfferDTO> >(new TransportOfferSearchRequest { TransportCompanyId = tCompany.Id });

                    float averageHotelRating     = (float)(await _ratingService.Get <List <RatingDTO> >(new RatingSearchRequest {
                        HotelId = hotel.Id
                    })).Average(_ => _.HotelRating);
                    float averageTransportRating = (float)(await _ratingService.Get <List <RatingDTO> >(new RatingSearchRequest {
                        TransportCompanyId = tCompany.Id
                    })).Average(_ => _.TransportRating);

                    var hotelUpdateRequest = new HotelInsertRequest
                    {
                        HotelAddress = hotel.HotelAddress,
                        HotelName    = hotel.HotelName,
                        CityId       = hotel.CityId,
                        TotalVisits  = hotel.TotalVisits,
                        Rating       = averageHotelRating,
                        Picture      = hotel.Picture
                    };
                    var transportUpdateRequest = new TransportCompanyInsertRequest
                    {
                        TransportCompanyName = tCompany.TransportCompanyName,
                        IsActive             = tCompany.IsActive,
                        Picture         = tCompany.Picture,
                        TransportTypeId = tCompany.TransportTypeId
                    };
                    var hotelResult = await _hotelService.Update <HotelDTO>(hotel.Id, hotelUpdateRequest);

                    var transportResult = await _tCompanyService.Update <TransportCompanyDTO>(tCompany.Id, transportUpdateRequest);

                    if (hotelResult != null && transportResult != null)
                    {
                        await Application.Current.MainPage.DisplayAlert("INFO", "Successufully added Rating!", "OK");
                    }
                    else
                    {
                        await Application.Current.MainPage.DisplayAlert("INFO", "Error adding Rating!", "OK");
                    }
                }
            }
            catch (Exception)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Make sure that all inputs are correct", "OK");
            }
        }
예제 #3
0
        private async Task <ReservationDTO> MakeReservation(object context)
        {
            var reservationModel = (ReservationDetailViewModel)context;
            //var rooms = reservationModel.Rooms;
            //var roomtypes = rooms.Where(_ => _.OrderedRooms != 0).ToList();
            //float totalPrice,roomPrice = 0;
            //if (roomtypes.Count != 0)
            //{
            //    foreach (var room in roomtypes)
            //    {
            //        NumberOfPersons += (room.OrderedRooms * room.NumberOfPeople);
            //        roomPrice += (room.Price * room.OrderedRooms);
            //    }
            //}
            //totalPrice = roomPrice + reservationModel.TransportOffer.tOffer.Price;


            var user = (await _userService.Get <List <UserDTO> >(new UserSearchRequest {
                UserName = APIService.Username
            }))
                       .FirstOrDefault(_ => _.UserName == APIService.Username);
            ReservationInsertRequest request = new ReservationInsertRequest()
            {
                UserId           = user.Id,
                HotelOfferId     = reservationModel.HotelOffer.hOffer.Id,
                TransportOfferId = reservationModel.TransportOffer.tOffer.Id,
                NumberOfPersons  = NumberOfPersons,
                TotalPrice       = TotalPrice,
                DateReserved     = DateTime.Now,
                NumberOfDays     = reservationModel.NumberOfDays
            };
            var result = await _reservationService.Insert <ReservationDTO>(request);

            if (result != null)
            {
                var hotel = await _hotelService.GetById <HotelDTO>(reservationModel.HotelOffer.hOffer.HotelId);

                var transport = await _tCompanyService.GetById <TransportCompanyDTO>(reservationModel.TransportOffer.tOffer.TransportCompanyId);

                hotel.TotalVisits           += request.NumberOfPersons;
                transport.TotalReservations += request.NumberOfPersons;

                var hotelUpdate = new HotelInsertRequest()
                {
                    CityId       = hotel.CityId,
                    HotelAddress = hotel.HotelAddress,
                    HotelName    = hotel.HotelName,
                    TotalVisits  = hotel.TotalVisits
                };
                await _hotelService.Update <HotelDTO>(hotel.Id, hotelUpdate);

                var transportUpdate = new TransportCompanyInsertRequest
                {
                    TransportTypeId      = transport.TransportTypeId,
                    IsActive             = transport.IsActive,
                    Picture              = transport.Picture,
                    TransportCompanyName = transport.TransportCompanyName,
                    TotalReservations    = transport.TotalReservations
                };
                await _tCompanyService.Update <TransportCompanyDTO>(transport.Id, transportUpdate);

                await Application.Current.MainPage.DisplayAlert("Info", "Successufully added reservation", "Ok");
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("Info", "Error occured while adding reservation, please check your inputs", "Ok");
            }

            return(result);
        }