Exemple #1
0
        // GET: Requests/Create //id is roomid likibu
        public async Task <ActionResult> Create(string id, string thumb, string Location)
        {
            try
            {
                //load Offer from Likibu SearchSession
                if (User != null)
                {
                    TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                    TravelerProfileSearchSession searchsession = tp.SearchSession; ///searchsession comes here fom view? any has to be saved in loaded TravelerProfile
                    tp = await ProfilesController.LoadProfile(tp.ID);

                    tp.SearchSession = searchsession;
                    Models.Accommodation.Likibu.AccomodationDetailsParam para    = new Models.Accommodation.Likibu.AccomodationDetailsParam(tp.Attributes.Language, tp.Attributes.Currency, tp.SearchSession.CheckIn, tp.SearchSession.CheckOut);
                    Models.Accommodation.Likibu.AccomodationDetails      details = await Likibu.LikibuAccess.RequestAccomodationDetails(para, id);

                    Models.Request.RequestVMOwner requestVM = new Models.Request.RequestVMOwner(details.offer.Destination, details.offer.BedRooms, details.offer.PriceNight, details.offer.PriceWeek, details.offer.PriceMonth, details.offer.Lat, details.offer.Lng, tp.SearchSession.CheckIn, tp.SearchSession.CheckOut, id, tp.Attributes.Currency, thumb);

                    requestVM.Location = Location;
                    requestVM.Thumbs   = Models.Accommodation.Likibu.Offer.StringToArray(thumb).ToList();


                    return(View(requestVM));
                }
                return(View());
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!");
                return(View());
            }
        }
        public static Models.Accommodation.Likibu.AccomodationDetails ParseDetailsResult(string res)
        {
            Models.Accommodation.Likibu.AccomodationDetails details = new Models.Accommodation.Likibu.AccomodationDetails();
            details.offer = new Models.Accommodation.Likibu.Offer();
            JObject jo = JObject.Parse(res);

            details.offer.offerID  = jo["id"].ToString();
            details.offer.SourceID = jo["source"]["id"].ToString();

            details.offer.SourceName  = jo["source"]["name"].ToString();
            details.offer.SourceSlug  = jo["source"]["slug"].ToString();
            details.offer.GenTitle    = jo["generated_title"].ToString();
            details.offer.Title       = jo["title"].ToString();
            details.offer.Description = jo["description"].ToString();
            details.offer.Type        = jo["type"].ToString();
            details.offer.PrivacyType = jo["privacy_type"].ToString();

            details.offer.Photos = new List <string>();
            int count = jo["photos"].Count();

            for (int j = 0; j < count; j++)
            {
                details.offer.Photos.Add(jo["photos"][j].ToString());
            }

            ///Add Ammenities
            details.offer.Amenities  = jo["place"]["amenities"].ToString();
            details.offer.URL        = jo["url"].ToString();
            details.offer.PriceTotal = float.Parse(jo["price_sojourn"].ToString());
            details.offer.PriceNight = float.Parse(jo["price_nightly"].ToString());

            details.offer.PriceWeek  = float.Parse(jo["price_weekly"].ToString());
            details.offer.PriceMonth = float.Parse(jo["price_monthly"].ToString());
            details.offer.Currency   = jo["currency"].ToString();

            details.offer.Lat = float.Parse(jo["location"]["location"][1].ToString());
            details.offer.Lng = float.Parse(jo["location"]["location"][0].ToString());

            count = (jo["location"]["destination_id"].Count());
            string[] destIds = new string[count];
            for (int i = 0; i < count; i++)
            {
                destIds[i] = jo["location"]["destination_id"][i].ToString();
            }
            //details.offer.Destination = jo["location"]["destination"].ToString();
            details.offer.DestinationIDs = Models.Accommodation.Likibu.Offer.ArrayToString(destIds);
            details.offer.City           = jo["location"]["city"].ToString();
            details.offer.Country        = jo["location"]["country"].ToString();
            details.offer.AverageRating  = float.Parse(jo["rating"].ToString());
            details.offer.RatingCount    = int.Parse(jo["rating_count"].ToString());
            details.offer.MaxGuests      = int.Parse(jo["booking"]["max_guests"].ToString());
            details.offer.BedRooms       = int.Parse(jo["place"]["bedrooms"].ToString());
            //  details.offer.Rooms = jo["place"]["rooms"].ToString(); does not exist!
            details.offer.BathRooms           = int.Parse(jo["place"]["bathrooms"].ToString());
            details.offer.SurfaceSquareMeters = jo["place"]["surface"].ToString();
            details.offer.IsInstantBooking    = Boolean.Parse(jo["booking"]["is_instant_booking_available"].ToString());
            details.offer.MinNights           = int.Parse(jo["booking"]["min_nights"].ToString());
            details.offer.MaxNights           = int.Parse(jo["booking"]["max_nights"].ToString());
            return(details);
        }
