示例#1
0
        public ActionResult MoveFlickrPhotos(FormCollection form)
        {
            string photofolderpath = Server.MapPath(string.Format("~/documents/file/{0}", Manager.Settings.Current.PhotoListTableName));

            Guid albumId = Guid.Parse(form["Album-Select"].ToString());

            foreach (var item in form.AllKeys)
            {
                if (item.StartsWith("hd_"))
                {
                    string photoid = item.Substring(3);
                    if (form["chc_" + photoid] == "on")
                    {
                        string   downloadlink   = form["hd_" + photoid].ToString();
                        string   thumbnaillink  = form["hdt_" + photoid].ToString();
                        string   title          = form["Txt_" + photoid].ToString();
                        string[] linksegments   = downloadlink.Split('/');
                        string   uploadfilename = Manager.PhotoManager.GetUnigateFileName(linksegments.Last());

                        this.ChangeFileFieldType(false);
                        Insert insert = UnigateObject.Insert(Manager.Settings.Current.PhotoListTableName)
                                        .Column("Slug", photoid)
                                        .Column("CreateDate", DateTime.Now.ToString())
                                        .Column("UpdateDate", DateTime.Now.ToString());

                        if (Manager.Settings.Current.PhotoListTableTitleField != null)
                        {
                            insert = insert.Column(Manager.Settings.Current.PhotoListTableTitleField.Name, title);
                        }

                        bool uploaded = false;
                        if (Manager.Settings.Current.PhotoListTablePhotoField != null)
                        {
                            string uploadpath = string.Format("{0}/{1}", photofolderpath, uploadfilename);
                            using (WebClient client = new WebClient())
                            {
                                try
                                {
                                    client.DownloadFile(downloadlink, uploadpath);
                                    uploaded = true;

                                    insert = insert.Column(Manager.Settings.Current.PhotoListTablePhotoField.Name, string.Format("/documents/file/{0}/{1}", Manager.Settings.Current.PhotoListTableName, uploadfilename));
                                }
                                catch (Exception)
                                {
                                    uploaded = false;
                                }
                            }
                        }

                        if (uploaded)
                        {
                            if (Manager.Settings.Current.PhotoListTableThumbnailField != null)
                            {
                                string uploadthumbnailname = Manager.PhotoManager.GetUnigateFileName(linksegments.Last());
                                string uploadthumbnailpath = string.Format("{0}/{1}", photofolderpath, uploadthumbnailname);
                                using (WebClient client = new WebClient())
                                {
                                    try
                                    {
                                        client.DownloadFile(downloadlink, uploadthumbnailpath);

                                        insert = insert.Column(Manager.Settings.Current.PhotoListTableThumbnailField.Name, string.Format("/documents/file/{0}/{1}", Manager.Settings.Current.PhotoListTableName, uploadthumbnailname));
                                    }
                                    catch (Exception)
                                    { }
                                }
                            }

                            if (Manager.Settings.Current.PhotoListTableAlbumRelationField != null)
                            {
                                insert = insert.Column(Manager.Settings.Current.PhotoListTableAlbumRelationField.Name, albumId);
                            }

                            MDataSourceResult result = insert.Execute();
                        }
                        this.ChangeFileFieldType(true);
                    }
                }
            }

            return(Redirect("/unigate/" + Unigate.PhotoGallery.AdminPlugin.Manager.PluginProperties.PluginName + "/PhotoGallery/Flickr"));
        }
