diff --git a/src/OnePeek.Api/AppMetadataEndpoint.cs b/src/OnePeek.Api/AppMetadataEndpoint.cs index 516d930..c838108 100644 --- a/src/OnePeek.Api/AppMetadataEndpoint.cs +++ b/src/OnePeek.Api/AppMetadataEndpoint.cs @@ -84,23 +84,32 @@ namespace OnePeek.Api throw new ArgumentException("Please provide a valid store culture"); } - string xml = await ApiHttpClient.Instance.Get( - EndpointUris.GetWindowsPhoneMetadataUri(appId, storeCulture.ToString()) - ); - - IEnumerable xel = XDocument.Parse(xml).Elements().First().Descendants(); - - // create rating AppRating result = new AppRating(); result.Culture = storeCulture; - result.RatingCount = Convert.ToInt32(xel.Get("userRatingCount")); - result.AverageRating = xel.GetFloat("averageUserRating"); - if (Configuration.UseFiveStarSystem) - { - result.AverageRating = (float)(result.AverageRating * 0.5); - } - return result; + try + { + string xml = await ApiHttpClient.Instance.Get( + EndpointUris.GetWindowsPhoneMetadataUri(appId, storeCulture.ToString()) + ); + + IEnumerable xel = XDocument.Parse(xml).Elements().First().Descendants(); + + // update rating + result.RatingCount = Convert.ToInt32(xel.Get("userRatingCount")); + result.AverageRating = xel.GetFloat("averageUserRating"); + if (Configuration.UseFiveStarSystem) + { + result.AverageRating = (float)(result.AverageRating * 0.5); + } + + return result; + } + catch + { + result.RatingNotAvailable = true; + return result; + } } diff --git a/src/OnePeek.Entities/AppRating.cs b/src/OnePeek.Entities/AppRating.cs index 62a89d3..419b286 100644 --- a/src/OnePeek.Entities/AppRating.cs +++ b/src/OnePeek.Entities/AppRating.cs @@ -10,6 +10,11 @@ namespace OnePeek.Entities /// public StoreCultureType Culture { get; set; } + /// + /// In case this is set to true, the Microsoft service didn't respond with a valid dataset to the requested culture + /// + public bool RatingNotAvailable { get; set; } + /// /// Average rating of the app from 1-10 (can be changed to 1-5 with Configuration.UseFiveStarSystem). /// Is dependent on the current culture. diff --git a/src/OnePeek.WebConsole/Modules/HomeModule.cs b/src/OnePeek.WebConsole/Modules/HomeModule.cs index b03ac4f..36362e1 100644 --- a/src/OnePeek.WebConsole/Modules/HomeModule.cs +++ b/src/OnePeek.WebConsole/Modules/HomeModule.cs @@ -2,6 +2,7 @@ using OnePeek.Api; using OnePeek.Entities; using System.Collections.Generic; +using System.Linq; using System.IO; namespace OnePeek.WebConsole.Modules @@ -34,8 +35,29 @@ namespace OnePeek.WebConsole.Modules Get["/ratings", true] = async (ctx, token) => { + var order = Request.Query["order"]; IEnumerable ratings = await metaEndpoint.GetRatingsForAllCultures(Request.Query["id"], StoreType.WindowsPhone8, new System.Threading.CancellationTokenSource().Token, null); - return View["Ratings", new { Ratings = ratings }]; + + if (order == "rating") + { + ratings = ratings.OrderByDescending(x => x.AverageRating).ThenByDescending(x => x.RatingCount); + } + else if (order == "name") + { + ratings = ratings.OrderBy(x => x.Culture); + } + else + { + order = "count"; + ratings = ratings.OrderByDescending(x => x.RatingCount); + } + + return View["Ratings", new + { + Order = order, + Id = Request.Query["id"], + Ratings = ratings + }]; }; } } diff --git a/src/OnePeek.WebConsole/Views/Ratings.cshtml b/src/OnePeek.WebConsole/Views/Ratings.cshtml index 5542a22..6a02a9c 100644 --- a/src/OnePeek.WebConsole/Views/Ratings.cshtml +++ b/src/OnePeek.WebConsole/Views/Ratings.cshtml @@ -3,17 +3,29 @@ Layout = "_Layout.cshtml"; } +ORDER BY
+ + +
+ @foreach (var rating in Model.Ratings) { + string percentage = ((float)rating.AverageRating * 20f).ToString("0.00").Replace(",", ".");

@rating.Culture

-

@rating.AverageRating (@rating.RatingCount)

+

@(rating.RatingNotAvailable ? "ERROR" : "OK") @rating.AverageRating (@rating.RatingCount)

-
+ +
} \ No newline at end of file