Ejemplo n.º 1
0
        /// <summary>
        /// This method wil return JSON and in case further operations are desired on result set it can be perfomrmed in this method before returning result
        /// </summary>
        /// <param name="requestHotel"></param>
        /// <returns></returns>
        public ResponseHotel SearchResultXML(RequestHotel requestHotel)
        {
            // in case in future further operations need to be performed on XML data
            // Result should be sent with proper details in case of failures either error or validations
            ResponseHotel responseSearch = new ResponseHotel();

            try
            {
                // in case in future further operations need to be performed on XML data
                responseSearch.Hotels = Search(requestHotel);

                // if all operations are perfomred well return success code
                responseSearch.Code = Constants.CONST_RESULT_CODE_SUCCESS;
            }
            catch (CustomException ex)
            {
                responseSearch.Messages = ex.Messages;

                // General failure code to inform client that request went unsuccessful
                responseSearch.Code = Constants.CONST_RESULT_CODE_FAILURE;
            }
            catch
            {
                responseSearch.Messages = new List <CustomMessage> {
                    new CustomMessage {
                        Code = Constants.CONST_EXCEPTION_INTERNAL_ERROR, Message = Constants.CONST_EXCEPTION_INTERNAL_ERROR_DESCRIPTION
                    }
                };

                // General failure code to inform client that request went unsuccessful
                responseSearch.Code = Constants.CONST_RESULT_CODE_FAILURE;
            }

            return(responseSearch);
        }
