Ejemplo n.º 1
0
        /// <summary>
        /// Inserts the files associated with the content
        /// </summary>
        private void InsertAttachFiles()
        {
            FileattachRepository objfiles = new FileattachRepository(this.session);

            objfiles.Entity.ContentId = this.ObjContent.ContentId;

            for (int i = 0; i < this.context.Request.Files.Count; i++)
            {
                if (this.context.Request.Files.GetKey(i).Contains("upload"))
                {
                    HttpPostedFileBase httpfile   = this.context.Request.Files[i];
                    string             ipnputname = "NP" + this.context.Request.Files.GetKey(i);

                    if (httpfile.ContentLength > 0)
                    {
                        objfiles.Entity.Filename = Utils.UploadFile(
                            httpfile,
                            this.context.Server.MapPath("~"),
                            @"files\" + this.ObjContent.ContentId + @"\",
                            i.ToString());

                        string valueinput = this.context.Request.Form[ipnputname];

                        objfiles.Entity.Type     = this.GetTypeFile(objfiles.Entity.Filename);
                        objfiles.Entity.Name     = !string.IsNullOrEmpty(valueinput) ? valueinput : null;
                        objfiles.Entity.Joindate = DateTime.Now;
                        objfiles.Insert();

                        if (objfiles.Entity.Type.Value == Fileattach.TypeFile.Image)
                        {
                            string fileroute = @"files\" + this.ObjContent.ContentId + @"\" + objfiles.Entity.Filename;
                            this.objimagerez.Resize(
                                fileroute,
                                ImageResize.TypeResize.PartialProportional);

                            this.objimagerez.Width  = 170;
                            this.objimagerez.Height = 105;
                            this.objimagerez.Prefix = "170x105-";
                            this.objimagerez.Resize(fileroute, ImageResize.TypeResize.CropProportional);

                            this.objimagerez.Width  = 683;
                            this.objimagerez.Height = 320;
                            this.objimagerez.Prefix = "683x320-";
                            this.objimagerez.Resize(fileroute, ImageResize.TypeResize.CropProportional);
                        }
                    }
                }
            }

            if (this.CollVideos != null)
            {
                foreach (string item in this.CollVideos)
                {
                    string codyoutube = Utils.CodeYoutube(item);
                    if (!string.IsNullOrEmpty(codyoutube))
                    {
                        objfiles.Entity.Filename = codyoutube;
                        objfiles.Entity.Type     = Fileattach.TypeFile.Video;
                        objfiles.Entity.Name     = item;
                        objfiles.Entity.Joindate = DateTime.Now;
                        objfiles.Insert();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Copy a content from the other content
        /// </summary>
        /// <param name="contentId">identifier of content</param>
        /// <param name="languageId">identifier of language</param>
        /// <param name="sectionId">identifier of section</param>
        /// <returns>returns true if the operation is successful</returns>
        public bool Clone(int contentId, int languageId, int sectionId)
        {
            try
            {
                this.session.Begin();
                ContentRepository     contentrepo    = new ContentRepository(this.session);
                FileattachRepository  fileattachrepo = new FileattachRepository(this.session);
                FriendlyurlRepository friendlyrepo   = new FriendlyurlRepository(this.session);

                fileattachrepo.Entity.ContentId      =
                    friendlyrepo.Entity.Id           =
                        contentrepo.Entity.ContentId = contentId;
                contentrepo.LoadByKey();

                friendlyrepo.Entity.Type = Friendlyurl.FriendlyType.Content;
                friendlyrepo.Load();

                List <Fileattach> collfiles = fileattachrepo.GetAll();

                contentrepo.Entity.SectionId   = sectionId;
                contentrepo.Entity.Name        = "Copy of " + contentrepo.Entity.Name;
                contentrepo.Entity.Orderliness = contentrepo.GetMaxOrder();
                int newid = Convert.ToInt32(contentrepo.Insert());

                friendlyrepo.Entity.Id            = newid;
                friendlyrepo.Entity.Friendlyurlid = "copy_of_" + friendlyrepo.Entity.Friendlyurlid;
                friendlyrepo.Entity.LanguageId    = languageId;
                friendlyrepo.Insert();

                foreach (Fileattach item in collfiles)
                {
                    fileattachrepo.Entity           = item;
                    fileattachrepo.Entity.ContentId = newid;
                    fileattachrepo.Insert();
                }

                this.CompleteClone(contentId, newid, contentrepo.Entity.ModulId.Value);

                string originpath = Path.Combine(this.context.Server.MapPath("~"), @"Files\" + contentId + @"\");
                string newpath    = Path.Combine(this.context.Server.MapPath("~"), @"Files\" + newid + @"\");

                if (Directory.Exists(originpath))
                {
                    DirectoryInfo dir   = new DirectoryInfo(originpath);
                    FileInfo[]    files = dir.GetFiles();

                    if (!Directory.Exists(newpath))
                    {
                        Directory.CreateDirectory(newpath);
                    }

                    foreach (FileInfo item in files)
                    {
                        File.Copy(item.FullName, newpath + item.Name);
                    }
                }

                this.session.Commit();

                return(true);
            }
            catch (Exception ex)
            {
                this.session.RollBack();
                Utils.InsertLog(this.session, "Clone Content ", ex.ToString());
                return(false);
            }
        }