Last active
March 14, 2019 19:03
-
-
Save gzamudio/5530a0248571d5cd97cc5bc482a19e47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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