Exemplo n.º 1
0
        public async Task <IActionResult> Create(FuelEntryCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                this.ShowModelStateError();
                return(RedirectToAction(nameof(Create), new { id = model.VehicleId }));
            }

            var serviceModel = Mapper.Map <FuelEntryCreateServiceModel>(model);
            var success      = await this.fuelEntryService.CreateAsync(serviceModel);

            if (!success)
            {
                this.ShowNotification(NotificationMessages.FuelEntryUpdateFailed);
                return(RedirectToAction(nameof(Create), new { id = model.VehicleId }));
            }

            this.ShowNotification(NotificationMessages.FuelEntryAddedSuccessfull, NotificationType.Success);
            return(RedirectToVehicle(model.VehicleId));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(int id)
        {
            var user = await this.userManager.GetUserAsync(User);

            DateTime dateCreated = this.dateTimeProvider.GetCurrentDateTime();

            var model = new FuelEntryCreateViewModel
            {
                DateCreated          = dateCreated,
                VehicleId            = id,
                CurrencyId           = user.CurrencyId,
                FuelEntryTypes       = await this.GetAllFuelEntryTypesAsync(),
                FuelTypes            = await this.GetAllFuelTypesAsync(),
                AllRoutes            = await this.GetAllRouteTypesAsync(),
                AllExraFuelConsumers = await this.GetAllExtraFuelConsumersAsync(),
                AllCurrencies        = await this.GetAllCurrenciesAsync(),
                PricingTypes         = await this.GetAllPricingTypesAsync(),
                LastOdometer         = await this.GetPreviousOdometerValue(id, dateCreated)
            };

            return(View(model));
        }