Пример #1
0
    protected bool Valid()
    {
        txtURL.Text = txtURL.Text.Replace("\'", "");
        if (string.IsNullOrEmpty(txtURL.Text))
        {
            MsgErr(Resource.Admin_m_News_NoID);
            return(false);
        }
        if (!UrlService.IsAvalibleUrl(BrandId, ParamType.Brand, txtURL.Text))
        {
            MsgErr(Resource.Admin_SynonymExist);
            return(false);
        }
        if (string.IsNullOrEmpty(txtName.Text))
        {
            MsgErr(Resource.Admin_m_News_NoTitle);
            return(false);
        }

        int sort = 0;

        if (!int.TryParse(txtSortOrder.Text, out sort))
        {
            MsgErr(Resource.Admin_m_Brand_WrongSorting);
            return(false);
        }
        if (FileUpload1.HasFile && !FileHelpers.CheckImageExtension(FileUpload1.FileName))
        {
            MsgErr(Resource.Admin_ErrorMessage_WrongImageExtension);
            return(false);
        }
        MsgErr(true); // Clean
        return(true);
    }
Пример #2
0
    private void SaveNews()
    {
        MsgErr(true); // Clean
        try
        {
            var news = new NewsItem
            {
                NewsID     = NewsId,
                AddingDate = Convert.ToDateTime(txtDate.Text + " " + txtTime.Text),
                Title      = txtTitle.Text,
                //Picture = file,
                TextToPublication = FCKTextToPublication.Text,
                TextAnnotation    = CKEditorControlAnnatation.Text,
                TextToEmail       = string.Empty,//rbNo.Checked ? String.Empty : FCKTextToEmail.Text,
                NewsCategoryID    = dboNewsCategory.SelectedValue.TryParseInt(),
                ShowOnMainPage    = chkOnMainPage.Checked,
                UrlPath           = txtStringID.Text,
                //MetaId = Convert.ToInt32(hfMetaId.Text),
                Meta = new MetaInfo
                {
                    ObjId           = NewsId,
                    Title           = txtHeadTitle.Text,
                    MetaKeywords    = txtMetaKeys.Text,
                    MetaDescription = txtMetaDescription.Text,
                    Type            = MetaType.News
                }
            };

            news.UrlPath = txtStringID.Text;
            NewsService.UpdateNews(news);
            if (FileUpload1.HasFile)
            {
                if (!FileHelpers.CheckImageExtension(FileUpload1.FileName))
                {
                    MsgErr(Resource.Admin_ErrorMessage_WrongImageExtension);
                    return;
                }
                PhotoService.DeletePhotos(NewsId, PhotoType.News);

                var tempName = PhotoService.AddPhoto(new Photo(0, NewsId, PhotoType.News)
                {
                    OriginName = FileUpload1.FileName
                });
                if (!string.IsNullOrWhiteSpace(tempName))
                {
                    using (var image = Image.FromStream(FileUpload1.FileContent))
                        FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.News, tempName), SettingsPictureSize.NewsImageWidth, SettingsPictureSize.NewsImageHeight, image);
                }
            }
            SendNews();
        }
        catch (Exception ex)
        {
            MsgErr(ex.Message + " SaveNews main");
            Debug.LogError(ex);
        }
    }
Пример #3
0
    protected void bthAddCarousel_Click(object sender, EventArgs e)
    {
        lblErrorImage.Text = string.Empty;
        int sort;

        if (!CarouselLoad.HasFile)
        {
            ulValidationFailed.Visible    = true;
            ulValidationFailed.InnerHtml += string.Format("<li>{0}</li>", Resource.Client_Feedback_WrongData);
            return;
        }

        if (CarouselLoad.HasFile && !FileHelpers.CheckImageExtension(CarouselLoad.FileName))
        {
            lblErrorImage.Text = Resource.Admin_ErrorMessage_WrongImageExtension;
            return;
        }

        int.TryParse(txtSortedCarousel.Text, out sort);

        if (string.IsNullOrEmpty(txtURL.Text))
        {
            txtURL.Text = "#";
        }

        var carousel = new Carousel {
            URL = txtURL.Text, SortOrder = sort, Enabled = true
        };
        int id = CarouselService.AddCarousel(carousel);

        try
        {
            if (CarouselLoad.HasFile)
            {
                var tempName = PhotoService.AddPhoto(new Photo(0, id, PhotoType.Carousel)
                {
                    OriginName = CarouselLoad.FileName
                });
                if (!string.IsNullOrWhiteSpace(tempName))
                {
                    using (System.Drawing.Image image = System.Drawing.Image.FromStream(CarouselLoad.PostedFile.InputStream))
                    {
                        FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.Carousel, tempName), SettingsPictureSize.CarouselBigWidth, SettingsPictureSize.CarouselBigHeight, image);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex, "Attempt to load not image file");
        }

        txtURL.Text            = string.Empty;
        txtSortedCarousel.Text = string.Empty;
        Response.Redirect(UrlService.GetAdminAbsoluteLink("Carousel.aspx"));
    }
