예제 #1
0
        public void Create_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            var specialIdList = new List <int>();

            foreach (ListItem item in LbSpecialIdList.Items)
            {
                if (!item.Selected)
                {
                    continue;
                }

                var specialId = TranslateUtils.ToInt(item.Value);
                specialIdList.Add(specialId);
            }

            if (specialIdList.Count == 0)
            {
                FailMessage("请选择需要生成的专题!");
                return;
            }

            foreach (var specialId in specialIdList)
            {
                CreateManager.CreateSpecial(SiteId, specialId);
            }

            PageUtils.Redirect(CmsPages.GetCreateStatusUrl(SiteId));
        }
예제 #2
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId       = request.GetPostInt("siteId");
                var guid         = request.GetPostString("guid");
                var specialId    = request.GetPostInt("specialId");
                var isEditOnly   = request.GetPostBool("isEditOnly");
                var isUploadOnly = request.GetPostBool("isUploadOnly");
                var title        = request.GetPostString("title");
                var url          = request.GetPostString("url");
                var fileNames    = TranslateUtils.StringCollectionToStringList(request.GetPostString("fileNames"));
                var siteInfo     = SiteManager.GetSiteInfo(siteId);

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSitePermissions(siteId,
                                                                     ConfigManager.SitePermissions.Specials))
                {
                    return(Unauthorized());
                }

                if (specialId > 0 && isEditOnly)
                {
                    var specialInfo      = SpecialManager.GetSpecialInfo(siteId, specialId);
                    var oldDirectoryPath = string.Empty;
                    var newDirectoryPath = string.Empty;

                    if (specialInfo.Title != title && DataProvider.SpecialDao.IsTitleExists(siteId, title))
                    {
                        return(BadRequest("专题修改失败,专题名称已存在!"));
                    }
                    if (specialInfo.Url != url)
                    {
                        if (DataProvider.SpecialDao.IsUrlExists(siteId, url))
                        {
                            return(BadRequest("专题修改失败,专题访问地址已存在!"));
                        }

                        oldDirectoryPath = SpecialManager.GetSpecialDirectoryPath(siteInfo, specialInfo.Url);
                        newDirectoryPath = SpecialManager.GetSpecialDirectoryPath(siteInfo, url);
                    }

                    specialInfo.Title = title;
                    specialInfo.Url   = url;
                    DataProvider.SpecialDao.Update(specialInfo);

                    if (oldDirectoryPath != newDirectoryPath)
                    {
                        DirectoryUtils.MoveDirectory(oldDirectoryPath, newDirectoryPath, true);
                    }
                }
                else if (specialId > 0 && isUploadOnly)
                {
                    var specialInfo = SpecialManager.GetSpecialInfo(siteId, specialId);

                    var directoryPath    = SpecialManager.GetSpecialDirectoryPath(siteInfo, specialInfo.Url);
                    var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath);
                    DirectoryUtils.CreateDirectoryIfNotExists(srcDirectoryPath);

                    var uploadDirectoryPath = PathUtils.GetTemporaryFilesPath(guid);
                    foreach (var filePath in DirectoryUtils.GetFilePaths(uploadDirectoryPath))
                    {
                        var fileName = PathUtils.GetFileName(filePath);
                        if (!StringUtils.ContainsIgnoreCase(fileNames, fileName))
                        {
                            continue;
                        }

                        if (EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(filePath)))
                        {
                            ZipUtils.ExtractZip(filePath, srcDirectoryPath);
                        }
                        else
                        {
                            FileUtils.MoveFile(filePath, PathUtils.Combine(srcDirectoryPath, fileName), true);
                        }
                    }

                    DirectoryUtils.Copy(srcDirectoryPath, directoryPath);
                }
                else if (specialId == 0)
                {
                    if (DataProvider.SpecialDao.IsTitleExists(siteId, title))
                    {
                        return(BadRequest("专题添加失败,专题名称已存在!"));
                    }
                    if (DataProvider.SpecialDao.IsUrlExists(siteId, url))
                    {
                        return(BadRequest("专题添加失败,专题访问地址已存在!"));
                    }

                    var directoryPath    = SpecialManager.GetSpecialDirectoryPath(siteInfo, url);
                    var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath);
                    DirectoryUtils.CreateDirectoryIfNotExists(srcDirectoryPath);

                    var uploadDirectoryPath = PathUtils.GetTemporaryFilesPath(guid);
                    foreach (var filePath in DirectoryUtils.GetFilePaths(uploadDirectoryPath))
                    {
                        var fileName = PathUtils.GetFileName(filePath);
                        if (!StringUtils.ContainsIgnoreCase(fileNames, fileName))
                        {
                            continue;
                        }

                        if (EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(filePath)))
                        {
                            ZipUtils.ExtractZip(filePath, srcDirectoryPath);
                        }
                        else
                        {
                            FileUtils.MoveFile(filePath, PathUtils.Combine(srcDirectoryPath, fileName), true);
                        }
                    }

                    DirectoryUtils.Copy(srcDirectoryPath, directoryPath);

                    specialId = DataProvider.SpecialDao.Insert(new SpecialInfo
                    {
                        Id      = 0,
                        SiteId  = siteId,
                        Title   = title,
                        Url     = url,
                        AddDate = DateTime.Now
                    });

                    request.AddSiteLog(siteId, "新建专题", $"专题名称:{title}");
                }

                CreateManager.CreateSpecial(siteId, specialId);

                return(Ok(new
                {
                    Value = specialId
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }