Пример #1
0
 public async Task <IActionResult> GetAverageOrderAmount([FromRoute(Name = "companyId")] int compnayId)
 {
     return(await _repository.GetAverageOrderAmount(compnayId)
            .Ensure(m => m.HasValue, "Have Values")
            .OnBoth(m => m.IsFailure ? StatusCode(404, "") : StatusCode(200, m.Value.Value))
            .ConfigureAwait(false));
 }
Пример #2
0
        public async Task <IActionResult> OnGetAsync()
        {
            ViewData["HideNavigation"] = !signInManager.IsSignedIn(User);

            if (signInManager.IsSignedIn(User))
            {
                Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

                Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

                var companyResult = await companies.FetchCompany(Employee.CompanyId)
                                    .Ensure(c => c.HasValue, "Company found")
                                    .OnSuccess(c => c.Value)
                                    .ConfigureAwait(false);

                // We intentionally let this throw on failure as this is the index page, so we have nowhere safe to redirect to.
                Company = companyResult.Value;
                Feed    = await feeds.GetFeed().ConfigureAwait(false);

                var averageOrderResult = await analytics.GetAverageOrderAmount(Company.CompanyId)
                                         .Ensure(r => r.HasValue, "Results found")
                                         .OnSuccess(r => r.Value)
                                         .ConfigureAwait(false);

                if (averageOrderResult.IsSuccess)
                {
                    var data = new BarChartData {
                        Labels = new List <string>(),
                        Series = new List <List <double> > {
                            new List <double>()
                        }
                    };

                    averageOrderResult.Value.ForEach(result => {
                        data.Labels.Add(result.VenueId.ToString());
                        data.Series[0].Add((double)result.Average);
                    });

                    AverageOrderPerVenue = JsonConvert.SerializeObject(data, jsonSerializerSettings);
                }

                var companyOrderStatuses = await analytics.GetCompanyOrderStatuses(Company.CompanyId)
                                           .Ensure(r => r.HasValue, "Results found")
                                           .OnSuccess(r => r.Value)
                                           .ConfigureAwait(false);

                if (companyOrderStatuses.IsSuccess)
                {
                    var data = new BarChartDescriptiveData
                    {
                        Labels = new List <string>(),
                        Series = new List <List <BarChartDesciptiveElem> >()
                    };

                    for (var i = 0; i < 3; i++)
                    {
                        data.Series.Add(new List <BarChartDesciptiveElem>());
                    }

                    companyOrderStatuses.Value.ForEach(result =>
                    {
                        data.Labels.Add(result.VenueId.ToString());

                        data.Series[0].Add(new BarChartDesciptiveElem
                        {
                            Meta  = "Incomplete",
                            Value = result.Incomplete
                        });

                        data.Series[1].Add(new BarChartDesciptiveElem
                        {
                            Meta  = "Complete",
                            Value = result.Complete
                        });

                        data.Series[2].Add(new BarChartDesciptiveElem
                        {
                            Meta  = "Failed",
                            Value = result.Failed
                        });
                    });

                    CompanyOrderStatuses = JsonConvert.SerializeObject(data, jsonSerializerSettings);
                }
            }

            return(Page());
        }