public void Add([FromBody] Car car) { if (_carRepository.GetAllCars().Where(u => u.Id == car.Id) == null) { _carRepository.CreateCar(car); } }
public async Task <IActionResult> CreateCar([FromForm] Car newcar) { /// TODO Validations Models // Get file url var result = await _carRepository.CreateCar(newcar); if (result > 0) { // write image in wwwroot/images try { var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "images"); if (newcar.Image.Length > 0) { var ext = System.IO.Path.GetExtension(newcar.Image.FileName); string filename = result.ToString() + "." + ext; // result is the card id var filePath = Path.Combine(uploads, filename); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await newcar.Image.CopyToAsync(fileStream); } } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.ToString()); } return(Ok(result)); } else { return(BadRequest(ResponseCodes.ErrorToCreate)); } }
public Car CreateCar(Car car) { if (_carValidator != null) { _carValidator.ValidateCar(car, false); } return(_carRepository.CreateCar(car)); }
public Car AddCar(Car car) { if (string.IsNullOrEmpty(car.Color)) { throw new InvalidOperationException("Car needs a Color"); } return(_carRepository.CreateCar(car)); }
public Car CreateCar(Car carToCreate) { ValidateId(carToCreate.CarId); ValidateSpecValues(carToCreate.CarSpecs); ValidateAccessoryValues(carToCreate.CarAccessories); ValidateDetailValues(carToCreate.CarDetails); return(_carRepository.CreateCar(carToCreate)); }
public void Handle(CarParams car) { var newCar = new Car { Name = car.Name, AddedOn = DateTime.Now }; _repository.CreateCar(newCar); }
public ActionResult CreateCar(Car Cars) { if (ModelState.IsValid) { _сarRepository.CreateCar(Cars); return(RedirectToAction("Index")); } else { return(View(Cars)); } }
public Car Create(Car car) { if (car.Model == null || car.Model.Length < 1) { throw new ArgumentException("wrong!!"); } if (string.IsNullOrEmpty(car.Manufacturer)) { throw new ArgumentException("Car needs Manufacturer"); } if (string.IsNullOrEmpty(car.Color)) { throw new ArgumentException("Car needs a color!"); } return(_carRepo.CreateCar(car)); }
public ActionResult Create(Car car) { try { if (ModelState.IsValid) { carRepo.CreateCar(car); return(RedirectToAction(nameof(Index))); } else { return(View(car)); } } catch (Exception ex) { return(View("Error", new ErrorViewModel { RequestId = "0", Description = $"Esception message: '{ex.Message}'" })); } }
public async Task <IHttpActionResult> AddCar(CreateCar car) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var carToAdd = new Common.Models.Car { Color = (Common.Models.CarColor)car.Color, PlateNumber = car.PlateNumber }; var createdCar = await _repository.CreateCar(carToAdd); var result = new Car { Id = createdCar.Id, PlateNumber = createdCar.PlateNumber, Color = (CarColor)createdCar.Color }; return(Created <Car>(new Uri(Request.RequestUri.ToString() + createdCar.Id), result)); }
public void InsertCar(CAR car) { carRepo.CreateCar(car); }
public void CreateCar(CarModel car) { _repository.CreateCar(ToCar(car)); }
public bool CreateCar(Car car) { return(_carRepository.CreateCar(car)); }
public async Task <Car> CreateCar(Car car) { return(await _carRepository.CreateCar(car)); }
public object CreateCar(object car) { // Seguindo o DIP utilizamos a abstracao do repositorio. return(_carRepository.CreateCar(car)); }
public Car CreateCar(Car car) { Car createdCar = carRepository.CreateCar(car); return(createdCar); }