Exemple #3
0
        private async Task <Models.Accommodation.Likibu.AccomodationDetails> GetAcomodationDetails(string lang, string cur, string chIn, string chOut, string roomID)
        {
            Models.Accommodation.Likibu.AccomodationDetailsParam reqParam = new Models.Accommodation.Likibu.AccomodationDetailsParam(lang, cur, chIn, chOut);
            Models.Accommodation.Likibu.AccomodationDetails      result   = await Likibu.LikibuAccess.RequestAccomodationDetails(reqParam, roomID);

            return(result);
        }
Exemple #4
0
        private async Task <Models.Accommodation.Likibu.AccomodationDetails> GetAcomodationDetails(Models.Find.SearchVM searchVM, string roomID)
        {
            Models.Accommodation.Likibu.AccomodationDetailsParam reqParam = new Models.Accommodation.Likibu.AccomodationDetailsParam(searchVM.Language, searchVM.Currency, searchVM.Search.CheckIn, searchVM.Search.CheckOut);
            Models.Accommodation.Likibu.AccomodationDetails      result   = await Likibu.LikibuAccess.RequestAccomodationDetails(reqParam, roomID);

            return(result);
        }
Exemple #5
0
        public async Task <ActionResult> Create([Bind(Exclude = "ID")] Models.Request.RequestVMOwner requestVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User);

                    Models.Accommodation.Likibu.AccomodationDetailsParam para    = new Models.Accommodation.Likibu.AccomodationDetailsParam(tp.Attributes.Language, tp.Attributes.Currency, requestVM.CheckIn.ToString(), requestVM.CheckOut.ToString());
                    Models.Accommodation.Likibu.AccomodationDetails      details = await Likibu.LikibuAccess.RequestAccomodationDetails(para, requestVM.AccomID);

                    ///
                    using (var db = new ApplicationDbContext())
                    {
                        requestVM.BedRooms    = details.offer.BedRooms;
                        requestVM.Lat         = details.offer.Lat;
                        requestVM.Lng         = details.offer.Lng;
                        requestVM.PricePNight = details.offer.PriceNight.ToString();
                        requestVM.PricePWeek  = details.offer.PriceWeek.ToString();
                        requestVM.PricepMonth = details.offer.PriceMonth.ToString();

                        details.offer.Destination = requestVM.Location;
                        details.offer.Thumbnails  = Models.Accommodation.Likibu.Offer.StringToArray(requestVM.ThumbsTemp).ToList();



                        Models.Request.Request rq = new Models.Request.Request(tp.ID, requestVM);

                        rq.Accommodation = new Models.Accommodation.Accommodation(details.offer.MaxGuests, details.offer.BedRooms); //AccommodationModel is generated here
                        if (!rq.Accommodation.Verified)
                        {
                            throw new Exception("Accommodation abstraction failed");
                        }
                        string currency = ProfilesController.Currency(tp.Attributes.Currency);
                        rq.Accommodation.AccomProfile = new Models.Accommodation.AccommodationProfile(details.offer, currency);

                        db.Requests.Add(rq);
                        await db.SaveChangesAsync();

                        NotificationManager.AddNotification(NotificationType.Success, "Your Request has been saved!");

                        return(RedirectToAction("Create", "RoomRequests", new { id = rq.ID }));
                    }
                }
                catch (Exception e)
                {
                    NotificationManager.AddException(e);
                    NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!");
                    return(RedirectToAction("Search", "Searches"));
                }
            }
            return(View(requestVM));
        }
        public static async Task <Models.Accommodation.Likibu.AccomodationDetails> RequestAccomodationDetails(Models.Accommodation.Likibu.AccomodationDetailsParam para, string roomID)
        {
            try
            {
                string webrq    = DetailsRqString + roomID + ApiKey;
                string rqString = webrq + para.Body;
                string retStr   = null;
                retStr = await webClient.DownloadStringTaskAsync(rqString);

                Models.Accommodation.Likibu.AccomodationDetails ADetails = ParseDetailsResult(retStr);
                return(ADetails);
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
                return(null);
            }
        }
Exemple #7
0
        public async Task <ActionResult> Details(string lang, string cur, string chIn, string chOut, string id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Models.Accommodation.Likibu.AccomodationDetails details = await GetAcomodationDetails(lang, cur, chIn, chOut, id);

                    return(View(details.offer));
                }
                return(View());
            }
            catch (Exception e)
            {
                NotificationManager.AddException(e);
            }
            return(PartialView());
        }