Exemplo n.º 1
0
        public AdvertisementItemPhotosNames SaveAdvertisementPhotos(IFormFileCollection files)
        {
            var photosPathsModel = new AdvertisementItemPhotosNames();
            var filesCount       = files.Count;

            for (int i = 0; i < filesCount; i++)
            {
                using (Stream readStream = files.GetFile(this.appFilesNamesHelper.GetPhotoNameInForm(i)).OpenReadStream())
                {
                    var newFileName  = this.appFilesNamesHelper.GetPhotoRandomUniqueName("jpg");
                    var newFilePath  = String.Concat(this.appFilesPathHelper.GetAdvertisementMainPhotosPath(), "/", newFileName);
                    var resizedPhoto = ResizePhoto(readStream);
                    resizedPhoto.Save(newFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    photosPathsModel.PhotosNames.Add(newFileName);
                    //first file (name ends with "0") will be main photo
                    if (i == 0)
                    {
                        var minPhotoName   = "mini" + newFileName;
                        var minImage       = CreateMinPhoto(readStream);
                        var newMinFilePath = Path.Combine(this.appFilesPathHelper.GetAdvertisementMinPhotosMainPath(), minPhotoName);
                        minImage.Save(newMinFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        photosPathsModel.PhotosNames.Add(minPhotoName);
                    }
                }
            }
            return(photosPathsModel);
        }
Exemplo n.º 2
0
 public IActionResult UploadAdvertisementItemPhotos()
 {
     try
     {
         AdvertisementItemPhotosNames photosPaths = this.advertisementItemPhotosUploader.SaveAdvertisementPhotos(Request.Form.Files);
         return(Json(photosPaths));
     }
     catch (Exception exc)
     {
         this.logger.LogError("Wystąpił błąd podcza uploadu zdjęć ogłoszenia: " + exc);
         Response.StatusCode = (int)HttpStatusCode.InternalServerError;
         return(Json(new ErrorResponse {
             ErrorMessage = exc.Message
         }));
     }
 }
Exemplo n.º 3
0
        private NewAdvertisementItem CreateNewAdvertisementItemModel(AdvertisementItemPhotosNames photosListModel)
        {
            var location = this.gpsLocationService.GetLocation();
            NewAdvertisementItem model = new NewAdvertisementItem();

            model.Id = editModel != null ? editModel.Id : -1;
            model.AdvertisementTitle       = advertisementTitle.Text;
            model.AdvertisementDescription = advertisementDescription.Text;
            model.Size               = this.size;
            model.Latitude           = location.Latitude;
            model.Longitude          = location.Longitude;
            model.IsOnlyForSell      = rdBtnOnlyForSell.Checked;
            model.AdvertisementPrice = Int32.Parse(advertisementPrice.Text);
            model.Category           = this.categoryInfoModel;
            model.PhotosNames        = photosListModel.PhotosNames;

            return(model);
        }