Пример #1
0
        public ActionResult UploadImage(string bandUrl, string galleryName, Guid batchId)
        {
            var file     = Request.Files[0];
            var filename = HttpContext.SaveImage(file);

            var image = new ImageModel
            {
                ImageId = Guid.NewGuid(),
                Url     = filename,
                Caption = file.FileName,
                BatchId = batchId
            };

            // if for a gallery, add that image to the gallery
            if (!String.IsNullOrEmpty(galleryName))
            {
                Guid galleryId = DataRepository.GetGallery(galleryName).GalleryId;
                image.GalleryId = galleryId;
            }

            DataRepository.AddImage(image, loggedUserGuid);

            // if for a band, associate image with band
            if (!bandUrl.IsNullOrWhiteSpace())
            {
                var bandId = DataRepository.GetBandId(bandUrl);
                if (bandId != null && DataRepository.UserIsMemberOfBand(loggedUserGuid, (Guid)bandId))
                {
                    DataRepository.AddBandImage(image.ImageId, (Guid)bandId);
                }
            }

            return(Json(new { success = true }));
        }