Beispiel #1
0
        private List <Guid> AddVehicles(List <Vehicle> vehicles)
        {
            List <Guid> insertedVehicles = new List <Guid>();

            insertedVehicles.AddRange(vehicles.Where(ben => ben.BeneficiaryId != Guid.Empty).Select(ben => ben.BeneficiaryId));
            vehicles.RemoveAll(ben => ben.BeneficiaryId != Guid.Empty);

            // Verifies if Chassis Number is already in DB
            if (_db.Vehicles
                .Select(veh => veh.VehicleChassisNumber)
                .Where(cha => vehicles.Select(veh => veh.VehicleChassisNumber).Contains(cha))
                .ToList().Count > 0)
            {
                return(null);
            }

            foreach (var vehicle in vehicles)
            {
                vehicle.IsDeleted = false;
                if (VehicleValidations.VehicleIsValid(vehicle))
                {
                    insertedVehicles.Add(_db.Vehicles.Add(vehicle).Entity.BeneficiaryId);
                }
            }
            if (insertedVehicles.Count == vehicles.Count)
            {
                return(insertedVehicles);
            }
            return(null);
        }
Beispiel #2
0
        public IActionResult PostVehicle([FromBody] Vehicle vehicle)
        {
            vehicle.BeneficiaryId = Guid.NewGuid();

            if (!VehicleValidations.VehicleIsValid(vehicle))
            {
                return(Forbid());
            }

            _vehicleRepository.Add(vehicle);

            return(Ok(vehicle));
        }
Beispiel #3
0
        public IActionResult UpdateVehicle(Guid id, [FromBody] Vehicle vehicle)
        {
            if (!VehicleValidations.VehicleIsValid(vehicle))
            {
                return(Forbid());
            }

            var obj = (Vehicle)_beneficiaryRepository.Find(id);

            obj.VehicleBrand             = vehicle.VehicleBrand;
            obj.VehicleChassisNumber     = vehicle.VehicleChassisNumber;
            obj.VehicleColor             = vehicle.VehicleColor;
            obj.VehicleCurrentFipeValue  = vehicle.VehicleCurrentFipeValue;
            obj.VehicleCurrentMileage    = vehicle.VehicleCurrentMileage;
            obj.VehicleDoneInspection    = vehicle.VehicleDoneInspection;
            obj.VehicleManufactoringYear = vehicle.VehicleManufactoringYear;
            obj.VehicleModel             = vehicle.VehicleModel;
            obj.VehicleModelYear         = vehicle.VehicleModelYear;

            return(Ok(_beneficiaryRepository.Update(id, obj)));
        }