Esempio n. 1
0
        public IActionResult AddUnitTemp(int DriverId, int TruckId)
        {
            UnitTempViewModel model = new UnitTempViewModel
            {
                DriverId = DriverId,
                TruckId  = TruckId
            };

            return(View(model));
        }
Esempio n. 2
0
        public IActionResult AddUnitTemp(UnitTempViewModel model)
        {
            if (ModelState.IsValid)
            {
                UnitTemp temp = new UnitTemp
                {
                    Buy       = model.Buy,
                    EndLts    = model.EndLts,
                    EndPulg   = model.EndPulg,
                    Fuel      = model.Fuel,
                    Id        = 0,
                    StartLts  = model.StartLts,
                    StartPulg = model.StartPulg
                };

                switch (model.Fuel)
                {
                case "1":
                    temp.TypeFuel = TypeFuel.Regular;
                    break;

                case "0":
                    temp.TypeFuel = TypeFuel.Diesel;
                    break;

                case "2":
                    temp.TypeFuel = TypeFuel.Super;
                    break;

                case "3":
                    temp.TypeFuel = TypeFuel.Exonerado;
                    break;
                }

                _context.UnitTemps.Add(temp);
                _context.SaveChanges();

                return(RedirectToAction($"{model.DriverId}/{nameof(Index)}/{model.TruckId}"));
            }

            return(View(model));
        }