public JsonResult UploadAlbumPicture(int albumId, HttpPostedFileBase pictureFile)
        {
            var album = _customerAlbumPictureService.GetCustomerAlbumById(albumId);


            if (album.Pictures.Count >= _mobSocialSettings.MaximumMainAlbumPictures)
            {
                throw new ApplicationException("You may only upload up to " + _mobSocialSettings.MaximumMainAlbumPictures + " pictures at this time.");
            }

            // Verify that the user selected a file
            if (pictureFile != null && pictureFile.ContentLength > 0)
            {
                // extract only the fielname
                var fileName = Path.GetFileName(pictureFile.FileName);


                string albumFolder = string.Format("~/Content/Images/Albums/{0}/{1}",
                                                   album.CustomerId, albumId);

                var albumPicturePath = Path.Combine(_webHelper.MapPath(albumFolder), fileName);
                albumPicturePath = FileUtility.FilePathAddNumberIfExists(albumPicturePath, _webHelper.MapPath(albumFolder));

                var directoryPath = Path.GetDirectoryName(albumPicturePath);
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                pictureFile.SaveAs(albumPicturePath);

                var thumbnailFileName = Path.GetFileNameWithoutExtension(albumPicturePath) + "-thumbnail" + Path.GetExtension(albumPicturePath);
                var thumbnailPath     = Path.Combine(_webHelper.MapPath(albumFolder), thumbnailFileName);
                var thumbnailWidth    = _mobSocialSettings.CustomerAlbumPictureThumbnailWidth;
                var resizedPicture    = _customerAlbumPictureService.CreateThumbnailPicture(pictureFile.GetPictureBits(), thumbnailWidth, pictureFile.ContentType);

                System.IO.File.WriteAllBytes(thumbnailPath, resizedPicture);

                var albumPicture = new CustomerAlbumPicture()
                {
                    Album           = album,
                    CustomerAlbumId = albumId,
                    DateCreated     = DateTime.Now,
                    DisplayOrder    = 0,
                    ThumbnailUrl    = thumbnailPath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty),
                    Url             = albumPicturePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty)
                };

                _customerAlbumPictureService.Insert(albumPicture);

                return(Json(albumPicture));
            }


            return(Json(null));
        }
Esempio n. 2
0
 public void Delete(CustomerAlbumPicture customerAlbumPicture)
 {
     _customerAlbumPictureRepository.Delete(customerAlbumPicture);
 }
Esempio n. 3
0
 public void Insert(CustomerAlbumPicture customerAlbumPicture)
 {
     _customerAlbumPictureRepository.Insert(customerAlbumPicture);
 }