示例#2
0
        public JsonResult Upload(Guid albumId)
        {
            if (Request.Files != null && Request.Files.Count > 0)
            {
                int orderno = 1;
                if (Manager.Settings.Current.PhotoListTableOrderNoField != null && !string.IsNullOrEmpty(Manager.Settings.Current.PhotoListTableOrderNoField.Name))
                {
                    orderno = UnigateObject.Query(Manager.Settings.Current.PhotoListTableName).ToList <Models.BaseModel>().Count + 1;
                }

                string photofolderpath = Server.MapPath(string.Format("~/documents/file/{0}", Manager.Settings.Current.PhotoListTableName));

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    string filename = Path.GetFileName(Request.Files[i].FileName);

                    Stream stream          = Request.Files[i].InputStream;
                    byte[] photobinarydata = new byte[stream.Length];
                    stream.Read(photobinarydata, 0, Convert.ToInt32(stream.Length));
                    Size imagesize = Manager.PhotoManager.GetImageSize(photobinarydata);

                    this.ChangeFileFieldType(false);
                    Insert insert = UnigateObject.Insert(Manager.Settings.Current.PhotoListTableName)
                                    .Column("Slug", filename.Replace(".", "-"))
                                    .Column("CreateDate", DateTime.Now.ToString())
                                    .Column("UpdateDate", DateTime.Now.ToString());

                    if (Manager.Settings.Current.PhotoListTableTitleField != null && !string.IsNullOrEmpty(Manager.Settings.Current.PhotoListTableTitleField.Name))
                    {
                        if (Manager.Settings.Current.PhotoListTableTitleField.DefaultValue != null)
                        {
                            switch (Manager.Settings.Current.PhotoListTableTitleField.DefaultValue.ToString())
                            {
                            case "FileName":
                                insert = insert.Column(Manager.Settings.Current.PhotoListTableTitleField.Name, filename);
                                break;

                            case "Now":
                                insert = insert.Column(Manager.Settings.Current.PhotoListTableTitleField.Name, DateTime.Now.ToString());
                                break;

                            case "Today":
                                insert = insert.Column(Manager.Settings.Current.PhotoListTableTitleField.Name, DateTime.Today.ToShortDateString());
                                break;

                            default:
                                insert = insert.Column(Manager.Settings.Current.PhotoListTableTitleField.Name, string.Empty);
                                break;
                            }
                        }
                        else
                        {
                            insert = insert.Column(Manager.Settings.Current.PhotoListTableTitleField.Name, string.Empty);
                        }
                    }

                    bool   uploaded       = false;
                    string uploadfilename = Manager.PhotoManager.GetUnigateFileName(filename);
                    if (Manager.Settings.Current.PhotoListTablePhotoField != null && !string.IsNullOrEmpty(Manager.Settings.Current.PhotoListTablePhotoField.Name))
                    {
                        string uploadpath = string.Format("{0}/{1}", photofolderpath, uploadfilename);

                        if (Manager.Settings.Current.PhotoSize != null && Manager.Settings.Current.PhotoSize.Width != null && Manager.Settings.Current.PhotoSize.Height != null)
                        {
                            uploaded = Manager.PhotoManager.SavePhoto(Manager.PhotoManager.ImageResize(photobinarydata, Manager.Settings.Current.PhotoSize.Width, Manager.Settings.Current.PhotoSize.Height, false), uploadpath);
                        }
                        else
                        {
                            uploaded = Manager.PhotoManager.SavePhoto(photobinarydata, uploadpath);
                        }

                        insert = insert.Column(Manager.Settings.Current.PhotoListTablePhotoField.Name, string.Format("/documents/file/{0}/{1}", Manager.Settings.Current.PhotoListTableName, uploadfilename));
                    }

                    if (uploaded)
                    {
                        if (Manager.Settings.Current.PhotoListTableThumbnailField != null && !string.IsNullOrEmpty(Manager.Settings.Current.PhotoListTableThumbnailField.Name))
                        {
                            string uploadthumbnailname = Manager.PhotoManager.GetUnigateFileName(filename);
                            string uploadthumbnailpath = string.Format("{0}/{1}", photofolderpath, uploadthumbnailname);

                            if (Manager.Settings.Current.ThumbnailPhotoSize != null && Manager.Settings.Current.ThumbnailPhotoSize.Width != null && Manager.Settings.Current.ThumbnailPhotoSize.Height != null)
                            {
                                Manager.PhotoManager.SavePhoto(Manager.PhotoManager.ImageResize(photobinarydata, Manager.Settings.Current.ThumbnailPhotoSize.Width, Manager.Settings.Current.ThumbnailPhotoSize.Height, false), uploadthumbnailpath);
                            }
                            else
                            {
                                uploadthumbnailname = uploadfilename;
                            }

                            insert = insert.Column(Manager.Settings.Current.PhotoListTableThumbnailField.Name, string.Format("/documents/file/{0}/{1}", Manager.Settings.Current.PhotoListTableName, uploadthumbnailname));
                        }

                        if (Manager.Settings.Current.PhotoListTableAlbumRelationField != null && !string.IsNullOrEmpty(Manager.Settings.Current.PhotoListTableAlbumRelationField.Name))
                        {
                            insert = insert.Column(Manager.Settings.Current.PhotoListTableAlbumRelationField.Name, albumId);
                        }

                        if (Manager.Settings.Current.PhotoListTableOrderNoField != null && !string.IsNullOrEmpty(Manager.Settings.Current.PhotoListTableOrderNoField.Name))
                        {
                            insert = insert.Column(Manager.Settings.Current.PhotoListTableOrderNoField.Name, orderno);
                            orderno++;
                        }

                        MDataSourceResult result = insert.Execute();
                        this.ChangeFileFieldType(true);
                    }
                }
            }

            return(Json("/unigate/" + Unigate.PhotoGallery.AdminPlugin.Manager.PluginProperties.PluginName + "/?albumId=" + albumId.ToString()));
        }