Exemplo n.º 1
0
        public JsonResult AddVehicle(string manufacturer, string model, int year, string color, string category, string fuelType, string plate, string rate, IFormFile imageFile)
        {
            string location = "/Vehicle Images";
            string dbName   = null;

            dbName = _fileUploader.UploadFileAsync(imageFile, model, location).Result;

            if (dbName != null)
            {
                Manufacturer man = _manufacturerService.GetFromName(manufacturer);

                if (man == null)
                {
                    _manufacturerService.AddManufacturer(new Manufacturer
                    {
                        ManufacturerName = manufacturer
                    });

                    man = _manufacturerService.GetFromName(manufacturer);
                }

                Vehicle vehicle = new Vehicle
                {
                    Manufacturer = man,
                    Model        = model,
                    Year         = year,
                    Color        = color,
                    Category     = category,
                    FuelType     = fuelType,
                    PlateNumber  = plate,
                    Rate         = Double.Parse(rate),
                    ImageUrl     = dbName
                };

                _vehicleService.AddVehicle(vehicle);

                return(Json("Success"));
            }

            return(Json("Failure"));
        }