retrieval of dynamic values

This commit is contained in:
Nicolas Constant 2021-02-18 21:48:52 -05:00
parent bf660b80f6
commit 45255fa39d
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688

View file

@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.Domain.Repository;
using BirdsiteLive.Statistics.Domain;
using Microsoft.AspNetCore.Mvc;
namespace BirdsiteLive.Component
@ -10,34 +12,42 @@ namespace BirdsiteLive.Component
public class NodeInfoViewComponent : ViewComponent
{
private readonly IModerationRepository _moderationRepository;
private readonly ITwitterStatisticsHandler _twitterStatisticsHandler;
private readonly ITwitterUserDal _twitterUserDal;
#region Ctor
public NodeInfoViewComponent(IModerationRepository moderationRepository)
public NodeInfoViewComponent(IModerationRepository moderationRepository, ITwitterStatisticsHandler twitterStatisticsHandler, ITwitterUserDal twitterUserDal)
{
_moderationRepository = moderationRepository;
_twitterStatisticsHandler = twitterStatisticsHandler;
_twitterUserDal = twitterUserDal;
}
#endregion
public IViewComponentResult Invoke()
public async Task<IViewComponentResult> InvokeAsync()
{
var followerPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.Follower);
var twitterAccountPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.TwitterAccount);
var twitterUserMax = _twitterStatisticsHandler.GetStatistics().UserCallsMax;
var twitterUserCount = await _twitterUserDal.GetTwitterUsersCountAsync();
var saturation = (int)((double)twitterUserCount / twitterUserMax * 100);
var viewModel = new NodeInfoViewModel
{
BlacklistingEnabled = followerPolicy == ModerationTypeEnum.BlackListing ||
twitterAccountPolicy == ModerationTypeEnum.BlackListing,
WhitelistingEnabled = followerPolicy == ModerationTypeEnum.WhiteListing ||
twitterAccountPolicy == ModerationTypeEnum.WhiteListing,
InstanceSaturation = 16,
InstanceSaturation = saturation,
};
viewModel = new NodeInfoViewModel
{
BlacklistingEnabled = false,
WhitelistingEnabled = false,
InstanceSaturation = 175
};
//viewModel = new NodeInfoViewModel
//{
// BlacklistingEnabled = false,
// WhitelistingEnabled = false,
// InstanceSaturation = 175
//};
return View(viewModel);
}
}