Пример #4
0
    protected void Upload(object sender, EventArgs e)
    {
        if (FileHelpers.CheckImageExtension(UploadedImageFile.FileName))
        {
            string filename = UniqueFilename(UploadedImageFile.FileName);
            UploadedImageFile.SaveAs(FileImageFolder + filename);

            byte[]     data = ImageMedia.Create(UploadedImageFile.FileBytes).ToByteArray();
            FileStream file = File.Create(FileImageFolder + filename);
            file.Write(data, 0, data.Length);
            file.Close();

            BindImageList();
            ImageList.SelectedValue = filename;
            SelectImage(null, null);
        }
    }
Пример #5
0
    protected void SaveCategory()
    {
        if (_mode == eCategoryMode.Err)
        {
            return;
        }

        int categoryID = _categoryId;

        lblError.Text = string.Empty;
        string synonym = txtSynonym.Text.Trim();

        if (String.IsNullOrEmpty(synonym))
        {
            MsgErr(Resource.Admin_m_Category_NoSynonym);
            return;
        }
        string oldSynonym = UrlService.GetObjUrlFromDb(ParamType.Category, categoryID);

        if (oldSynonym != synonym)
        {
            //Changed by Evgeni to Add synonims in Russian (changed also in aspx)
            var reg = new Regex("^[а-яА-Яa-zA-Z0-9_-]*$");
            if (!reg.IsMatch(synonym))
            {
                MsgErr(Resource.Admin_m_Category_SynonymInfo);
                return;
            }
            if (!UrlService.IsAvalibleUrl(categoryID, ParamType.Category, synonym))
            {
                MsgErr(Resource.Admin_SynonymExist);
                return;
            }
        }

        var c = new Category
        {
            CategoryId                 = categoryID,
            Name                       = txtName.Text,
            ParentCategoryId           = tree.SelectedValue.TryParseInt(),
            Description                = fckDescription.Text == "<br />" || fckDescription.Text == "&nbsp;" || fckDescription.Text == "\r\n" ? string.Empty : fckDescription.Text,
            BriefDescription           = fckBriefDescription.Text == "<br />" || fckBriefDescription.Text == "&nbsp;" || fckBriefDescription.Text == "\r\n" ? string.Empty : fckBriefDescription.Text,
            Enabled                    = ChkEnableCategory.Checked,
            DisplayStyle               = SubCategoryDisplayStyle.SelectedValue,
            DisplayChildProducts       = ChkDisplayChildProducts.Checked,
            DisplayBrandsInMenu        = ChkDisplayBrands.Checked,
            DisplaySubCategoriesInMenu = ChkDisplaySubCategories.Checked,
            UrlPath                    = synonym,
            SortOrder                  = txtSortIndex.Text.TryParseInt()
        };

        FileHelpers.UpdateDirectories();
        if (PictureFileUpload.HasFile)
        {
            PhotoService.DeletePhotos(_categoryId, PhotoType.CategoryBig);
            if (!FileHelpers.CheckImageExtension(PictureFileUpload.FileName))
            {
                MsgErr(Resource.Admin_ErrorMessage_WrongImageExtension);
                return;
            }

            var tempName = PhotoService.AddPhoto(new Photo(0, categoryID, PhotoType.CategoryBig)
            {
                OriginName = PictureFileUpload.FileName
            });
            if (!string.IsNullOrWhiteSpace(tempName))
            {
                using (Image image = Image.FromStream(PictureFileUpload.FileContent))
                    FileHelpers.SaveResizePhotoFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Big, tempName), SettingsPictureSize.BigCategoryImageWidth, SettingsPictureSize.BigCategoryImageHeight, image);
            }
        }


        if (MiniPictureFileUpload.HasFile)
        {
            PhotoService.DeletePhotos(_categoryId, PhotoType.CategorySmall);

            if (!FileHelpers.CheckImageExtension(MiniPictureFileUpload.FileName))
            {
                MsgErr(Resource.Admin_ErrorMessage_WrongImageExtension);
                return;
            }

            var tempName = PhotoService.AddPhoto(new Photo(0, categoryID, PhotoType.CategorySmall)
            {
                OriginName = MiniPictureFileUpload.FileName
            });
            if (!string.IsNullOrWhiteSpace(tempName))
            {
                using (Image image = Image.FromStream(MiniPictureFileUpload.FileContent))
                    FileHelpers.SaveResizePhotoFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Small, tempName), SettingsPictureSize.SmallCategoryImageWidth, SettingsPictureSize.SmallCategoryImageHeight, image);
            }
        }

        c.Meta = new MetaInfo(0, c.CategoryId, MetaType.Category, txtTitle.Text, txtMetaKeywords.Text, txtMetaDescription.Text);

        if (!CategoryService.UpdateCategory(c, true))
        {
            MsgErr("Failed to save category");
        }
    }