Exemplo n.º 1
0
        public async Task <AdminChartResponse> GetChartResponse()
        {
            var week   = EntityExtensions.GetWeekDate(DateTime.Now);
            var months = EntityExtensions.GetRevenue(DateTime.Now);
            var roles  = await _identityRoleRepository.GetListRoles();

            var areaLabels = new List <string>();
            var areaData   = new List <double>();
            var barLabels  = new List <string>();
            var barData    = new List <double>();
            var pieLabels  = new List <string>();
            var pieData    = new List <double>();

            foreach (var item in week)
            {
                var price = await GetDayEarning(item);

                areaLabels.Add("'" + item.Date.Day + "/" + item.Date.Month + "'");
                areaData.Add(price);
            }

            foreach (var item in months)
            {
                var price = await GetMonthEarning(item);

                barLabels.Add("'Tháng " + item.Date.Month + "'");
                barData.Add(price);
            }

            var emp = _applicationUserRepository.CountEmp();

            foreach (var item in roles)
            {
                var user = await _applicationUserRepository.GetListUserByRole(item);

                pieLabels.Add("'" + item.Name + "'");
                pieData.Add(Math.Round((double)user.Count() / emp * 100));
            }

            return(new AdminChartResponse {
                AreaChart = new AreaChart {
                    Date = areaLabels, DateEarning = areaData
                },
                BarChart = new BarChart {
                    Date = barLabels, DateEarning = barData
                },
                PieChart = new PieChart {
                    Roles = pieLabels, Percentage = pieData
                }
            });
        }