Esempio n. 1
0
        public IActionResult Create(IFormFile vehicleImage, string name, string rideService)
        {
            string bucketname = _config.GetSection("AppSettings").GetSection("LogosBucket").Value;

            Vehicle newVehicle = new Vehicle();

            newVehicle.VehicleID = Guid.NewGuid();
            newVehicle.Name      = name;
            newVehicle.Category  = rideService;

            using (var myFile = vehicleImage.OpenReadStream())
            {
                var credential = GoogleCredential.GetApplicationDefault();
                var storage    = StorageClient.Create(credential);
                var filePath   = @"vehicleImages/" + newVehicle.VehicleID + "/" + vehicleImage.FileName;
                storage.UploadObject(bucketname, filePath, null, myFile);

                newVehicle.ImageURL = filePath;
            }

            newVehicle.Owner = User.Identity.Name;
            _vehiclesRepo.AddVehicle(newVehicle);
            ViewBag.Categories = _cacheRepository.GetCategories();
            return(View());
        }
Esempio n. 2
0
 public Response <string> Execute(Vehicle vehicle)
 {
     if (IsAlreadyParked(vehicle.numberPlate))
     {
         return(new Response <string>(false, null, AllowEntryVehicleErrors.itsAlreadyParked));
     }
     if (IsThereSiteAvaliableByVehicleType(vehicle.type))
     {
         return(new Response <string>(false, null, AllowEntryVehicleErrors.parkIsFull));
     }
     if (CanNotEnterToday(vehicle.numberPlate, vehicle.date))
     {
         return(new Response <string>(false, null, AllowEntryVehicleErrors.canNotEnterToday));
     }
     vehiclesRepository.AddVehicle(vehicle);
     return(new Response <string>(true, vehicleAdded, null));
 }