OpenWeatherMap Demo Application

25-Jan-2018 - Following a 'code review', this mini project was a three day setup and see if it works prototype.

So, a quick revisit to identify separations of concerns, redesigned as OOD, to some degree.
Still not happy with HTML strings in the controller, but:
1. It works;
2. Easy to understand.

If this was moved into the View, it would require 'if' statements which is frowned upon (bad coding smell).
Conclusion: Not worth any more effort at this time.

23-Jan-2018 - DDL issue with HiddenFor is not a bug - my mistake (doh!). Where I have used it is in Edit/Delete views to capture non-displayed primary keys.

16-Jan-2018 - Updated to only load city data once.

15-Jan-2018 - "Fix" issue with DDL.

13-Jan-2018 - Investigate issue with DDL.

12-Jan-2018 - Day 3 Completed!!!

11-Jan-2018 - Day 2

10-Jan-2018 - The Brief: Technical Exercise - Using the OpenWeatherMap API create an application which demonstrates your technical abilities as a developer.

OK - what to do? On looking at the OWM website, there is an API menu option which opens up a page:

"Our weather API is simple, clear and free. We also offer higher levels of support, please see our paid plan options.
To access the API you need to sign up for an API key if you are on a free or paid plan."

After a bit of reading, followed the instructions and signed up for a free API key.

"Call API by city ID instead of city name, city coordinates or zip code. In this case you get precise respond exactly for your city. The cities' IDs can be found in the following file: Cities' IDs list."

Starting Point - download, unzip and see what's in the file!

First Steps:
  1. Create a new C# MVC template project to build my prototype.
  2. Download, unzip the city file - JSON format
  3. Import the city file
  4. Test page for Select a City and to action a request for one city
  5. Get the results of the request into a usable format (class structures)
  6. Display results on screen (view)

Well, not quite. 1, 2 & 3 went really smoothly, even the file load.

Point 3: Wow - too many records in the city data for a drop-down-list.

Point 4: Split-decision = press on, but only list city data in country 'GB' beginning with 'H'.

Point 5: Class Structures - chored for now - see if it works.


Point 5: Oh Dear!

The story goes like this...

Set up the template for C# MVC.
Loaded the city file into a city class.
Passed this to my view ok.
Tested the current weather api call and got the response ok.
Added a ddl to my view to list a limited number of cities from the loaded city file...
...seems to be a major problem as the model is coming back from the view as invalid.

Several hours later, I have found the problem and a solution, but still smacks of a bug in VS:

In my view, the plan was to have an id to capture the selected id of the city selected from the ddl i.e. I have:
@Html.HiddenFor(model => model.cityid)


@Html.DropDownListFor(m => m.cityid, new SelectList(Model.citylist, "id", "name"), "Select...", new { @class = "form-control", id = "CityDDLDiv" })
But this value comes back as null and the model is invalid

After much searching and testing, this is the only thing that worked:

@Html.DropDownListFor(m => m.citylist[0].id, new SelectList(Model.citylist, "id", "name"), "Select...", new { @class = "form-control", id = "CityDDLDiv" })

Anyway, it's working and the response has been decoded and I have the data on screen :-)

© 2018 - StartledCat