Exemple #1
0
        protected void btnUpdateImage_Click(object sender, EventArgs e)
        {
            if (news == null)
            {
                return;
            }

            //txtImageTitle.Text = txtImageTitle.Text.Trim();
            NewsHelper.VerifyNewsFolders(fileSystem, imageFolderPath);

            foreach (UploadedFile file in uplImageFile.UploadedFiles)
            {
                string ext = file.GetExtension();
                if (SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.ImageFileExtensions))
                {
                    ContentMedia image = new ContentMedia();
                    image.SiteGuid    = siteSettings.SiteGuid;
                    image.ContentGuid = news.NewsGuid;
                    //image.Title = txtImageTitle.Text;
                    image.DisplayOrder = 0;

                    string newFileName  = file.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                    string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                    if (image.MediaFile == newFileName)
                    {
                        // an existing image delete the old one
                        fileSystem.DeleteFile(newImagePath);
                    }
                    else
                    {
                        // this is a new newsImage instance, make sure we don't use the same file name as any other instance
                        int i = 1;
                        while (fileSystem.FileExists(VirtualPathUtility.Combine(imageFolderPath, newFileName)))
                        {
                            newFileName = i.ToInvariantString() + newFileName;
                            i          += 1;
                        }
                    }

                    newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                    file.SaveAs(Server.MapPath(newImagePath));

                    image.MediaFile       = newFileName;
                    image.ThumbnailFile   = newFileName;
                    image.ThumbNailWidth  = displaySettings.ThumbnailWidth;
                    image.ThumbNailHeight = displaySettings.ThumbnailHeight;
                    image.Save();
                    NewsHelper.ProcessImage(image, fileSystem, imageFolderPath, file.FileName, NewsHelper.GetColor(displaySettings.ResizeBackgroundColor));
                }
            }
            grid.Rebind();
            updImages.Update();
        }
        private int Save()
        {
            checkpass();
            if (comfim)
            {
                try
                {
                    var    full = txtFullName.Text.Trim().Split(' ');
                    string Fist = "";
                    string Last = "";
                    for (int i = 0; i < full.Length; i++)
                    {
                        if ((i + 1) < full.Length)
                        {
                            Last += full[i];
                        }
                        else
                        {
                            Fist += full[i];
                        }
                    }
                    SiteUser user = new SiteUser(siteSettings)
                    {
                        Name      = txtFullName.Text.Trim(),
                        FirstName = Fist,
                        LastName  = Last,
                        Email     = txtEmail.Text.Trim(),
                        LoginName = txtFullName.Text.Trim().Replace(' ', '-'),
                        Password  = txtPass2.Text,
                    };
                    user.Save();
                    user = new SiteUser(siteSettings, txtFullName.Text.Replace(' ', '-'));
                    KLAuthor author = null;

                    imageFolderPath = AuthorHepper.MediaFolderPath(siteSettings.SiteId, user.UserId);
                    if (user.Save())
                    {
                        author = new KLAuthor()
                        {
                            ArticleCount = 0,
                            UserID       = user.UserId,
                            IsDel        = false,
                            LevelAuthor  = "Basic",
                            Name         = txtFullName.Text,
                            IsActive     = false,
                        };
                        if (fileImage.UploadedFiles.Count > 0)
                        {
                            imageFolderPath = AuthorHepper.MediaFolderPath(siteSettings.SiteId, user.UserId);


                            AuthorHepper.VerifyAuthorFolders(fileSystem, imageFolderPath);

                            foreach (UploadedFile file in fileImage.UploadedFiles)
                            {
                                string ext = file.GetExtension();
                                if (SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.ImageFileExtensions))
                                {
                                    ContentMedia media = new ContentMedia();
                                    media.SiteGuid = siteSettings.SiteGuid;
                                    //image.Title = txtImageTitle.Text;
                                    media.DisplayOrder = 0;

                                    string newFileName  = file.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                                    string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                                    if (media.MediaFile == newFileName)
                                    {
                                        // an existing image delete the old one
                                        fileSystem.DeleteFile(newImagePath);
                                    }
                                    else
                                    {
                                        // this is a new newsImage instance, make sure we don't use the same file name as any other instance
                                        int i = 1;
                                        while (fileSystem.FileExists(VirtualPathUtility.Combine(imageFolderPath, newFileName)))
                                        {
                                            newFileName = i.ToInvariantString() + newFileName;
                                            i          += 1;
                                        }
                                    }

                                    newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                                    file.SaveAs(Server.MapPath(newImagePath));

                                    media.MediaFile     = newFileName;
                                    media.ThumbnailFile = newFileName;

                                    author.Avatar = newFileName;
                                    media.Save();
                                    AuthorHepper.ProcessImage(media, fileSystem, imageFolderPath, file.FileName);
                                }
                            }
                        }
                    }
                    author.Save();

                    Role role = new Role(siteSettings.SiteId, "Author");
                    Role.AddUser(role.RoleId, author.UserID, role.RoleGuid, user.UserGuid);

                    if (!sendmail(user.Name, user.Email))
                    {
                        return(-1);
                    }

                    return(author.UserID);
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                }
            }
            return(-1);
        }
        private int Save()
        {
            Page.Validate("Author");

            if (!Page.IsValid)
            {
                return(-1);
            }
            try
            {
                author.LinkFacebook  = txtfb.Text;
                author.LinkInstagram = txtinstagram.Text;
                author.LinkPinterest = txtpinterest.Text;
                author.LinkTwitter   = txttwinter.Text;
                author.Name          = txtFullName.Text;
                SiteUser temp = new SiteUser(siteSettings, author.UserID);
                temp.Signature = editDescription.Text;
                if (fileImage.UploadedFiles.Count > 0)
                {
                    imageFolderPath = AuthorHepper.MediaFolderPath(siteSettings.SiteId, author.UserID);


                    AuthorHepper.VerifyAuthorFolders(fileSystem, imageFolderPath);

                    foreach (UploadedFile file in fileImage.UploadedFiles)
                    {
                        string ext = file.GetExtension();
                        if (SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.ImageFileExtensions))
                        {
                            ContentMedia media = new ContentMedia();
                            media.SiteGuid = siteSettings.SiteGuid;
                            //image.Title = txtImageTitle.Text;
                            media.DisplayOrder = 0;

                            string newFileName  = file.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                            string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                            if (media.MediaFile == newFileName)
                            {
                                // an existing image delete the old one
                                fileSystem.DeleteFile(newImagePath);
                            }
                            else
                            {
                                // this is a new newsImage instance, make sure we don't use the same file name as any other instance
                                int i = 1;
                                while (fileSystem.FileExists(VirtualPathUtility.Combine(imageFolderPath, newFileName)))
                                {
                                    newFileName = i.ToInvariantString() + newFileName;
                                    i          += 1;
                                }
                            }

                            newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                            file.SaveAs(Server.MapPath(newImagePath));

                            media.MediaFile     = newFileName;
                            media.ThumbnailFile = newFileName;

                            author.Avatar = newFileName;
                            media.Save();
                            AuthorHepper.ProcessImage(media, fileSystem, imageFolderPath, file.FileName);
                        }
                    }
                }


                if (temp.Save() && author.Save())
                {
                    ImageAvatar.ImageUrl = AuthorHepper.GetAvatarAuthor(siteSettings.SiteId, author.UserID);
                    LogActivity.Write("Update Author", author.Name);
                    message.SuccessMessage = ResourceHelper.GetResourceString("CustomResources", "UpdateAuthorSuccess");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
            return(author.AuthorID);
        }
Exemple #4
0
        private int Save()
        {
            Page.Validate("Books");

            if (!Page.IsValid)
            {
                return(-1);
            }

            if (currentuser == null)
            {
                return(-1);
            }
            if (book == null)
            {
                book            = new KLBook();
                book.AuthorID   = author.AuthorID;
                book.IsPublish  = true;
                book.IsDelected = false;
            }
            book.Title       = txttitle.Text;
            book.Url         = txtURl.Text;
            book.Description = fullcontent.Text;
            if (book.Save())
            {
                imageFolderPath = BookHelper.MediaFolderPath(siteSettings.SiteId, book.BookID);

                if (fileImages.UploadedFiles.Count > 0)
                {
                    BookHelper.VerifyBookFolders(fileSystem, imageFolderPath);

                    foreach (UploadedFile file in fileImages.UploadedFiles)
                    {
                        string ext = file.GetExtension();
                        if (SiteUtils.IsAllowedUploadBrowseFile(ext, WebConfigSettings.ImageFileExtensions))
                        {
                            ContentMedia media = new ContentMedia();
                            media.SiteGuid = siteSettings.SiteGuid;
                            //image.Title = txtImageTitle.Text;
                            media.DisplayOrder = 0;

                            string newFileName  = file.FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);
                            string newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                            if (media.MediaFile == newFileName)
                            {
                                // an existing image delete the old one
                                fileSystem.DeleteFile(newImagePath);
                            }
                            else
                            {
                                // this is a new newsImage instance, make sure we don't use the same file name as any other instance
                                int i = 1;
                                while (fileSystem.FileExists(VirtualPathUtility.Combine(imageFolderPath, newFileName)))
                                {
                                    newFileName = i.ToInvariantString() + newFileName;
                                    i          += 1;
                                }
                            }

                            newImagePath = VirtualPathUtility.Combine(imageFolderPath, newFileName);

                            file.SaveAs(Server.MapPath(newImagePath));

                            media.MediaFile     = newFileName;
                            media.ThumbnailFile = newFileName;

                            book.Image = newFileName;
                            media.Save();
                            BookHelper.ProcessImage(media, fileSystem, imageFolderPath, file.FileName);
                        }
                    }
                }
            }
            if (book.Save())
            {
                LogActivity.Write("Create new news", book.Title);
                message.SuccessMessage = ResourceHelper.GetResourceString("Resource", "InsertSuccessMessage");
            }
            return(book.BookID);
        }