Example #1
0
 public ShowStatisticsPageViewModel(INavigationService navigationService,
                                    IApiService apiService) : base(navigationService)
 {
     _navigationService = navigationService;
     _apiService        = apiService;
     Title           = Languages.MyStatistics;
     IsRunning       = false;
     IsVisible       = false;
     Chart           = new ToShowChart();
     StatisticsTypes = new ObservableCollection <StatisticsType>(CombosHelper.GetStatisticsTypes());
     Months          = new ObservableCollection <Month>(CombosHelper.GetMonths());
 }
Example #2
0
        public async Task <Response> GetStatistics(string urlBase,
                                                   string servicePrefix,
                                                   string controller,
                                                   string tokenType,
                                                   string accessToken,
                                                   StatisticsRequest request)
        {
            try
            {
                string        requestString = JsonConvert.SerializeObject(request);
                StringContent content       = new StringContent(requestString, Encoding.UTF8, "application/json");
                HttpClient    client        = new HttpClient
                {
                    BaseAddress = new Uri(urlBase)
                };

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, accessToken);
                string url = $"{servicePrefix}{controller}";
                HttpResponseMessage response = await client.PostAsync(url, content);

                string result = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = result,
                    });
                }

                ToShowChart statisticsResponse = JsonConvert.DeserializeObject <ToShowChart>(result);
                return(new Response
                {
                    IsSuccess = true,
                    Result = statisticsResponse
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = ex.Message
                });
            }
        }
Example #3
0
        public async Task <IActionResult> Statistics()
        {
            List <ContactStatistics> statistics = await _dataContext.ContactStatistics
                                                  .FromSql(@"
                    SELECT DAY(c.StartDate) AS Day
	                    , CONVERT(FLOAT,ROUND(((COUNT(c.CustomerId)*1.0/tab.Total_Contacto)*100),0)) AS PercentContact
                    FROM Calls AS c 
                    INNER JOIN Codifications AS cod 
                    ON cod.Id = c.CodificationId
                    INNER JOIN (SELECT DAY(c.StartDate) AS Dia
				                    , COUNT(c.CustomerId) AS Total_Contacto
			                    FROM Calls AS c
			                    GROUP BY DAY(c.StartDate)) AS tab ON tab.Dia = DAY(c.StartDate)
                    WHERE cod.ContactType = 0
                    GROUP BY DAY(c.StartDate),tab.Total_Contacto
                    ORDER BY DAY(c.StartDate) ASC
                ").ToListAsync();

            List <EffectivityStatistics> statistics2 = await _dataContext.EffectivityStatistics
                                                       .FromSql(@"
                    SELECT DAY(c.StartDate) AS Day
	                    , CONVERT(FLOAT,ROUND(((COUNT(c.CustomerId)*1.0/tab.Total_Contacto)*100),0)) AS PercentEffectivity
                    FROM Calls AS c 
                    INNER JOIN Codifications AS cod 
                    ON cod.Id = c.CodificationId
                    INNER JOIN (SELECT DAY(c.StartDate) AS Dia
				                    , COUNT(c.CustomerId) AS Total_Contacto
			                    FROM Calls AS c
			                    GROUP BY DAY(c.StartDate)) AS tab ON tab.Dia = DAY(c.StartDate)
                    WHERE cod.EffectivityType = 0
                    GROUP BY DAY(c.StartDate),tab.Total_Contacto
                    ORDER BY DAY(c.StartDate) ASC
                ").ToListAsync();

            ToShowChart model = new ToShowChart
            {
                ContactStatistics     = statistics,
                EffectivityStatistics = statistics2
            };

            return(View(model));
        }
        public async Task <IActionResult> GetMyStatistics([FromBody] StatisticsRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            UserEntity user = _userHelper.GetUserByCodeAsync(request.UserCode);
            List <ContactStatistics> statistics = await _dataContext.ContactStatistics
                                                  .FromSql($"SELECT DAY(c.StartDate) AS Day, CONVERT(FLOAT,ROUND(((COUNT(c.CustomerId)*1.0/tab.Total_Contacto)*100),0)) AS PercentContact FROM Calls AS c INNER JOIN Codifications AS cod  ON cod.Id = c.CodificationId INNER JOIN (SELECT DAY(c.StartDate) AS Dia, COUNT(c.CustomerId) AS Total_Contacto FROM Calls AS c WHERE c.UserId = {user.Id} AND MONTH(c.StartDate) = {request.Month} GROUP BY DAY(c.StartDate)) AS tab ON tab.Dia = DAY(c.StartDate) WHERE cod.ContactType = 0 AND c.UserId = {user.Id} AND MONTH(c.StartDate) = {request.Month} GROUP BY DAY(c.StartDate),tab.Total_Contacto ORDER BY DAY(c.StartDate) ASC").ToListAsync();

            List <EffectivityStatistics> statistics2 = await _dataContext.EffectivityStatistics
                                                       .FromSql($"SELECT DAY(c.StartDate) AS Day, CONVERT(FLOAT,ROUND(((COUNT(c.CustomerId)*1.0/tab.Total_Contacto)*100),0)) AS PercentEffectivity FROM Calls AS c INNER JOIN Codifications AS cod  ON cod.Id = c.CodificationId INNER JOIN (SELECT DAY(c.StartDate) AS Dia, COUNT(c.CustomerId) AS Total_Contacto FROM Calls AS c WHERE c.UserId = {user.Id} AND MONTH(c.StartDate) = {request.Month} GROUP BY DAY(c.StartDate)) AS tab ON tab.Dia = DAY(c.StartDate) WHERE cod.EffectivityType = 0 AND c.UserId = {user.Id} AND MONTH(c.StartDate) = {request.Month} GROUP BY DAY(c.StartDate),tab.Total_Contacto ORDER BY DAY(c.StartDate) ASC").ToListAsync();

            ToShowChart response = new ToShowChart
            {
                ContactStatistics     = statistics,
                EffectivityStatistics = statistics2
            };

            return(Ok(response));
        }