コード例 #1
0
        public IResult Add(IFormFile file, CarImage carImage)
        {
            var businessRuleResults = BusinessRules.Run(CheckIfCarImageLimitExceeded(carImage.CarId));

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


            carImage.ImagePath = _uploadService.Add(file);
            carImage.Date      = DateTime.Now;
            _carImageDal.Add(carImage);
            return(new SuccessResult(Messages.CarImageAdded));
        }
コード例 #2
0
        public Result Upload(UploadDto dto, List <IFormFile> formFiles)
        {
            try
            {
                var files = Request.Form.Files;
                if (files.Count > 0)
                {
                    var file            = files[0];
                    var webRootPath     = _hostingEnvironment.WebRootPath;
                    var contentRootPath = _hostingEnvironment.ContentRootPath;
                    var filePath        = webRootPath + @"/upload/" + file.FileName;
                    using (var stream = System.IO.File.Create(filePath))
                    {
                        file.CopyTo(stream);
                        stream.Flush();
                    }

                    dto.Route    = filePath;
                    dto.Name     = Path.GetFileNameWithoutExtension(filePath);
                    dto.FileName = Path.GetExtension(file.FileName);
                }
                var result = _uploadService.Add(dto);
                if (result.Status)
                {
                    result.Message = "/Upload/Index";
                }
                return(result);
            }
            catch (Exception ex)
            {
                Logger.Error($"错误描述,{ex}");
                return(new Result {
                    Status = false
                });
            }
        }