Esempio n. 1
0
 public bool UpdateAlbum(int AlbumId, string AlbumName)
 {
     try
     {
         AlbumsDSTableAdapters.PhotoAlbumsTableAdapter adp = new AlbumsDSTableAdapters.PhotoAlbumsTableAdapter();
         DataRow album = this.GetPhotoAlbums(string.Format("Id={0}", AlbumId))[0].Row;
         album["Name"]        = StringUtils.ToURL(AlbumName);
         album["DisplayName"] = AlbumName;
         adp.Update(album);
     }
     catch (Exception e)
     {
         return(false);
     }
     return(true);
 }
Esempio n. 2
0
        public bool UpdateAlbum(int AlbumId, string Name, string DisplayName,
                                string Description,
                                bool status, int Sort,
                                bool HasIntroPage, int CategoryId,
                                bool DeleteImage, HttpPostedFile Image, Languages lan, DateTime?AlbumDate)
        {
            AlbumsDS _ds = new AlbumsDS();

            AlbumsDSTableAdapters.PhotoAlbumsTableAdapter adp = new AlbumsDSTableAdapters.PhotoAlbumsTableAdapter();

            DataRow album = this.GetPhotoAlbums(string.Format("Id={0}", AlbumId))[0].Row;

            album["Name"]         = StringUtils.ToURL(DisplayName);
            album["DisplayName"]  = DisplayName;
            album["Description"]  = Description;
            album["Status"]       = status;
            album["Sort"]         = Sort;
            album["HasIntroPage"] = HasIntroPage;
            album["CategoryId"]   = CategoryId;
            album["DateAdded"]    = (DateTime)album["DateAdded"];
            album["DateModified"] = DateTime.Now;
            album["Image"]        = album["Image"].ToString();
            album["Language"]     = (short)lan;
            if (AlbumDate != null)
            {
                album["AlbumDate"] = AlbumDate.Value;
            }

            adp.Update(album);


            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.PhotoAlbums);

            path = System.IO.Path.Combine(path, string.Format("Album{0}", album["Id"]));

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);

                Directory.CreateDirectory(Path.Combine(path, "Original"));
                Directory.CreateDirectory(Path.Combine(path, "Large"));
                Directory.CreateDirectory(Path.Combine(path, "Thumb"));
            }


            bool del = (DeleteImage || (Image != null && Image.ContentLength > 0)) &&
                       album["Image"].ToString() != "";

            bool updateData = false;

            if (DeleteImage)
            {
                string fileName = Path.Combine(path, album["Image"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }


                fileName = Path.Combine(path, "Large_" + album["Image"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                fileName = Path.Combine(path, "Thumb_" + album["Image"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                album["Image"] = "";
                updateData     = true;
            }

            //if (!DeleteImage && Image != null && Image.ContentLength > 0)
            if (Image != null && Image.ContentLength > 0)
            {
                Config cfg = new Config();

                string fileName = StringUtils.GetFileName(Image.FileName);

                string ImageName      = string.Format("{0}\\{1}", path, fileName);
                string largeImageName = string.Format("{0}\\Large_{1}", path, fileName);
                string thumbImageName = string.Format("{0}\\Thumb_{1}", path, fileName);

                Image.SaveAs(ImageName);

                if (cfg.GetKey("AlbumImage") == "on")
                {
                    try
                    {
                        Dimension largeImageSize = new Dimension(cte.CoverPhotoDefaultSize);
                        Dimension thumbImageSize = new Dimension(cte.CoverPhotoDefaultThumbSize);

                        if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.CoverPhotoSize)))
                        {
                            largeImageSize = new Dimension(cfg.GetKey(cte.CoverPhotoSize));
                        }
                        if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.CoverPhotoThumbSize)))
                        {
                            thumbImageSize = new Dimension(cfg.GetKey(cte.CoverPhotoThumbSize));
                        }

                        lw.GraphicUtils.ImageUtils.Resize(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight);
                        lw.GraphicUtils.ImageUtils.CropImage(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight, ImageUtils.AnchorPosition.Default);
                    }
                    catch (Exception ex)
                    {
                        ErrorContext.Add("resize-image", "Unable to resize album image.<br><span class=hid>" + ex.Message + "</span>");
                    }
                }

                album["Image"] = fileName;
                updateData     = true;
            }

            if (updateData)
            {
                adp.Update(album);
            }

            return(true);
        }