Пример #1
0
        public IResult AddCarImages(AddCarImagesDto addCarImagesDto)
        {
            var result = BusinessRules.Run(
                CheckIfCarImagesMoreThanFive(addCarImagesDto.CarImages.Length, addCarImagesDto.CarId),
                CheckIfImageFile(addCarImagesDto.CarImages)

                );

            if (result != null)
            {
                return(new ErrorResult(result.Message));
            }

            var imageUrls = _fileHelper.WriteFile(Consts.ImageUploadUrl, addCarImagesDto.CarImages);

            foreach (var imageUrl in imageUrls)
            {
                _carImagesDal.Add(new CarImage
                {
                    CarId     = addCarImagesDto.CarId,
                    ImagePath = imageUrl
                });
            }

            return(new SuccessResult(Messages.CarImagesAdded));
        }
        public IResult Add(CarImage carImages)
        {
            var result = BusinessRules.Run(CheckCountOfCarImages(carImages.CarID));

            if (result != null)
            {
                return(result);
            }
            _carImagesDal.Add(carImages);
            return(new SuccessResult(Messages.CarImagesAdded));
        }
        public IResult Add(CarImage entity)
        {
            var result = BusinessRules.Run(CheckCarImageCount());

            if (result != null)
            {
                return(result);
            }
            entity.Date = DateTime.Now;
            _carImageDal.Add(entity);
            return(new SuccessResult(Messages.CarImageAdded));
        }
        public IResult Add(Image image, CarImage carImages)
        {
            IResult result = BusinessRules.Run(CheckCarImageLimit(carImages.CarId));


            if (result != null)
            {
                return(result);
            }
            _carImagesDal.Add(carImages);
            return(new SuccessResult("Araba resmi başarıyla eklendi."));
        }
Пример #5
0
        public IResult Add(IFormFile file, CarImage carImage)
        {
            IResult result = BusinessRules.Run(CheckImageLimitExceeded(carImage.CarId));

            if (result != null)
            {
                return(result);
            }
            carImage.ImagePath = FileHelper.Add(file);
            carImage.Date      = DateTime.Now;
            _carImageDal.Add(carImage);
            return(new SuccessResult());
        }
Пример #6
0
        //[ValidationAspect(typeof(CarImagesValidator))]
        public IResult Add(IFormFile formFile, CarImages entity)
        {

           var result= BusinessRules.Run(CheckImagesLimited(entity.CarId));
            
            if (result != null)
            {
                return result;
            }
            entity.ImagePath = FileHelper.Add(formFile);
            entity.Date = DateTime.Now;
            _carImagesDal.Add(entity);

            return new SuccessResult(SuccessMessages.CarAdded);
        }
Пример #7
0
 public IResult Add(Car car)
 {
     CheckValidator.Validate(new CarValidator(), car);
     cardal.Add(car);
     if (!CheckCarImageExist(car.Id))
     {
         carImagesDal.Add(new CarImage
         {
             CarId       = car.Id,
             CreatedDate = DateTime.UtcNow,
             ImagePath   = "thumbnail.png"
         });
     }
     return(new SuccessResult(Messages.Add_Message(Messages.GetNameDict[typeof(Car)])));
 }
Пример #8
0
        public IResult Add(CarImages carImages)
        {
            IResult result = BusinessRules.Run(CheckIfCarImagesLimited(carImages.CarId));

            if (result != null)
            {
                return(result);
            }
            if (CheckIfCarImagesLimited(carImages.CarId).Success)
            {
                _carImagesDal.Add(carImages);
                return(new SuccessResult(Message.AddSuccessCarImages));
            }
            return(new ErrorResult("Araba Resmi Eklenmedi"));
        }
Пример #9
0
        public IResult Add(IFormFile file, CarImages carImages)
        {
            IResult result = BusinessRules.Run(
                CheckIfImageLimit(carImages.CarId)
                );

            if (result != null)
            {
                return(result);
            }

            carImages.ImagePath = FileHelper.AddAsync(file);
            carImages.Date      = DateTime.Now;
            _carImagesDal.Add(carImages);
            return(new SuccessResult());
        }
Пример #10
0
        public IResult Add(CarImages carImages, IFormFile file)
        {
            IResult result = BusinessRules.Run(
                CheckIfImageLimitExpired(carImages.CarId),
                CheckIfImageExtensionValid(file)
                );

            if (result != null)
            {
                return(result);
            }

            carImages.ImagePath = FileHelper.Add(file);
            carImages.Date      = DateTime.Now;
            _carImageDal.Add(carImages);
            return(new SuccessResult());
        }
