public async Task <IActionResult> Create() { var id = this.TempData.Peek("carId").ToString(); var carFromDb = await this.carsService.GetDetailsAsync <CarDetailsViewModel>(id); var viewModel = new TransportWorkTicketInputViewModel { CarId = carFromDb.Id, CarFuelType = carFromDb.FuelType, CarModel = carFromDb.Model, CarCompanyId = carFromDb.CompanyId, CarAverageConsumption = carFromDb.AverageConsumption, CarInitialFuel = carFromDb.InitialFuel, CarLicensePlate = carFromDb.LicensePlate, CarStartKilometers = carFromDb.StartKilometers, CarTankCapacity = carFromDb.TankCapacity, AllDrivers = this.usersService.GetAll(carFromDb.CompanyId), AllLiters = this.carsService.GetCurrentLitresByCarId(carFromDb.Id), AllTravelledDistance = this.carsService.GetCurrentTravelledDistanceByCarId(carFromDb.Id), AllFuelConsumption = this.carsService.GetCurrentFuelConsumptionByCarId(carFromDb.Id), AllRoutes = this.routesService.GetAll(), }; if (viewModel == null) { return(this.NotFound()); } return(this.View(viewModel)); }
public async Task <ActionResult> RouteDetailsPartial(string id) { var viewModel = new TransportWorkTicketInputViewModel(); viewModel.Routes = new List <RouteViewModel>(); string[] splittedIds = id.Split(",", System.StringSplitOptions.RemoveEmptyEntries); foreach (var routeId in splittedIds) { var currentRoute = await this.routesService.GetByIdAsync <RouteViewModel>(routeId); viewModel.Routes.Add(currentRoute); } return(this.PartialView("_RouteDetailsPartial", viewModel)); }
public async Task <IActionResult> Create(TransportWorkTicketInputViewModel input) { var id = this.TempData.Peek("carId").ToString(); if (!this.ModelState.IsValid) { input.AllLiters = this.carsService.GetCurrentLitresByCarId(input.CarId); input.AllTravelledDistance = this.carsService.GetCurrentTravelledDistanceByCarId(input.CarId); input.AllFuelConsumption = this.carsService.GetCurrentFuelConsumptionByCarId(input.CarId); input.AllRoutes = this.routesService.GetAll(); return(this.View(input)); } var user = await this.userManager.GetUserAsync(this.User); var transportWorkTicket = await this.transportWorkTicketsService.CreateAsync(input.Date, user.Id, input.CarId, input.CreatedBy, input.StartKilometers, input.EndKilometers, input.FuelConsumption, input.Residue, input.FuelAvailability, input.TravelledDistance); await this.routeTransportWorkTicketsService.UpdateAsync(transportWorkTicket.Id, input.CarCompanyId, input.Route); return(this.RedirectToAction("All", "TransportWorkTickets", new { id })); }