Пример #1
0
        public IActionResult AddAsync([FromForm] IFormFile image, [FromForm] string carImageString)
        {
            if (image == null)
            {
                return(BadRequest("File not found"));
            }
            CarImage carImage = JsonConvert.DeserializeObject <CarImage>(carImageString);
            string   firstURL = _webHostEnvironment.WebRootPath;
            //string firstURL = "http://127.0.0.1:8080";
            string path = firstURL + @"\images\";
            string newFileNameWithGUID = Guid.NewGuid().ToString() + Path.GetExtension(image.FileName);

            bool fileCreate = ImageOperations.CopyFileToServer(image, path, newFileNameWithGUID);

            if (!fileCreate)
            {
                return(BadRequest(Messages.FileCreateError));
            }

            carImage.ImagePath = path + newFileNameWithGUID;
            var result = _carImageService.Add(carImage);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }