Ejemplo n.º 1
0
        public bool CreatePoster(IPhoto photo, Guid? showId)
        {
            bool final = false;
            var posterId = Guid.NewGuid();

            var posterService = new PosterService(Ioc.GetInstance<IPosterRepository>());
            var myShowService = new MyShowService(Ioc.GetInstance<IMyShowRepository>());
            var spService = new MyShowPosterService(Ioc.GetInstance<IMyShowPosterRepository>());

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

            var date = DateTime.UtcNow;

            Poster p = new Poster
            {
                CreatedDate = DateTime.Now,
                PhotoId = photo.PhotoId,
                PosterId = posterId,
                Notes = photo.Notes,
                UserId = photo.UserId,
                Creator = txtCreator.Text,
                Length = string.IsNullOrEmpty(txtLength.Text) ? 0 : double.Parse(txtLength.Text),
                Width = string.IsNullOrEmpty(txtWidth.Text) ? 0 : double.Parse(txtWidth.Text),
                Total = string.IsNullOrEmpty(txtTotal.Text) ? 0 : int.Parse(txtTotal.Text),
                Number = string.IsNullOrEmpty(txtNumber.Text) ? 0 : int.Parse(txtNumber.Text),
                Technique = txtTechnique.Text,
                Title = txtTitle.Text,
                ShowId = showId
            };

            var combinedSuccess = true;
            bool success = false;

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

            combinedSuccess = combinedSuccess && success;

            posterService.Save(p, out success);

            combinedSuccess = combinedSuccess && success;

            var myShowPoster = new MyShowPoster
            {
                CreatedDate = date,
                UpdatedDate = date,
                MyShowId = myShowId,
                MyShowPosterId = Guid.NewGuid(),
                PosterId = posterId
            };

            spService.Save(myShowPoster, out success);

            combinedSuccess = combinedSuccess && success;

            return combinedSuccess;
        }
Ejemplo n.º 2
0
        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 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." } };
        }