private void BindPoster()
        {
            var posterId = string.IsNullOrEmpty(Request.QueryString["id"]) ? EmptyGuid : new Guid(Request.QueryString["id"]);

            if (posterId == EmptyGuid)
            {
                ShowError("There was an error with your request please go back and try again.");
                phMain.Visible = false;
                return;
            }

            hdnId.Value = posterId.ToString();

            var poster = posterService.GetPoster(posterId);

            var photoService = new PhotoService(Ioc.GetInstance<IPhotoRepository>());

            var photo = photoService.GetPhoto(poster.PhotoId);

            imgDisplayFull.ImageUrl = LinkBuilder.GetImageLinkByFileName(photo.FileName);

            ddlShow.SelectedValue = photo.ShowId.ToString();

            txtCreator.Text = poster.Creator;
            txtLength.Text = poster.Length.ToString();
            txtNotes.Text = poster.Notes;
            txtNumber.Text = poster.Number.ToString();
            txtReleaseDate.Text = poster.ReleaseDate != null ? poster.ReleaseDate.Value.ToString("MM/dd/yyyy") : string.Empty;
            txtTechnique.Text = poster.Technique;
            txtTitle.Text = poster.Title;
            txtTotal.Text = poster.Total.ToString();
            txtWidth.Text = poster.Width.ToString();
            ddlStatus.SelectedValue = poster.Status.ToString();
        }
