Exemplo n.º 1
0
 /// <summary>
 /// Create a new GalleryItem object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="albumId">Initial value of the AlbumId property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="postedAt">Initial value of the PostedAt property.</param>
 /// <param name="accountId">Initial value of the AccountId property.</param>
 /// <param name="fileId">Initial value of the FileId property.</param>
 /// <param name="thumbnailFileId">Initial value of the ThumbnailFileId property.</param>
 public static GalleryItem CreateGalleryItem(global::System.Int32 id, global::System.Int32 albumId, global::System.String title, global::System.String text, global::System.DateTime postedAt, global::System.Int32 accountId, global::System.Int32 fileId, global::System.Int32 thumbnailFileId)
 {
     GalleryItem galleryItem = new GalleryItem();
     galleryItem.Id = id;
     galleryItem.AlbumId = albumId;
     galleryItem.Title = title;
     galleryItem.Text = text;
     galleryItem.PostedAt = postedAt;
     galleryItem.AccountId = accountId;
     galleryItem.FileId = fileId;
     galleryItem.ThumbnailFileId = thumbnailFileId;
     return galleryItem;
 }
Exemplo n.º 2
0
        public ActionResult AddImage(GalleryItemViewModel gvm, HttpPostedFileBase file)
        {
            if(ModelState.IsValid)
            {
                using (new UnitOfWork(_currentContext))
                {
                    //upload file first
                    var ticks = DateTime.Now.Ticks;
                    var fileName = String.Format("gallery-{0}", ticks) + Path.GetExtension(file.FileName);
                    var absoluteTempPath = Server.MapPath("~/Content/images/uploads/temp/");
                    var absolutePath = Server.MapPath("~/Content/images/uploads/gallery/");
                    var fullVirtualPath = "~/Content/images/uploads/gallery/" + fileName;
                    var absoluteThumbnailPath = Server.MapPath("~/Content/images/uploads/gallery/thumbnails/");
                    var fullVirtualThumbnailPath = "~/Content/images/uploads/gallery/thumbnails/" + fileName;
                    //create a temp file first, then compress it
                    FileUploader.UploadFile(file, fileName,
                                            absoluteTempPath);

                    var encoder = new ImageEncoder();
                    encoder.Compress(absoluteTempPath + fileName, absolutePath + fileName, 800, 600);
                    encoder.Compress(absoluteTempPath + fileName, absoluteThumbnailPath + fileName, 290, 217);
                    //after compressing deleting original file
                    FileUploader.DeleteFile(absoluteTempPath + fileName);

                    var fullImage = new File()
                    {
                        FileName = fullVirtualPath,
                        FilePurposeId = (int)FilePurposes.Gallery
                    };

                    var thumbnailImage = new File()
                        {
                            FileName = fullVirtualThumbnailPath,
                            FilePurposeId = (int) FilePurposes.Gallery
                        };

                    var galleryItem = new GalleryItem
                    {
                        Title = gvm.Title,
                        Text = gvm.Text,
                        PostedAt = DateTime.Now,
                        File = fullImage,
                        Thumbnail = thumbnailImage,
                        AlbumId = gvm.AlbumId,
                        Account = accountRepository.GetByUsername(CurrentUserName)
                    };

                    galleryRepository.Add(galleryItem);
                }
                TempData[Const.ActionResultInfo] = "Изображение добавлено в альбом";
                return RedirectToAction("Album", new { id = gvm.AlbumId});
            }

            TempData[Const.ActionErrorInfo] = "Ошибка добавления изображения. Проверьте корректность введенных данных";
            return View(gvm);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the GalleryItemSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToGalleryItemSet(GalleryItem galleryItem)
 {
     base.AddObject("GalleryItemSet", galleryItem);
 }