コード例 #1
0
        public IActionResult Downloads(int id)
        {
            List <DownloadCategory> categories     = _downloadProvider.DownloadCategoriesGet(UserId());
            DownloadCategory        activeCategory = categories.Where(d => d.Id == id).FirstOrDefault();

            if (activeCategory == null)
            {
                activeCategory = categories[0];
            }

            List <ViewDownloadViewItem> downloads = new List <ViewDownloadViewItem>();

            foreach (DownloadItem item in activeCategory.Downloads)
            {
                downloads.Add(new ViewDownloadViewItem(GetModelData(),
                                                       item.Id, item.Name, item.Description,
                                                       item.Version, item.Filename, item.Icon, item.Size));
            }

            DownloadViewModel model = new DownloadViewModel(GetModelData(),
                                                            categories, activeCategory.Name, downloads);

            model.Breadcrumbs = GetBreadcrumbs();
            model.CartSummary = GetCartSummary();

            return(View(model));
        }
コード例 #2
0
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "QuickUpdate")
        {
            string DownloadCategoryID, Priority, IsShowOnMenu, IsShowOnHomePage, IsAvailable;
            var    oDownloadCategory = new DownloadCategory();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                DownloadCategoryID = item.GetDataKeyValue("DownloadCategoryID").ToString();
                Priority           = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                IsShowOnMenu       = ((CheckBox)item.FindControl("chkIsShowOnMenu")).Checked.ToString();
                IsShowOnHomePage   = ((CheckBox)item.FindControl("chkIsShowOnHomePage")).Checked.ToString();
                IsAvailable        = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oDownloadCategory.DownloadCategoryQuickUpdate(
                    DownloadCategoryID,
                    IsShowOnMenu,
                    IsShowOnHomePage,
                    IsAvailable,
                    Priority
                    );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var oDownloadCategory = new DownloadCategory();

            string errorList = "", DownloadCategoryName = "";

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                try
                {
                    var DownloadCategoryID = item.GetDataKeyValue("DownloadCategoryID").ToString();
                    DownloadCategoryName = ((Label)item.FindControl("lblDownloadCategoryName")).Text;
                    oDownloadCategory.DownloadCategoryDelete(DownloadCategoryID);
                }
                catch (Exception ex)
                {
                    if (ex.Message == ((int)ErrorNumber.ConstraintConflicted).ToString())
                    {
                        errorList += ", " + DownloadCategoryName;
                    }
                }
            }
            if (!string.IsNullOrEmpty(errorList))
            {
                e.Canceled = true;
                string strAlertMessage = "Danh mục <b>\"" + errorList.Remove(0, 1).Trim() + " \"</b> đang chứa file download.<br /> Xin xóa file trong danh mục này hoặc thiết lập hiển thị = \"không\".";
                lblError.Text = strAlertMessage;
            }
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            var command       = e.CommandName;
            var row           = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;
            var FileImageName = (RadUpload)row.FindControl("FileImageName");

            string strDownloadCategoryName          = ((RadTextBox)row.FindControl("txtDownloadCategoryName")).Text.Trim();
            string strDownloadCategoryNameEn        = ((RadTextBox)row.FindControl("txtDownloadCategoryNameEn")).Text.Trim();
            string strConvertedDownloadCategoryName = Common.ConvertTitle(strDownloadCategoryName);
            string strDescription       = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescription")).Content.Trim()));
            string strDescriptionEn     = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescriptionEn")).Content.Trim()));
            string strContent           = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContent")).Content.Trim()));
            string strContentEn         = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContentEn")).Content.Trim()));
            string strMetaTitle         = ((RadTextBox)row.FindControl("txtMetaTitle")).Text.Trim();
            string strMetaTitleEn       = ((RadTextBox)row.FindControl("txtMetaTitleEn")).Text.Trim();
            string strMetaDescription   = ((RadTextBox)row.FindControl("txtMetaDescription")).Text.Trim();
            string strMetaDescriptionEn = ((RadTextBox)row.FindControl("txtMetaDescriptionEn")).Text.Trim();
            string strImageName         = FileImageName.UploadedFiles.Count > 0 ? FileImageName.UploadedFiles[0].GetName() : "";
            string strIsAvailable       = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            string strIsShowOnMenu      = ((CheckBox)row.FindControl("chkIsShowOnMenu")).Checked.ToString();
            string strIsShowOnHomePage  = ((CheckBox)row.FindControl("chkIsShowOnHomePage")).Checked.ToString();
            string strPriority          = ((RadNumericTextBox)row.FindControl("txtPriority")).Text.Trim();

            var oDownloadCategory = new DownloadCategory();

            if (e.CommandName == "PerformInsert")
            {
                strImageName = oDownloadCategory.DownloadCategoryInsert(
                    strImageName,
                    strDownloadCategoryName,
                    strDownloadCategoryNameEn,
                    strConvertedDownloadCategoryName,
                    strDescription,
                    strDescriptionEn,
                    strContent,
                    strContentEn,
                    strMetaTitle,
                    strMetaTitleEn,
                    strMetaDescription,
                    strMetaDescriptionEn,
                    strIsShowOnMenu,
                    strIsShowOnHomePage,
                    strIsAvailable,
                    strPriority
                    );

                string strFullPath = "~/res/downloadcategory/" + strImageName;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 40, 40);
                }
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam         = ObjectDataSource1.UpdateParameters;
                var strDownloadCategoryID = row.GetDataKeyValue("DownloadCategoryID").ToString();
                var strOldImageName       = ((HiddenField)row.FindControl("hdnImageName")).Value;
                var strOldImagePath       = Server.MapPath("~/res/downloadcategory/" + strOldImageName);

                dsUpdateParam["DownloadCategoryName"].DefaultValue          = strDownloadCategoryName;
                dsUpdateParam["DownloadCategoryNameEn"].DefaultValue        = strDownloadCategoryNameEn;
                dsUpdateParam["ConvertedDownloadCategoryName"].DefaultValue = strConvertedDownloadCategoryName;
                dsUpdateParam["Description"].DefaultValue      = strDescription;
                dsUpdateParam["DescriptionEn"].DefaultValue    = strDescriptionEn;
                dsUpdateParam["Content"].DefaultValue          = strContent;
                dsUpdateParam["ContentEn"].DefaultValue        = strContentEn;
                dsUpdateParam["ImageName"].DefaultValue        = strImageName;
                dsUpdateParam["IsShowOnMenu"].DefaultValue     = strIsShowOnMenu;
                dsUpdateParam["IsShowOnHomePage"].DefaultValue = strIsShowOnHomePage;
                dsUpdateParam["IsAvailable"].DefaultValue      = strIsAvailable;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    var strFullPath = "~/res/downloadcategory/" + strConvertedDownloadCategoryName + "-" + strDownloadCategoryID + strImageName.Substring(strImageName.LastIndexOf('.'));

                    if (File.Exists(strOldImagePath))
                    {
                        File.Delete(strOldImagePath);
                    }

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 40, 40);
                }
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oDownloadCategory = new DownloadCategory();
            var lnkDeleteImage    = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strDownloadCategoryID = s[0];
            var strImageName          = s[1];

            oDownloadCategory.DownloadCategoryImageDelete(strDownloadCategoryID);
            DeleteImage(strImageName);
            RadGrid1.Rebind();
        }
    }