Example #2
0
        private void BindArt()
        {
            var artId = string.IsNullOrEmpty(Request.QueryString["id"]) ? EmptyGuid : new Guid(Request.QueryString["id"]);

            if (artId == EmptyGuid)
            {
                ShowError("There was an error with your request please go back and try again.");
                phMain.Visible = false;
                return;
            }

            hdnId.Value = artId.ToString();

            var art = artService.GetArt(artId);

            var photoService = new PhotoService(Ioc.GetInstance<IPhotoRepository>());

            var photo = photoService.GetPhoto(art.PhotoId);

            txtNotes.Text = art.Notes;
            ddlShow.SelectedValue = photo.ShowId.ToString();
            imgDisplayFull.ImageUrl = LinkBuilder.GetImageLinkByFileName(photo.FileName);
            txtCreator.Text = art.Creator;
        }
        private void BindTicketStub()
        {
            var ticketStubId = string.IsNullOrEmpty(Request.QueryString["id"]) ? EmptyGuid : new Guid(Request.QueryString["id"]);

            if (ticketStubId == EmptyGuid)
            {
                ShowError("There was an error with your request please go back and try again.");
                phMain.Visible = false;
                return;
            }

            hdnId.Value = ticketStubId.ToString();

            var ticketStub = ticketStubService.GetTicketStub(ticketStubId);

            var photoService = new PhotoService(Ioc.GetInstance<IPhotoRepository>());

            var photo = photoService.GetPhoto(ticketStub.PhotoId);

            txtNotes.Text = ticketStub.Notes;
            ddlShow.SelectedValue = photo.ShowId.ToString();
            imgDisplayFull.ImageUrl = LinkBuilder.GetImageLinkByFileName(photo.FileName);
            chkPTBM.Checked = ticketStub.Original;
        }
        public void Brih(Guid showId)
        {
            IImageMediaFormats imageMediaFormats = Ioc.GetInstance<IImageMediaFormats>();
            IPhotoRepository photoRepo = Ioc.GetInstance<IPhotoRepository>();

            ImageResizerService imageResizerService = new ImageResizerService();
            PhotoService photoService = new PhotoService(photoRepo);

            bool compiledSuccess = true;

            var posted = fuPicture.PostedFile;

            if (posted == null)
            {
                return;
                //ERROR MESSAGE
                //return new FileUploadJsonResult { Data = new { Src = "", ErrorMessage = "File was not uploaded." } };
            }

            var fileExt = Path.GetExtension(posted.FileName.ToLower());

            if (string.IsNullOrEmpty(fileExt))
            {
                //ERROR MESSAGE
                //return new FileUploadJsonResult { Data = new { Src = "", ErrorMessage = "File was not uploaded." } };
            }
            else
            { //check type
                if (imageMediaFormats.HasExtension(fileExt))
                {
                    var mediaFormat = imageMediaFormats.GetSpecByExtension(fileExt);

                    Guid userID = new Guid(Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString());
                    string userName = Membership.GetUser(User.Identity.Name).UserName;
                    var ticks = DateTime.Now.Ticks;
                    Guid thumbImageId = Guid.NewGuid();
                    Guid fullImageId = Guid.NewGuid();

                    //save file 
                    var newFileName = posted.FileName;

                    if (posted.ContentLength > 0)
                    {

                        //try to resize the image
                        var tmpResizeBuffer = new byte[posted.ContentLength];
                        posted.InputStream.Read(tmpResizeBuffer, 0, posted.ContentLength);
                        var thumbResizedBuffer = imageResizerService.ResizeImage(tmpResizeBuffer, new ThumbnailSize(), mediaFormat);
                        var fullResizedBuffer = imageResizerService.ResizeImage(tmpResizeBuffer, new FullImageSize(), mediaFormat);

                        IPhoto thumbImage = null;
                        IPhoto fullImage = null;
                        //TODO: save fullImage

                        using (var unitOfWork = TheCore.Infrastructure.UnitOfWork.Begin())
                        {
                            /*
                             * thumbnail
                             */
                            if (thumbImage == null)
                            {
                                thumbImage = new Photo
                                {
                                    PhotoId = thumbImageId,
                                    CreatedDate = DateTime.Now,
                                    UserId = userID,
                                    FileName = "thumb" + newFileName,
                                    ContentType = mediaFormat.ContentType,
                                    ContentLength = thumbResizedBuffer.Length,
                                    //Image = new byte[thumbResizedBuffer.Length],
                                    Type = (short)PhotoType.TicketStub,
                                    Thumbnail = true,
                                    ShowId = showId
                                };
                            }
                            else
                            { //update entity
                                thumbImage.ContentType = mediaFormat.ContentType;
                                thumbImage.ContentLength = thumbResizedBuffer.Length;
                            }

                            bool success = false;
                            photoService.Save(thumbImage, mediaFormat, out success);

                            compiledSuccess = compiledSuccess && success;

                            /*
                             * fullsize
                             */
                            if (fullImage == null)
                            {
                                //newFileName = userName + "-" + DateTime.Now.Ticks + fileExt;

                                fullImage = new Photo
                                {
                                    PhotoId = fullImageId,
                                    CreatedDate = DateTime.Now,
                                    UserId = userID,
                                    FileName = newFileName,
                                    ContentType = mediaFormat.ContentType,
                                    ContentLength = fullResizedBuffer.Length,
                                    //Image = new byte[fullResizedBuffer.Length],
                                    Type = (short)PhotoType.TicketStub,
                                    Thumbnail = false,
                                    ShowId = showId
                                };
                            }
                            else
                            { //update entity
                                fullImage.ContentType = mediaFormat.ContentType;
                                fullImage.ContentLength = fullResizedBuffer.Length;
                            }

                            photoService.Save(fullImage, mediaFormat, out success);

                            compiledSuccess = compiledSuccess && success;

                            if (!compiledSuccess)
                            {
                                //log.Error("The following validation conditions cased the offering image upload to fail during a call to CreateOfferingImageUpload: {0}".FormatWith(validationState.GetMessages()));
                                //ERROR MESSAGE NEEDED
                                //return new FileUploadJsonResult { Data = new { Src = "", ErrorMessage = "An error occurred while trying to save you upload. Please try again." } };
                            }
                            else
                            {
                                unitOfWork.Commit();

                                var thumbImageTemp = photoService.GetPhoto(thumbImageId);
                                thumbImageTemp.Image = thumbResizedBuffer;

                                string path = string.Format("{0}{1}", DefaultTicketStubImageLocation, thumbImageTemp.FileName);

                                bool valid = photoService.SaveAs(thumbImageTemp, HttpContext.Current.Server.MapPath(path));

                                if (valid)
                                {
                                    var fullImageTemp = photoService.GetPhoto(fullImageId);
                                    fullImageTemp.Image = fullResizedBuffer;

                                    path = string.Format("{0}{1}", DefaultTicketStubImageLocation, fullImageTemp.FileName);

                                    valid = photoService.SaveAs(fullImageTemp, HttpContext.Current.Server.MapPath(path));

                                    if (valid)
                                    {
                                        imgTheImage.ImageUrl = LinkBuilder.GetTicketStubLink(fullImage.FileName);

                                        thumbImageTemp.Image = null;
                                        fullImageTemp.Image = null;

                                        CreateTicketStubNow(fullImage, showId);
                                    }
                                    else
                                    {
                                        //FREAK OUT!!
                                    }
                                }
                            }
                        }
                    }

                    //ERROR MESSAGE NEEDED
                    //return new FileUploadJsonResult { Data = new { Src = Url.TempImages(tempId), ErrorMessage = "" } };

                }
                else
                {
                    //ERROR MESSAGE NEEDED
                    //return new FileUploadJsonResult { Data = new { Src = "", ErrorMessage = "The image you are trying to upload is listed as an invalid image type.  Please use the approved types:{0}".FormatWith(_imageMediaFormats.ImageFormatSpecs.ToDebugString(",")) } };
                }

            }

            //ERROR MESSAGE NEEDED
            //return new FileUploadJsonResult { Data = new { Src = "", ErrorMessage = "No file uploaded." } };
        }