Ejemplo n.º 1
0
        // GET: FuelReceipts
        public async Task <ActionResult> Index(int?id, [Form] TableQueryOptions queryOptions, string searchString)
        {
            ViewBag.QueryOptions = queryOptions;
            var start = QueryOptionsCalculator.CalculateStartPage(queryOptions);

            ViewBag.CarId = id;

            if (id != null)
            {
                var results = await dbReceipt.GetAll();

                var resultsCar = await dbCar.Get(id.GetValueOrDefault());

                ViewBag.CarName         = $"{resultsCar.CarProducer} {resultsCar.CarModel}";
                ViewBag.NumberOfEntries = results.Count();
                var receiptViewModels = results.Where(m => m.FueledCarId == id).Select(vm => vm.ToViewModel()).AsQueryable <FuelReceiptViewModel>();
                ViewBag.NumberOfEntries = receiptViewModels.Count();
                if (!String.IsNullOrEmpty(searchString))
                {
                    searchString      = searchString.ToUpper();
                    receiptViewModels = receiptViewModels.Where(r => r.RefuelingDate.ToString().Contains(searchString) || r.PetrolStationName.ToUpper().Contains(searchString) ||
                                                                r.FuelPrice.ToString().Contains(searchString) || r.FuelAmount.ToString().Contains(searchString) ||
                                                                r.FuelConsumption.ToString().Contains(searchString) || r.PriceFor100km.ToString().Contains(searchString));
                }
                queryOptions.TotalPages = QueryOptionsCalculator.CalculateTotalPages(receiptViewModels.Count(), queryOptions.PageSize);
                return(View(receiptViewModels.OrderBy(queryOptions.Sort).Skip(start).Take(queryOptions.PageSize).ToList()));
            }
            return(RedirectToAction("Index", "Cars"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Configure(int id)
        {
            if (Request.IsAjaxRequest())
            {
                var model = await dbCar.Get(id);

                if (model == null)
                {
                    Response.StatusCode = 403;
                    return(View("NotFound"));
                }
                var viewModel = new ReportConfigureViewModel()
                {
                    CarId     = model.Id,
                    CarData   = $"{model.CarProducer} {model.CarModel}",
                    StartDate = DateTime.Now.AddMonths(-3),
                    EndDate   = DateTime.Now
                };
                return(PartialView(viewModel));
            }
            else
            {
                Response.StatusCode = 500;
                return(View("NotFound"));
            }
        }
Ejemplo n.º 3
0
        public IActionResult Index()
        {
            var model  = new Car();
            var allCar = _carData.GetAll();

            model.brand = _carData.Get(3).brand;
            return(View(model));
        }
        public async Task <ActionResult> Details(int id)
        {
            if (Request.IsAjaxRequest())
            {
                var model = await db.Get(id);

                if (model == null)
                {
                    Response.StatusCode = 403;
                    return(View("NotFound"));
                }
                var viewModel = model.ToViewModel();
                return(PartialView(viewModel));
            }
            else
            {
                Response.StatusCode = 500;
                return(View("NotFound"));
            }
        }
Ejemplo n.º 5
0
        // GET: Charts
        public async Task <ActionResult> Chart(int?id, [Form] ChartQueryOptions chartQueryOptions)
        {
            ViewBag.chartQueryOptions = chartQueryOptions;

            if (id != null)
            {
                var results = await db.GetAll();

                var carResults = await dbCar.Get(id.GetValueOrDefault());

                if (results != null)
                {
                    var lastFuelingReceipt = results.Where(r => r.FueledCarId == id).Where(r => r.FuelType == TypeOfFuel.LPG);
                    if (lastFuelingReceipt.Count() == 0)
                    {
                        return(RedirectToAction("Index", "FuelReceipts", new { id }));
                    }
                    var lastFueling = lastFuelingReceipt.OrderByDescending(r => r.RefuelingDate).First().RefuelingDate;
                    var startDate   = chartQueryOptions.startingTimeRange > lastFueling ? lastFueling : chartQueryOptions.startingTimeRange;
                    ViewBag.startingdate = startDate;
                    var receiptViewModels = results.Where(vm => vm.FueledCarId == id).Where(vm => vm.RefuelingDate >= startDate).Select(vm => vm.ToViewModel());
                    var chartViewModel    = new ChartViewModel()
                    {
                        carId                  = carResults.Id,
                        carData                = $"{carResults.CarProducer} {carResults.CarModel}",
                        lpgConsumptionArray    = receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.LPG).Select(r => decimal.Round(r.FuelConsumption, 2, MidpointRounding.AwayFromZero)).ToArray(),
                        lpgPriceArray          = receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.LPG).Select(r => decimal.Round(r.PriceFor100km, 2, MidpointRounding.AwayFromZero)).ToArray(),
                        lpgDateTimesArray      = receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.LPG).Select(r => r.RefuelingDate.ToString("dd/MM/yyyy")).ToArray(),
                        petrolConsumptionArray = receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.Petrol).Select(r => decimal.Round(r.FuelConsumption, 2, MidpointRounding.AwayFromZero)).ToArray(),
                        petrolPriceArray       = receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.Petrol).Select(r => decimal.Round(r.PriceFor100km, 2, MidpointRounding.AwayFromZero)).ToArray(),
                        petrolDateTimesArray   = receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.Petrol).Select(r => r.RefuelingDate.ToString("dd/MM/yyyy")).ToArray(),
                        dieselConsumptionArray = receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.Diesel).Select(r => decimal.Round(r.FuelConsumption, 2, MidpointRounding.AwayFromZero)).ToArray(),
                        dieselPriceArray       = receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.Diesel).Select(r => decimal.Round(r.PriceFor100km, 2, MidpointRounding.AwayFromZero)).ToArray(),
                        dieselDateTimesArray   = receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.Diesel).Select(r => r.RefuelingDate.ToString("dd/MM/yyyy")).ToArray(),

                        averageFuelCons = decimal.Round(receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.LPG).Average(r => r.FuelConsumption), 2, MidpointRounding.AwayFromZero),
                        maxFuelCons     = decimal.Round(receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.LPG).Max(r => r.FuelConsumption), 2, MidpointRounding.AwayFromZero),
                        minFuelCons     = decimal.Round(receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.LPG).Min(r => r.FuelConsumption), 2, MidpointRounding.AwayFromZero),
                        avgPrice        = decimal.Round(receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.LPG).Average(r => r.PriceFor100km), 2, MidpointRounding.AwayFromZero),
                        totalDistance   = decimal.Round(receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.LPG).Sum(r => r.DistanceFromLastRefueling), 2, MidpointRounding.AwayFromZero),
                        totalPrice      = decimal.Round(receiptViewModels.Where(vm => vm.FuelType == TypeOfFuel.LPG).Sum(r => r.FuelAmount * r.FuelPrice), 2, MidpointRounding.AwayFromZero)
                    };
                    return(View(chartViewModel));
                }
                else
                {
                    return(RedirectToAction("Index", "FuelReceipts", new { id }));
                }
            }
            return(RedirectToAction("Index", "Cars"));
        }