public IResult Add(CarImageDto carImageDto) { var result = BusinessRules.Run(CheckIfImageLimitExceeded(carImageDto.CarId)); if (result != null) { return(result); } var isFileUploaded = FileHelper.UploadFile(carImageDto.Image); if (!isFileUploaded.Success) { return(new ErrorResult(isFileUploaded.Message)); } var carImage = new CarImage { CarId = carImageDto.CarId, ImagePath = isFileUploaded.Data }; _carImageDal.Add(carImage); return(new SuccessResult(Messages.CarImage.Add(isPlural: false))); }
public IActionResult Add([FromForm] CarImageDto carImage, List <IFormFile> files) { var result = _carImageService.Add(carImage, files); if (result.Success) { return(Created("", result)); } return(BadRequest(result)); }
public IActionResult Add([FromForm] CarImageDto carImageDto) { var result = _carImageService.Add(carImageDto); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult Upload([FromForm] CarImageDto carImageDTO) { var result = _carImageService.Update(carImageDTO); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <IActionResult> Update([FromForm] CarImageDto imageDto, IFormFile file) { var result = await _carImageService.UpdateAsync(_mapper.Map <CarImage>(imageDto), file); if (result.Success) { return(Created("", result)); } return(BadRequest()); }
public IResult Update(CarImageDto carImageDto) { var dbImage = _carImageDal.Get(ci => ci.id == carImageDto.Id); if (dbImage == null) { return(new ErrorResult("Image nor found")); } FileHelper.UpdateImageFile(carImageDto.ImageFile, dbImage.ImagePath); return(new SuccessResult(Messages.ImagesAdded)); }
public IActionResult Add([FromForm] CarImageDto carImageDto) { CarImage carImage = new CarImage(); carImage.CarId = carImageDto.CarId; var result = _carImageService.Add(carImageDto.File, carImage); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
private async Task UploadCarImage(CarImageDto carImageDto, Car car) { var carImageId = await GetNextValueCarImage(); var newCarImage = this.mapper.Map <CarImage>(carImageDto); newCarImage.Id = carImageId; newCarImage.Car = car; await this.context.CarImages.AddAsync(newCarImage); await this.context.SaveChangesAsync(); }
public IResult Add(CarImageDto entity, List <IFormFile> files) { var result = BusinessRules.Run(CheckImageCount(entity.CarId)); if (result != null) { return(result); } foreach (var file in files) { entity.ImagePath = Guid.NewGuid() + Path.GetExtension(file.FileName); _fileHelper.Upload(entity.ImagePath, file); _carImageDal.Add(_mapper.Map <CarImage>(new CarImageDto { CarId = entity.CarId, ImagePath = entity.ImagePath })); } return(new SuccessResult()); }
public IResult Add(CarImageDto carImageDto) { var result = BusinessRules.Run(CheckIfImageLimitExceded(carImageDto.CarId)); if (result != null) { return(result); } CarImage carImage = new CarImage { CarId = carImageDto.CarId, ImagePath = FileHelper.UploadImageFile(carImageDto.ImageFile), Date = DateTime.Now }; _carImageDal.Add(carImage); return(new SuccessResult(Messages.ImagesAdded)); }
public IDataResult <List <CarImageDto> > GetAll() { List <CarImageDto> carImageDtos = new List <CarImageDto>(); foreach (var item in _carImageDal.GetAll()) { CarImageDto carImageDto = new CarImageDto { ImagePath = item.ImagePath }; carImageDtos.Add(carImageDto); } var results = carImageDtos; if (results.Count != 0) { return(new SuccessDataResult <List <CarImageDto> >(results)); } return(new ErrorDataResult <List <CarImageDto> >(Messages.CarPhotosNotFound)); }
public async Task <CarDto> AddCar(CarDto car) { var brand = await this.context.CarBrands .Include(cars => cars.Cars) .SingleOrDefaultAsync(carBrand => carBrand.Id == car.CarModelId); var engine = await this.context.StatusEngines .Include(cars => cars.Cars) .SingleOrDefaultAsync(carBrand => carBrand.Id == car.EngineTypeId); var carId = await GetNextValue(); var newCar = new Car { Id = carId, CarBrand = brand, CarBrandId = car.CarBrandId, CarModelId = car.CarModelId, Door = car.Door, EngineTypeId = car.EngineTypeId, EngineType = engine, Price = car.Price, ProductionYear = car.ProductionYear, UserId = car.UserId, }; await this.context.Cars.AddAsync(newCar); await this.context.SaveChangesAsync(); var imageDto = new CarImageDto { CarId = carId, ImagePath = car.ImagePath }; await this.UploadCarImage(imageDto, newCar); return(this.mapper.Map <CarDto>(newCar)); }
public IResult Update(CarImageDto entity) { _carImageDal.Update(_mapper.Map <CarImage>(entity)); return(new SuccessResult()); }