public async Task <IActionResult> UpdateVehicle(int id, [FromBody] SaveVehicleResources vehicle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var vData = await repos.GetVehicle(vehicle.Id);

            if (vData == null)
            {
                return(NotFound());
            }

            map.Map <SaveVehicleResources, Vehicle>(vehicle, vData);
            vData.LastUpdate = DateTime.Now;

            await uow.Complete();

            vData = await repos.GetVehicle(vehicle.Id);

            var respond = map.Map <Vehicle, VehicleResources>(vData);

            return(Ok(respond));
        }
        public async Task <IActionResult> CreateVehicle([FromBody] SaveVehicleResources VR)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //var model = await context.Models.FindAsync(VR.ModelId);
            var model = await repository.GetModel(VR.ModelId);

            if (model == null)
            {
                ModelState.AddModelError("ModelId", "Invalid Model");
                return(BadRequest(ModelState));
            }

            var vehicle = mapper.Map <SaveVehicleResources, Vehicle>(VR);

            vehicle.LastUdpate = DateTime.Now;
            //context.Vehicles.Add(vehicle);
            repository.Add(vehicle);
            await unitofWork.CompleteAsync();

            // This will include all the other name properties form id
            vehicle = await repository.GetVehicle(vehicle.Id);

            var result = mapper.Map <Vehicle, VehicleResources>(vehicle);

            return(Ok(result));
        }
Beispiel #3
0
        public async Task <IActionResult> CreateVehicle([FromBody] SaveVehicleResources vehicleResources)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if ((await featureRepository.GetModelAsync(vehicleResources.ModelId)) == null)
            {
                ModelState.AddModelError("ModelId", "Invalid ModelId");
                return(BadRequest(ModelState));
            }

            var vehicle = mapper.Map <Vehicle>(vehicleResources);

            vehicle.LastUpdate = DateTime.Now;
            vehicleRepository.Add(vehicle);
            await unitOfWork.CompleteAsync();

            vehicle = await vehicleRepository.GetVehicleAsync(vehicle.Id);

            var result = mapper.Map <VehicleResources>(vehicle);

            return(Ok(result));
        }
Beispiel #4
0
        public async Task <IActionResult> CreateVehicle([FromBody] SaveVehicleResources vehicleRes)
        {
            var vehicle = mapper.Map <SaveVehicleResources, Vehicle>(vehicleRes);

            //vehicle.LastUpdate = DateTime.Now;
            repository.AddVehicle(vehicle);
            await unitOfWork.CompleteAsync();

            vehicle = await repository.GetVehicle(vehicle.Id);

            var result = mapper.Map <Vehicle, VehicleResources>(vehicle);

            return(Ok(result));
        }
Beispiel #5
0
        public async Task <IActionResult> UpdateVehicle([FromBody] SaveVehicleResources vehicleRes, int id)
        {
            // var vehicle = await context.Vehicles.Include(v=>v.Features).SingleOrDefaultAsync(x=>x.Id == id);

            var vehicle = await repository.GetVehicle(id);

            if (vehicle == null)
            {
                return(NotFound());
            }
            mapper.Map <SaveVehicleResources, Vehicle>(vehicleRes, vehicle);
            // vehicle.LastUpdate = DateTime.Now;
            await unitOfWork.CompleteAsync();

            vehicle = await repository.GetVehicle(vehicle.Id);

            var result = mapper.Map <Vehicle, VehicleResources>(vehicle);

            return(Ok(result));
        }
        public async Task <IActionResult> CreateVehicle([FromBody] SaveVehicleResources vehicle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var res = map.Map <SaveVehicleResources, Vehicle>(vehicle);

            res.LastUpdate = DateTime.Now;

            repos.Add(res);
            await uow.Complete();

            var result = await repos.GetVehicle(vehicle.Id);

            var respond = map.Map <Vehicle, VehicleResources>(result);

            return(Ok(respond));
        }
Beispiel #7
0
        public async Task <IActionResult> UpdateVehicle(int id, [FromBody] SaveVehicleResources vehicleResources)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var vehicle = await vehicleRepository.GetVehicleAsync(id);

            if (vehicle == null)
            {
                ModelState.AddModelError("Id", "Invalid Vehicle Id");
                return(BadRequest(ModelState));
            }

            mapper.Map <SaveVehicleResources, Vehicle>(vehicleResources, vehicle);
            vehicle.LastUpdate = DateTime.Now;
            await unitOfWork.CompleteAsync();

            var result = mapper.Map <VehicleResources>(vehicle);

            return(Ok(result));
        }
        [HttpPut("{id}")] // / api/vehicles/{id}

        public async Task <IActionResult> UpdateVehicle(int id, [FromBody] SaveVehicleResources VR)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var vehicle = await repository.GetVehicle(id);

            if (vehicle == null)
            {
                return(NotFound());
            }
            mapper.Map <SaveVehicleResources, Vehicle>(VR, vehicle);
            vehicle.LastUdpate = DateTime.Now;
            await unitofWork.CompleteAsync();

            // This will include all the other name properties form id
            vehicle = await repository.GetVehicle(vehicle.Id);

            var result = mapper.Map <Vehicle, VehicleResources>(vehicle);

            return(Ok(result));
        }