Esempio n. 1
0
        public async Task <IActionResult> Create()
        {
            var id = this.TempData.Peek("carId").ToString();

            var carFromDb = await this.carsService.GetDetailsAsync <CarDetailsViewModel>(id);

            var viewModel = new InvoiceInputViewModel
            {
                CarId              = carFromDb.Id,
                CarFuelType        = carFromDb.FuelType,
                CarModel           = carFromDb.Model,
                CarCompanyId       = carFromDb.CompanyId,
                CarInitialFuel     = carFromDb.InitialFuel,
                CarTankCapacity    = carFromDb.TankCapacity,
                AllLitres          = this.carsService.GetCurrentLitresByCarId(id),
                AllFuelConsumption = this.carsService.GetCurrentFuelConsumptionByCarId(id),
            };

            viewModel.CurrentLiters = viewModel.Liters;

            if (viewModel == null)
            {
                return(this.NotFound());
            }

            return(this.View(viewModel));
        }
        public async Task <IActionResult> Create(InvoiceInputViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.AllDrivers = this.usersService.GetUsersByCar(input.CarId);
                return(this.View(input));
            }

            var user = await this.usersService.GetByNameAsync <UserViewModel>(input.FullName, input.CarCompanyId);

            await this.invoicesService.CreateAsync(input.Number, input.Date, input.CarFuelType, input.Location, input.CurrentLiters, input.Price, input.Quantity, input.TotalPrice, user.Id, input.CarId, input.CreatedBy);

            return(this.RedirectToAction("All", "Invoices", new { id = input.CarId }));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create(InvoiceInputViewModel input)
        {
            var id = this.TempData.Peek("carId").ToString();

            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            await this.invoicesService.CreateAsync(input.Number, input.Date, input.CarFuelType, input.Location, input.CurrentLiters, input.Price, input.Quantity, input.TotalPrice, user.Id, input.CreatedBy, input.CreatedBy);

            return(this.RedirectToAction("All", "Invoices", new { id }));
        }