Ejemplo n.º 2
0
 public ResponseHotel GetHotelOffer(RequestHotel request)
 {
     using (var httpClient = new HttpClient()) {
         var response      = httpClient.GetStringAsync(new Uri(baseUrl)).Result;
         var responseHotel = JsonConvert.DeserializeObject <ResponseHotel>(response);
         return(responseHotel);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Transforming get parameters into object model to keep it in unified state to be later used by search method
        /// </summary>
        /// <param name="hotelName"></param>
        /// <param name="destination"></param>
        /// <param name="rangeFrom"></param>
        /// <param name="rangeTo"></param>
        /// <param name="dateFrom"></param>
        /// <param name="dateTo"></param>
        /// <param name="sortByName"></param>
        /// <param name="sortByPrice"></param>
        /// <returns></returns>
        private RequestHotel TransformGetValuestoRequestModel(String hotelName, String destination, String rangeFrom, String rangeTo, String dateFrom, String dateTo, String sortByName, String sortByPrice)
        {
            RequestHotel requestHotel;

            try
            {
                requestHotel = new RequestHotel
                {
                    HotelName = String.IsNullOrEmpty(hotelName) ? null :  Convert.ToString(hotelName).Trim()
                    ,
                    Destination = String.IsNullOrEmpty(destination) ? null : Convert.ToString(destination).Trim()
                    ,
                    RangeFrom = String.IsNullOrEmpty(rangeFrom) ? (Double?)null : Math.Round(Convert.ToDouble(rangeFrom), 2)
                    ,
                    RangeTo = String.IsNullOrEmpty(rangeTo) ? (Double?)null : Math.Round(Convert.ToDouble(rangeTo), 2)
                    ,
                    DateFrom = String.IsNullOrEmpty(dateFrom) ? (DateTime?)null : DateTime.ParseExact(dateFrom, "dd-MM-yyyy", CultureInfo.InvariantCulture)
                    ,
                    DateTo = String.IsNullOrEmpty(dateTo) ? (DateTime?)null : DateTime.ParseExact(dateTo, "dd-MM-yyyy", CultureInfo.InvariantCulture)
                    ,
                    SortByName = String.IsNullOrEmpty(sortByName) ? null : Convert.ToString(sortByName).Trim()
                    ,
                    SortByPrice = String.IsNullOrEmpty(sortByPrice) ? null : Convert.ToString(sortByPrice).Trim()
                };
            }
            catch (CustomException ex)
            {
                // only add message if it is crashed as of casting issue
                if (ex.Messages.IsNull())
                {
                    ex.Messages = new List <CustomMessage>();
                    ex.Messages.Add(new CustomMessage {
                        Code      = Constants.CONST_EXCEPTION_SEARCH_PARAMETERS_ERROR
                        , Message = Constants.CONST_EXCEPTION_SEARCH_PARAMETERS_ERROR_DESCRIPTION
                    });
                }

                throw ex;
            }
            catch (Exception ex)
            {
                CustomException cEx = new CustomException(new List <CustomMessage> {
                    new CustomMessage {
                        Code = Constants.CONST_EXCEPTION_SEARCH_PARAMETERS_ERROR, Message = Constants.CONST_EXCEPTION_SEARCH_PARAMETERS_ERROR_DESCRIPTION
                    }
                }
                                                          , ex.Message
                                                          , ex.InnerException);

                throw cEx;
            }

            return(requestHotel);
        }
Ejemplo n.º 4
0
        public async Task <AvailableHotels> AvailableHotels(RequestHotel request)
        {
            var FullUrl  = BullidUrl(request);
            var client   = new HttpClient();
            var response = await client.GetAsync(FullUrl);

            var content = response.Content;
            var result  = await content.ReadAsStringAsync();

            var responseHotel = JsonConvert.DeserializeObject <AvailableHotels>(result);

            return(responseHotel);
        }
Ejemplo n.º 5
0
        private string BuildRestRequestParam(RequestHotel request)
        {
            var requestUrl = new StringBuilder(baseUrl);

            if (!String.IsNullOrWhiteSpace(request.DestinationName))
            {
                requestUrl.Append("&destinationName=" + request.DestinationName);
            }
            if (!String.IsNullOrWhiteSpace(request.DestinationCity))
            {
                requestUrl.Append("&destinationCity=" + request.DestinationCity);
            }
            if (!String.IsNullOrWhiteSpace(request.MinTripStartDate))
            {
                requestUrl.Append("&minTripStartDate=" + request.MinTripStartDate);
            }
            if (!String.IsNullOrWhiteSpace(request.MaxTripStartDate))
            {
                requestUrl.Append("&maxTripStartDate=" + request.MaxTripStartDate);
            }
            if (!String.IsNullOrWhiteSpace(request.LengthOfStay))
            {
                requestUrl.Append("&lengthOfStay=" + request.LengthOfStay);
            }
            if (!String.IsNullOrWhiteSpace(request.MaxStarRating))
            {
                requestUrl.Append("&maxStarRating=" + request.MaxStarRating);
            }
            if (!String.IsNullOrWhiteSpace(request.MinStarRating))
            {
                requestUrl.Append("&minStarRating=" + request.MinStarRating);
            }
            if (!String.IsNullOrWhiteSpace(request.MaxTotalRate))
            {
                requestUrl.Append("&maxTotalRate=" + request.MaxTotalRate);
            }
            if (!String.IsNullOrWhiteSpace(request.MinTotalRate))
            {
                requestUrl.Append("&minTotalRate=" + request.MinTotalRate);
            }
            if (!String.IsNullOrWhiteSpace(request.MaxGuestRating))
            {
                requestUrl.Append("&maxGuestRating=" + request.MaxGuestRating);
            }
            if (!String.IsNullOrWhiteSpace(request.MinGuestRating))
            {
                requestUrl.Append("&minGuestRating=" + request.MinGuestRating);
            }

            return(requestUrl.ToString());
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hotelName"></param>
        /// <param name="destination"></param>
        /// <param name="rangeFrom"></param>
        /// <param name="rangeTo"></param>
        /// <param name="dateFrom"></param>
        /// <param name="dateTo"></param>
        /// <param name="sortByName"></param>
        /// <param name="sortByPrice"></param>
        /// <returns></returns>
        public ResponseHotel SearchResultXML_Get(String hotelName, String destination, String rangeFrom, String rangeTo, String dateFrom, String dateTo, String sortByName, String sortByPrice)
        {
            // in case in future further operations need to be performed on XML data
            // Result should be sent with proper details in case of failures either error or validations
            ResponseHotel responseSearch = new ResponseHotel();
            HotelBAL      hotelBAL       = new HotelBAL();

            try
            {
                // first check that vaid values are sent in paramater for get request
                if (hotelBAL.AreParameterTypesValidForSearch(rangeFrom, rangeTo, dateFrom, dateTo))
                {
                    RequestHotel requestHotel = TransformGetValuestoRequestModel(hotelName, destination, rangeFrom, rangeTo, dateFrom, dateTo, sortByName, sortByPrice);

                    // in case in future further operations need to be performed on XML data
                    responseSearch.Hotels = Search(requestHotel);

                    // if all operations are perfomred well return success code
                    responseSearch.Code = Constants.CONST_RESULT_CODE_SUCCESS;
                }
            }
            catch (CustomException ex)
            {
                responseSearch.Messages = ex.Messages;

                // General failure code to inform client that request went unsuccessful
                responseSearch.Code = Constants.CONST_RESULT_CODE_FAILURE;
            }
            catch
            {
                responseSearch.Messages = new List <CustomMessage> {
                    new CustomMessage {
                        Code = Constants.CONST_EXCEPTION_INTERNAL_ERROR, Message = Constants.CONST_EXCEPTION_INTERNAL_ERROR_DESCRIPTION
                    }
                };

                // General failure code to inform client that request went unsuccessful
                responseSearch.Code = Constants.CONST_RESULT_CODE_FAILURE;
            }

            return(responseSearch);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// unified method to perform all search opearations for hotels without any difference of calling method
        /// </summary>
        /// <param name="requestHotel"></param>
        /// <returns></returns>
        private List <Hotel> Search(RequestHotel requestHotel)
        {
            HotelBAL hotelBAL = new HotelBAL();

            try
            {
                // calling business layer methos to perform all operations and just return result for hotels
                return(hotelBAL.SearchHotels(requestHotel));
            }
            catch (CustomException ex)
            {
                // in case some exception appears which was not defined and method crashed
                // all nested methods are defined with exception which specifically will populate message based on error with in internal system
                // but in case any failure happens which was not handled or it is external issue then general message will be assigned with failure
                if (ex.Messages.IsNullOrEmpty())
                {
                    ex.Messages = new List <CustomMessage>();
                    ex.Messages.Add(new CustomMessage {
                        Code = Constants.CONST_EXCEPTION_INTERNAL_ERROR, Message = Constants.CONST_EXCEPTION_INTERNAL_ERROR_DESCRIPTION
                    });
                }

                throw ex;
            }
            catch (Exception ex)
            {
                CustomException cEx = new CustomException(new List <CustomMessage> {
                    new CustomMessage {
                        Code = Constants.CONST_EXCEPTION_INTERNAL_ERROR, Message = Constants.CONST_EXCEPTION_INTERNAL_ERROR_DESCRIPTION
                    }
                }
                                                          , ex.Message
                                                          , ex.InnerException);

                throw cEx;
            }
        }
Ejemplo n.º 8
0
        public IActionResult ViewResult(RequestHotel request)
        {
            var availableHotels = _service.AvailableHotels(request).Result;

            return(View(availableHotels));
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestHotel"></param>
        /// <returns></returns>
        public List <Hotel> SearchHotels(RequestHotel requestHotel)
        {
            Utility      utility  = null;
            List <Hotel> lstHotel = null;

            try
            {
                // first of all validate data for search parameters
                if (IsDataValidForSearch(requestHotel.RangeFrom, requestHotel.RangeTo, requestHotel.DateFrom, requestHotel.DateTo
                                         , requestHotel.SortByName, requestHotel.SortByPrice))
                {
                    // parsing json into list
                    utility  = new Utility();
                    lstHotel = utility.CallHotelsAPI();

                    // first check that it must contains some values
                    if (!lstHotel.IsNullOrEmpty())
                    {
                        lstHotel = Search(lstHotel.AsQueryable()
                                          , String.IsNullOrEmpty(requestHotel.HotelName) ? requestHotel.HotelName : requestHotel.HotelName
                                          , String.IsNullOrEmpty(requestHotel.Destination) ? requestHotel.Destination : requestHotel.Destination
                                          , (requestHotel.RangeFrom.HasValue && requestHotel.RangeFrom.Value > 0) ? requestHotel.RangeFrom : null
                                          , (requestHotel.RangeTo.HasValue && requestHotel.RangeTo.Value > 0) ? requestHotel.RangeTo : null
                                          , requestHotel.DateFrom
                                          , requestHotel.DateTo
                                          , String.IsNullOrEmpty(requestHotel.SortByName) ? requestHotel.SortByName : requestHotel.SortByName
                                          , String.IsNullOrEmpty(requestHotel.SortByPrice) ? requestHotel.SortByPrice : requestHotel.SortByPrice);


                        // in case it is not desired to remove irrelavant date entries from availability collection then comment below code and return list from above
                        // simply pass date ranges and irrelevant entries will be removed
                        RemoveIrrelevantDataFromAvailability(lstHotel, requestHotel.DateFrom, requestHotel.DateTo);
                    }
                    else
                    {
                        CustomException ex = new CustomException {
                            Messages = new List <CustomMessage>()
                        };
                        ex.Messages.Add(new CustomMessage
                        {
                            Code = Constants.CONST_API_DO_NOT_CONTAIN_OFFERS
                            ,
                            Message = Constants.CONST_API_DO_NOT_CONTAIN_OFFERS_DESCRIPTION
                        });

                        throw ex;
                    }
                }
            }
            catch (CustomException ex)
            {
                // only add message if it is crashed as of query disorder
                if (ex.Messages.IsNull())
                {
                    ex.Messages = new List <CustomMessage>();
                    ex.Messages.Add(new CustomMessage {
                        Code = Constants.CONST_EXCEPTION_QUERY_ERROR, Message = Constants.CONST_EXCEPTION_QUERY_ERROR_DESCRIPTION
                    });
                }
                throw ex;
            }
            catch (Exception ex)
            {
                CustomException cEx = new CustomException(new List <CustomMessage> {
                    new CustomMessage {
                        Code = Constants.CONST_EXCEPTION_QUERY_ERROR, Message = Constants.CONST_EXCEPTION_QUERY_ERROR_DESCRIPTION
                    }
                }
                                                          , ex.Message
                                                          , ex.InnerException);

                throw cEx;
            }

            return(lstHotel.ToList());
        }
Ejemplo n.º 10
0
        string BullidUrl(RequestHotel request)
        {
            string fuLlUrl = Url;

            if (!string.IsNullOrEmpty(request.DestinationCity))
            {
                fuLlUrl += "&DestinationCity=" + request.DestinationCity;
            }

            if (!string.IsNullOrEmpty(request.DestinationName))
            {
                fuLlUrl += "&DestinationName=" + request.DestinationName;
            }

            if (!string.IsNullOrEmpty(request.LengthOfStay))
            {
                fuLlUrl += "&LengthOfStay=" + request.LengthOfStay;
            }

            if (!string.IsNullOrEmpty(request.MaxGuestRating))
            {
                fuLlUrl += "&MaxGuestRating=" + request.MaxGuestRating;
            }

            if (!string.IsNullOrEmpty(request.MaxStarRating))
            {
                fuLlUrl += "&MaxStarRating=" + request.MaxStarRating;
            }

            if (!string.IsNullOrEmpty(request.MaxTotalRate))
            {
                fuLlUrl += "&MaxTotalRate=" + request.MaxTotalRate;
            }

            if (!string.IsNullOrEmpty(request.MaxTripStartDate))
            {
                fuLlUrl += "&MaxTotalRate=" + request.MaxTripStartDate;
            }

            if (!string.IsNullOrEmpty(request.MinGuestRating))
            {
                fuLlUrl += "&MinGuestRating=" + request.MinGuestRating;
            }

            if (!string.IsNullOrEmpty(request.MinStarRating))
            {
                fuLlUrl += "&MinStarRating=" + request.MinStarRating;
            }

            if (!string.IsNullOrEmpty(request.MinTotalRate))
            {
                fuLlUrl += "&MinTotalRate=" + request.MinTotalRate;
            }

            if (!string.IsNullOrEmpty(request.MinTripStartDate))
            {
                fuLlUrl += "&MinTripStartDate=" + request.MinTripStartDate;
            }

            return(fuLlUrl);
        }