Exemplo n.º 1
0
 protected string GetNoImagesFound()
 {
     var json = new ImageJSONifier("records");
     var loc = NoImagesLocation;
     json.Add(new ImageItem { Image = loc, Thumb = loc, Title = "No Images Found", Description = "Upload posters or pictures of your own so everyone can see what this show was like" });
     return json.GetFinalizedJSON();
 }
        public override void ProcessRequest(HttpContextBase context)
        {
            HttpRequestBase request = context.Request;
            var showIdStr = request.QueryString["s"];
            var showDateStr = request.QueryString["d"];
            HttpResponseBase response = context.Response;

            var final = string.Empty;

            if (EmptyNullUndefined(showIdStr) && EmptyNullUndefined(showDateStr))
            {
                final = GetNoImagesFound();

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

            var showService = new ShowService(Ioc.GetInstance<IShowRepository>());
            if (string.IsNullOrEmpty(showIdStr))
            {
                DateTime date;
                var success = DateTime.TryParse(showDateStr, out date);

                if (!success)
                    return;

                var s = showService.GetShow(date);

                if (s == null)
                    return;

                showIdStr = s.ShowId.ToString();
            }

            var showId = new Guid(showIdStr);

            IPhotoRepository photoRepo = new PhotoRepository(new PhishDatabase(new ConnectionString(new AppConfigManager(), connKey)));

            PhotoService photoService = new PhotoService(photoRepo);

            var photos = photoService.GetPhotosByShow(showId).Where(x => x.Thumbnail == false).ToList();

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

            if (string.IsNullOrEmpty(final))
            {
                var json = new ImageJSONifier("records");

                foreach (var photo in photos)
                {
                    var path = (PhotoType)photo.Type != PhotoType.TicketStub ? ShowImagesFolder : TicketStubImagesFolder;

                    json.Add(new ImageItem
                    {
                        Image = path + photo.FileName,
                        Description = photo.Notes,
                        Title = photo.NickName,
                        //Thumb =  //This is a consideration.  If we want to go through the trouble of using the thumb or not
                    });
                }

                final = json.GetFinalizedJSON();
            }

            response.ContentType = "application/json";
            response.ContentEncoding = Encoding.UTF8;
            response.Write(final);
        }
        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);
        }