示例#1
0
        public void CreateTruck(TruckViewModel truckViewModel)
        {
            var truck = Mapper.Map <TruckViewModel, Truck_M>(truckViewModel);

            _truckRepository.Add(truck);

            SaveTruck();
        }
示例#2
0
        public async Task <TruckDTO> CreateTruck(SaveTruckDTO dto)
        {
            var truck = new Truck
            {
                ModelId         = dto.ModelId,
                ModelYear       = dto.ModelYear,
                Name            = dto.Name,
                YearManufacture = dto.YearManufacture
            };

            var insert = _truckRepository.Add(truck);

            return(_mapper.Map <TruckDTO>(insert));
        }
示例#3
0
        public IActionResult Create(TruckViewModel truck)
        {
            if (!ModelState.IsValid)
            {
                TruckEditViewModel tevm = new TruckEditViewModel
                {
                    Chassis        = truck.Chassis,
                    BuildingYear   = truck.BuildingYear,
                    ModelYear      = truck.ModelYear,
                    TruckModelList = PopulateList(),
                    TruckModel     = new SelectListItem
                    {
                        Value = truck.TruckModel.Value
                    }
                };
                return(View(tevm));
            }
            if (truck.TruckModel.Value == "-1")
            {
                TruckEditViewModel tevm = new TruckEditViewModel
                {
                    Chassis        = truck.Chassis,
                    BuildingYear   = truck.BuildingYear,
                    ModelYear      = truck.ModelYear,
                    TruckModelList = PopulateList(),
                    TruckModel     = new SelectListItem
                    {
                        Value = truck.TruckModel.Value
                    }
                };
                ModelState.AddModelError("TruckModel.Value", "Você deve selecionar um modelo");
                return(View("Create", tevm));
            }

            Truck t = new Truck
            {
                Chassis      = RandomString(17),
                BuildingYear = truck.BuildingYear,
                ModelYear    = truck.ModelYear,
                TruckModelId = Convert.ToInt32(truck.TruckModel.Value)
            };

            truckRepository.Add(t);

            return(RedirectToAction("Index"));
        }