patterncsharpMinor
Calling 5 APIs to pick the cheapest hotel prices
Viewed 0 times
apisthecheapesthotelpricescallingpick
Problem
I am using 5 Hotels APIs and trying to combine and pick min price hotel with unique hotels from all APIs. I am following these STEPS
```
string sessionid = sqf;
DS.Models.BL.Common.HotelSearchDetails details = new DS.Models.BL.Common.HotelSearchDetails();
details = (.Models.BL.Common.HotelSearchDetails)Session["Details_" + sessionid];
List DOTWhdlist = new List();
List GTAhdlist = new List();
List HPhdlist = new List();
List HBhdlist = new List();
List TSGhdlist = new List();
//GTA City Cache
DS.Models.BL.GTA_Model.Methods.HotelInfo hinfo = new Models.BL.GTA_Model.Methods.HotelInfo();
List hlist = new List();
hlist = hinfo.GethotellistCityWise(details.GTACityCode);
//
/*****
* DOTW cache
*
*****/
DS.BL.DOTW.Method.HotelInfo objhoteldetails = new DS.BL.DOTW.Method.HotelInfo();
Dictionary dictionary = objhoteldetails.Gethotelratings();
List objhotellist = new List();
objhotellist = objhoteldetails.GethotellistCityWise(details.DOTWCityCode);
//-------------------------------------------------------------------------------------------------------
//------Hotel pro cache city
DS.BL.HotelsPro.Method.GetHotelDetails objhoteldetails_hp = new BL.HotelsPro.Method.GetHotelDetails();
List objhotellist_hp = new List();
objhotellist_hp = objhoteldetails_hp.GethotellistCityWise(details.HotelsProCityCode);
/*
* Hotelbeds city cache
*
*/
DS.Models.BL.HotelBeds.Methods.HotelInfoController objhotelbeds = new DS.Models.BL.HotelBeds.Methods.HotelInfoController();
- Call All 5 APIsand wait for response.
- get all static data from database or if avail my server caching(all 5 APIs like hotels name, images, desc, etc)
- Combine into one custom class
- get GIATA map codes from caching or database.
- Apply GIATA into API result and group all hotels with unique GIATA id.
- Pick min price .
- Bind UI and show to customer.
```
string sessionid = sqf;
DS.Models.BL.Common.HotelSearchDetails details = new DS.Models.BL.Common.HotelSearchDetails();
details = (.Models.BL.Common.HotelSearchDetails)Session["Details_" + sessionid];
List DOTWhdlist = new List();
List GTAhdlist = new List();
List HPhdlist = new List();
List HBhdlist = new List();
List TSGhdlist = new List();
//GTA City Cache
DS.Models.BL.GTA_Model.Methods.HotelInfo hinfo = new Models.BL.GTA_Model.Methods.HotelInfo();
List hlist = new List();
hlist = hinfo.GethotellistCityWise(details.GTACityCode);
//
/*****
* DOTW cache
*
*****/
DS.BL.DOTW.Method.HotelInfo objhoteldetails = new DS.BL.DOTW.Method.HotelInfo();
Dictionary dictionary = objhoteldetails.Gethotelratings();
List objhotellist = new List();
objhotellist = objhoteldetails.GethotellistCityWise(details.DOTWCityCode);
//-------------------------------------------------------------------------------------------------------
//------Hotel pro cache city
DS.BL.HotelsPro.Method.GetHotelDetails objhoteldetails_hp = new BL.HotelsPro.Method.GetHotelDetails();
List objhotellist_hp = new List();
objhotellist_hp = objhoteldetails_hp.GethotellistCityWise(details.HotelsProCityCode);
/*
* Hotelbeds city cache
*
*/
DS.Models.BL.HotelBeds.Methods.HotelInfoController objhotelbeds = new DS.Models.BL.HotelBeds.Methods.HotelInfoController();
Solution
I can't answer your question about performance because I don't know where your bottleneck is. If one of the API calls is taking the time, you can't really do anything using your current approach.
If it's
This is going to sound brutal so I apologise beforehand but still feel that it needs to be said: this code is horrible to read.
Let's start with namespaces.
The guideline from MS is
Do you see how much easier that is to read?
There is no point in initialising a local variable if you never use that value.
E.g. this:
Could easily be this:
Note that
If you're using C# 6 you could take it further with string interpolation:
If you need to put huge comments in your method to delimit chunks of functionality, you should instead refactor and introduce a method.
Please name your variables better.
Please get acquainted with the MS style guides:
If it's
GiataApply you'll need to explain more about what's in each list.This is going to sound brutal so I apologise beforehand but still feel that it needs to be said: this code is horrible to read.
Let's start with namespaces.
DS.Models.BL.Common.HotelSearchDetails. What is DS? What is BL. Why does a DS.Models.BL have a Common? Common to other whats? The guideline from MS is
.(|)[.][.]. Once you've sorted out the namespace names, chuck in some usings:using MyCompany.HotelFinder.Models;
// ... later
List hotelDetails = new List();Do you see how much easier that is to read?
There is no point in initialising a local variable if you never use that value.
E.g. this:
DS.Models.BL.Common.HotelSearchDetails details = new DS.Models.BL.Common.HotelSearchDetails();
details = (Models.BL.Common.HotelSearchDetails)Session["Details_" + sessionid];Could easily be this:
var details = (HotelSearchDetails)Session["Details_" + sessionId];Note that
sessionid should be sessionId because local variables are camelCase in C#.If you're using C# 6 you could take it further with string interpolation:
var details = (HotelSearchDetails)Session[$"Details_{sessionId}"];If you need to put huge comments in your method to delimit chunks of functionality, you should instead refactor and introduce a method.
Please name your variables better.
HPhdlist versus hotelProHotelList.Please get acquainted with the MS style guides:
- Capitalization
- Naming
Code Snippets
using MyCompany.HotelFinder.Models;
// ... later
List<HotelDetail> hotelDetails = new List<HotelDetail>();DS.Models.BL.Common.HotelSearchDetails details = new DS.Models.BL.Common.HotelSearchDetails();
details = (Models.BL.Common.HotelSearchDetails)Session["Details_" + sessionid];var details = (HotelSearchDetails)Session["Details_" + sessionId];var details = (HotelSearchDetails)Session[$"Details_{sessionId}"];Context
StackExchange Code Review Q#150051, answer score: 3
Revisions (0)
No revisions yet.