public MyShowThumbnail<IMyShowArt> GetAnyMyShowArtForUser(Guid userId)
        {
            var myShowService = new MyShowService(Ioc.GetInstance<IMyShowRepository>());
            var artService = new ArtService(Ioc.GetInstance<IArtRepository>());
            var photoService = new PhotoService(Ioc.GetInstance<IPhotoRepository>());

            var myShows = myShowService.GetMyShowsForUser(userId);

            var myShowArts = GetAllMyShowArt().Where(x => myShows.Any(y => y.MyShowId == x.MyShowId)).OrderByDescending(z => z.CreatedDate);

            foreach (var myShowArt in myShowArts)
            {
                var art = artService.GetArt(myShowArt.ArtId);
                var photo = photoService.GetPhotoThumbnail(art.PhotoId);
                if (photo.Thumbnail)
                    return new MyShowThumbnail<IMyShowArt>(myShowArt, photo);
            }
            
            return null;
        }
        public MyShowThumbnail <IMyShowArt> GetAnyMyShowArtForUser(Guid userId)
        {
            var myShowService = new MyShowService(Ioc.GetInstance <IMyShowRepository>());
            var artService    = new ArtService(Ioc.GetInstance <IArtRepository>());
            var photoService  = new PhotoService(Ioc.GetInstance <IPhotoRepository>());

            var myShows = myShowService.GetMyShowsForUser(userId);

            var myShowArts = GetAllMyShowArt().Where(x => myShows.Any(y => y.MyShowId == x.MyShowId)).OrderByDescending(z => z.CreatedDate);

            foreach (var myShowArt in myShowArts)
            {
                var art   = artService.GetArt(myShowArt.ArtId);
                var photo = photoService.GetPhotoThumbnail(art.PhotoId);
                if (photo.Thumbnail)
                {
                    return(new MyShowThumbnail <IMyShowArt>(myShowArt, photo));
                }
            }

            return(null);
        }
        private void DeletePic(string pictureIdStr)
        {
            var pictureId = new Guid(pictureIdStr);

            var myShowArt = GetPicture(pictureId);
            var myShowArtId = myShowArt.MyShowArtId.ToString();
            var photoId = myShowArt.Art.Photo.PhotoId.ToString();
            var filename = myShowArt.Art.Photo.FileName.ToString();

            var artService = new ArtService(Ioc.GetInstance<IArtRepository>());
            var photoService = new PhotoService(Ioc.GetInstance<IPhotoRepository>());
            var myShowArtService = new MyShowArtService(Ioc.GetInstance<IMyShowArtRepository>());

            using (IUnitOfWork uow = UnitOfWork.Begin())
            {
                photoService.Delete(myShowArt.Art.Photo);
                artService.Delete(myShowArt.Art);
                myShowArtService.Delete(myShowArt);

                uow.Commit();
            }

            log.WriteLine("Deleted myShowArt Id: " + myShowArtId);
            log.WriteLine("Deleted photo Id: " + photoId + "and filename: " + filename);
            log.WriteLine("Deleted picture Id: " + pictureId);

            Response.Redirect(LinkBuilder.MyPicturesLink(new Guid(hdnShowId.Value)));
        }
        public bool CreateArt(IPhoto photo, Guid? showId)
        {
            bool final = false;
            var artId = Guid.NewGuid();

            var artService = new ArtService(Ioc.GetInstance<IArtRepository>());
            var myShowService = new MyShowService(Ioc.GetInstance<IMyShowRepository>());
            var spService = new MyShowArtService(Ioc.GetInstance<IMyShowArtRepository>());

            var userId = new Guid(Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString());
            var myShowId = myShowService.GetMyShow(showId.Value, userId).MyShowId;

            var date = DateTime.UtcNow;

            Art p = new Art
            {
                CreatedDate = date,
                UpdatedDate = date,
                PhotoId = photo.PhotoId,
                ArtId = artId,
                Notes = photo.Notes,
                UserId = photo.UserId,
                ShowId = showId
            };


            var combinedSuccess = true;
            bool success = false;

            var photoService = new PhotoService(Ioc.GetInstance<IPhotoRepository>());
            photoService.Save(photo, out success);

            combinedSuccess = combinedSuccess && success;

            artService.Save(p, out success);

            combinedSuccess = combinedSuccess && success;

            var myShowArt = new MyShowArt
            {
                CreatedDate = date,
                UpdatedDate = date,
                MyShowId = myShowId,
                MyShowArtId = Guid.NewGuid(),
                ArtId = artId
            };

            spService.Save(myShowArt, out success);

            combinedSuccess = combinedSuccess && success;

            return combinedSuccess;
        }
        public override void ProcessRequest(HttpContextBase context)
        {
            //System.Threading.Thread.Sleep(4000);
            HttpRequestBase request = context.Request;
            var showIdStr = request.QueryString["s"];
            var userIdStr = request.QueryString["u"];
            HttpResponseBase response = context.Response;

            var final = string.Empty;

            if ( EmptyNullUndefined(showIdStr) || EmptyNullUndefined(userIdStr) )
            {
                final = GetNoImagesFound();

                response.ContentType = "application/json";
                response.ContentEncoding = Encoding.UTF8;
                response.Write(final);
                response.End();
            }

            var showId = new Guid(showIdStr);
            var userId = new Guid(userIdStr);

            MyShowService myShowService = new MyShowService(Ioc.GetInstance<IMyShowRepository>());
            MyShowArtService myShowArtService = new MyShowArtService(Ioc.GetInstance<IMyShowArtRepository>());
            ArtService artService = new ArtService(Ioc.GetInstance<IArtRepository>());

            var myShow = myShowService.GetMyShow(showId, userId);
            IList<KeyValuePair<Art, IMyShowArt>> art = new List<KeyValuePair<Art, IMyShowArt>>();

            if (myShow != null)
            {
                var myShowArts = myShowArtService.GetMyShowArtByMyShow(myShow.MyShowId);

                myShowArts.ToList().ForEach(x =>
                {
                    art.Add(new KeyValuePair<Art, IMyShowArt>((Art)artService.GetArt(x.ArtId), x));
                });
            }

            if (art == null || art.Count <= 0)
            {
                final = GetNoImagesFound();
            }

            //If there are images and no errors so far then process
            if (string.IsNullOrEmpty(final))
            {
                var json = new ImageJSONifier("records");

                foreach (var a in art)
                {
                    if (a.Key == null || a.Key.Photo == null) continue;

                    json.Add(new ImageItem 
                    { 
                        Image = "/images/Shows/" + a.Key.Photo.FileName,
                        Description = a.Key.Notes,
                        Title = a.Key.Photo.NickName,
                        Link = string.Format("DeletePicture.aspx?picid={0}&showId={1}", a.Value.MyShowArtId.ToString(), showId.ToString())
                    });
                }

                final = json.GetFinalizedJSON();
            }

            response.ContentType = "application/json";
            response.ContentEncoding = Encoding.UTF8;
            response.Write(final);

        }
        public override void ProcessRequest(HttpContextBase context)
        {
            HttpRequestBase request = context.Request;
            var userIdStr = request.QueryString["u"];
            HttpResponseBase response = context.Response;

            var final = string.Empty;

            if (EmptyNullUndefined(userIdStr))
            {
                final = GetNoImagesFound();

                response.ContentType = "application/json";
                response.ContentEncoding = Encoding.UTF8;
                response.Write(final);
                response.End();
            }

            var userId = new Guid(userIdStr);

            var artService = new ArtService(Ioc.GetInstance<IArtRepository>());
            var posterService = new PosterService(Ioc.GetInstance<IPosterRepository>());

            var art = artService.GetArtByUser(userId).Cast<Art>().Where(y => y.Show != null).ToList();
            var posters = posterService.GetByUser(userId).Cast<Poster>().Where(z => z.ShowId != null).ToList();

            //If there are no art or posters then return no images found
            if ((art == null && posters == null) || (art.Count <= 0 && posters.Count <= 0))
            {
                final = GetNoImagesFound();

                response.ContentType = "application/json";
                response.ContentEncoding = Encoding.UTF8;
                response.Write(final);
                response.End();
            }

            var allImages = (from a in art
                             select new ImageItem
                             {
                                 Image = ShowImagesFolder + a.Photo.FileName,
                                 Description = a.Photo.Notes,
                                 Title = a.Photo.NickName,
                                 ShowDate = a.Show.ShowDate.Value
                             }).ToList();

            allImages.AddRange((from p in posters
                                select new ImageItem
                                {
                                    Image = ShowImagesFolder + p.Photo.FileName,
                                    Description = p.Photo.Notes,
                                    Title = p.Photo.NickName,
                                    ShowDate = p.Show.ShowDate.Value
                                }).ToList());

            var json = new ImageJSONifier("records", allImages.OrderBy(y => y.ShowDate));

            final = json.GetFinalizedJSON();

            response.ContentType = "application/json";
            response.ContentEncoding = Encoding.UTF8;
            response.Write(final);
        }