public async Task <IActionResult> GtDateRangeList([FromBody] SmartParkListDateRangeRequestViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model = new SmartParkListDateRangeRequestViewModel
                {
                    DateFrom = DateTime.Today.AddDays(-6),
                    DateTo   = DateTime.Now
                };
            }

            var dateFrom = model.DateFrom;
            var dateTo   = model.DateTo;

            // ReSharper disable once PossibleInvalidOperationException
            var userId = CurrentUser.UserId.Value;

            var serviceResult = await _gateUsageService.GetAllAsync(x => x.DateOfUse >= dateFrom && x.DateOfUse <= dateTo && x.UserId == userId);

            if (serviceResult.IsValid)
            {
                return(Ok(SmartJsonResult <SmartParkListWithDateRangeViewModel <GateOpeningViewModel> >
                          .Success(new SmartParkListWithDateRangeViewModel <GateOpeningViewModel>
                {
                    ListItems = serviceResult.Result.OrderByDescending(x => x.DateOfUse).Select(_mapper.Map <GateOpeningViewModel>),
                    DateTo = model.DateTo,
                    DateFrom = model.DateFrom
                })));
            }
            return(BadRequest(SmartJsonResult <SmartParkListWithDateRangeViewModel <GateOpeningViewModel> > .Failure(serviceResult.ValidationErrors)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetUserChargesData()
        {
            var user           = (await _userService.GetByEmailAsync(CurrentUser.Email)).Result;
            var userId         = user.Id;
            var endDate        = DateTime.Today.AddDays(1).AddSeconds(-1);
            var startDate      = DateTime.Today.AddDays(-6);
            var userGateUsages = (await _gateUsageService.GetAllAsync(x => x.UserId == userId)).Result.ToList();

            var lineChartData = await _chartService.GetDataAsync(new ChartRequestDto(startDate, endDate, ChartType.GateOpenings, ChartGranuality.PerDay, userId));

            return(Ok(new
            {
                chargesUsed = userGateUsages.Count,
                chargesLeft = user.Charges,
                lineChartData = _mapper.Map <ChartDataReturnModel>(lineChartData.Result)
            }));
        }