Ejemplo n.º 1
0
        public AjaxControlToolkit.Slide[] GetShowPictures(String contextKey)
        {
            if (String.IsNullOrEmpty(contextKey))
                return null;

            var showId = new Guid(contextKey);

            try
            {

                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)
                {
                    var linkBuilder = new LinkBuilder();
                    var myPictureLink = linkBuilder.MyPicturesLink(showId);

                    var link = string.Format("<a href=\"{0}\">Upload your pictures here!</a>", myPictureLink);
                    
                    var name = string.Format("There are no pictures uploaded for this show. {0} You could be the first!", link);

                    return GetNoImagesFoundDirectory(name, string.Empty);
                }

                // create generic empty list of slides
                List<AjaxControlToolkit.Slide> list = new List<AjaxControlToolkit.Slide>();
                String justFileName;
                String displayedFileTitleOnSlider;
                String displayedFileDescriptionOnSlider;

                foreach (var photo in photos)
                {
                    // get complete filename
                    justFileName = photo.FileName;

                    // get title
                    displayedFileTitleOnSlider = photo.NickName;

                    // set description
                    displayedFileDescriptionOnSlider = photo.Notes;

                    // add file to list of slides
                    list.Add(new AjaxControlToolkit.Slide(showImagesFolder + justFileName, displayedFileTitleOnSlider, displayedFileDescriptionOnSlider));
                }

                return (list.ToArray());
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        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);
        }