Пример #11
0
        public IResult Add(IFormFile image, CarImages carImage)
        {
            var imageCount = _carImageDal.GetAll(c => c.CarId == carImage.CarId).Count;

            if (imageCount >= 5)
            {
                return(new ErrorResult(Messages.ImageLimit));
            }

            var imageResult = FileHelper.Add(image);

            if (!imageResult.Success)
            {
                return(new ErrorResult(imageResult.Message));
            }
            carImage.ImagePath = imageResult.Message;
            _carImageDal.Add(carImage);
            return(new SuccessResult(Messages.AddedCarImages));
        }
Пример #12
0
        public IResult Add(IFormFile image, CarImage carImage)
        {
            var imageCount = _carImagesDal.GetAll(c => c.CarId == carImage.CarId).Count;

            if (imageCount >= 10)
            {
                return(new ErrorResult("One car must have 10 or less images"));
            }

            var imageResult = FileHelper.Upload(image);

            if (!imageResult.Success)
            {
                return(new ErrorResult(imageResult.Message));
            }
            carImage.ImagePath = imageResult.Message;
            _carImagesDal.Add(carImage);
            return(new SuccessResult("Car image added"));
        }
        public IResult Add(CarImages images)
        {
            //Resimler projeniz içerisinde bir klasörde tutulacaktır.
            //Bir arabanın en fazla 5 resmi olabilir.

            IResult result = BusinessRules.Run(CheckDirectoryExistOrNot(path), CheckImageCount(images.CarId));

            if (result != null)
            {
                return(new ErrorResult());
            }

            //Resimler yüklendiği isimle değil, kendi vereceğiniz GUID ile dosyalanacaktır.
            images.ImagePath = path + "\\" + Guid.NewGuid().ToString();

            //Resmin eklendiği tarih sistem tarafından atanacaktır.
            images.DateTime = DateTime.Now;

            _carImageDal.Add(images);
            return(new SuccessResult(Messages.Added));
        }
Пример #14
0
        public IResult Add(int id, IFormFile files)
        {
            IResult result = BusinessRules.Run(CheckImagesLimit(id), CheckTheCarExists(id));

            if (result != null)
            {
                return(new ErrorResult());
            }

            string   FileName = Guid.NewGuid().ToString();
            CarImage carImg   = new CarImage
            {
                CarId       = id,
                CreatedDate = DateTime.UtcNow,
                ImagePath   = FileName
            };

            carImagesDal.Add(carImg);
            var fileResult = fileProcess.Upload(FileName, files);

            return(new SuccessResult(Messages.Add_Message(Messages.GetNameDict[typeof(CarImage)])));
        }
Пример #15
0
        public IResult Add(CarImagesOperationDto carImagesOperationDto)
        {
            var result = BusinessRules.Run(
                CheckCarImageCount(carImagesOperationDto.CarId),
                CheckIfCarId(carImagesOperationDto.CarId));

            if (result != null)
            {
                return(result);
            }

            foreach (var file in carImagesOperationDto.Images)
            {
                _carImageDal.Add(new CarImages
                {
                    CarId     = carImagesOperationDto.CarId,
                    ImagePath = FileProcessHelper.Upload(DefaultNameOrPath.ImageDirectory, file).Data
                });
            }

            return(new SuccessResult(Messages.CarImagesAdded));
        }
Пример #16
0
        private IResult AddMetod(Image image, CarImages carImage)
        {
            string path       = Environment.CurrentDirectory + "\\wwwroot" + "\\Images\\";
            string randomName = null;
            string type       = null;


            if (image.Files != null && image.Files.Length > 0)
            {
                randomName = Guid.NewGuid().ToString();
                type       = Path.GetExtension(image.Files.FileName);

                if (type != ".jpeg" && type != ".png" && type != ".jpg")
                {
                    return(new ErrorResult("Wrong file type."));
                }

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                using (FileStream fs = File.Create(path + randomName + type))
                {
                    image.Files.CopyTo(fs);
                    fs.Flush();
                    carImage.ImagePath = (path + randomName + type).Replace("\\", "/");
                    carImage.Date      = DateTime.Now;
                }

                _carImageDal.Add(carImage);
                return(new SuccessResult("Car image added"));
            }

            return(new ErrorResult("File doesn't exists."));
        }
Пример #17
0
 public IResult Add(CarImages carimages)
 {
     _carimagesDal.Add(carimages);
     return(new Success(Messages.CarImagesAdded));
 }