Skip to content

Instantly share code, notes, and snippets.

@gzamudio
Last active March 14, 2019 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gzamudio/5530a0248571d5cd97cc5bc482a19e47 to your computer and use it in GitHub Desktop.
Save gzamudio/5530a0248571d5cd97cc5bc482a19e47 to your computer and use it in GitHub Desktop.
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[HttpGet("AllResourceCategoryMetric")]
public IActionResult ResourceCategoryMetric(string startingDate)
{
// TODO: roles not implemented yed, this metric is returns the same metric for any role
if (startingDate == string.Empty)
return BadRequest(Localizer["SelectATimePeriod"]);
var resources = UnitOfWork.ResourceRepository.GetAllWithRelatedEntitites().Where(ra =>
ra.UpdatedAt >= DateTime.ParseExact(startingDate, "dd/MM/yyyy", CultureInfo.InvariantCulture))
.ToList();
if (!resources.Any())
return BadRequest(Localizer["ResourcesNotFoundInPeriod"].Value);
var allReviewCategories = resources.SelectMany(r => r.UserResourceReviews.SelectMany(rev => rev.Categories));
return Json(Enum.GetValues(typeof(ReviewCategory)).Select(category => new ResourceCategoryMetricVO
{
CategoryName = category.ToString(),
Percentage = Math.Round((decimal)(100 * allReviewCategories.Count(cat => cat == category)) / allReviewCategories.Count(), 2),
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment