예제 #1
0
        public static bool UpdateNews(NewsItem news)
        {
            CacheManager.Remove(CacheNames.GetNewsForMainPage());

            SQLDataAccess.ExecuteNonQuery("[Settings].[sp_UpdateNews]", CommandType.StoredProcedure,
                                            new[]
                                                        {
                                                            new SqlParameter("@NewsID", news.NewsID),
                                                            new SqlParameter("@NewsCategoryID", news.NewsCategoryID),
                                                            new SqlParameter("@AddingDate", news.AddingDate),
                                                            new SqlParameter("@Title", news.Title),
                                                            //new SqlParameter("@Picture", news.Picture),
                                                            new SqlParameter("@TextToPublication", news.TextToPublication),
                                                            new SqlParameter("@TextToEmail", news.TextToEmail),
                                                            new SqlParameter("@TextAnnotation", news.TextAnnotation),
                                                            new SqlParameter("@ShowOnMainPage", news.ShowOnMainPage),
                                                            new SqlParameter("@UrlPath", news.UrlPath)
                                                        }
                                        );
            if (news.Meta != null)
            {
                if (news.Meta.Title.IsNullOrEmpty() && news.Meta.MetaKeywords.IsNullOrEmpty() && news.Meta.MetaDescription.IsNullOrEmpty() && news.Meta.H1.IsNullOrEmpty())
                {
                    if (MetaInfoService.IsMetaExist(news.ID, MetaType.News))
                        MetaInfoService.DeleteMetaInfo(news.ID, MetaType.News);
                }
                else
                    MetaInfoService.SetMeta(news.Meta);
            }
            return true;
        }
예제 #2
0
        private void SaveNews()
        {
            MsgErr(true); // Clean
            try
            {
                var news = new NewsItem
                    {
                        NewsID = NewsId,
                        AddingDate = SQLDataHelper.GetDateTime(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 = SQLDataHelper.GetInt(hfMetaId.Text),
                        Meta = new MetaInfo
                            {
                                ObjId = NewsId,
                                Title = txtHeadTitle.Text,
                                H1 = txtH1.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
 public static int InsertNews(NewsItem news)
 {
     CacheManager.Remove(CacheNames.GetNewsForMainPage());
     var id = SQLDataAccess.ExecuteScalar<int>("[Settings].[sp_AddNews]", CommandType.StoredProcedure,
                                                              new[]
                                                                     {
                                                                         new SqlParameter("@NewsCategoryID", news.NewsCategoryID),
                                                                         new SqlParameter("@AddingDate", news.AddingDate),
                                                                         new SqlParameter("@Title", news.Title),
                                                                         //new SqlParameter("@Picture", news.Picture),
                                                                         new SqlParameter("@TextToPublication", news.TextToPublication),
                                                                         new SqlParameter("@TextToEmail", news.TextToEmail),
                                                                         new SqlParameter("@TextAnnotation", news.TextAnnotation),
                                                                         new SqlParameter("@ShowOnMainPage", news.ShowOnMainPage),
                                                                         new SqlParameter("@UrlPath", news .UrlPath  )
                                                                     });
     // ---- Meta
     if (news.Meta != null)
     {
         if (!news.Meta.Title.IsNullOrEmpty() || !news.Meta.MetaKeywords.IsNullOrEmpty() || !news.Meta.MetaDescription.IsNullOrEmpty() || !news.Meta.H1.IsNullOrEmpty())
         {
             news.Meta.ObjId = id;
             MetaInfoService.SetMeta(news.Meta);
         }
     }
     return id;
 }
예제 #4
0
        private void CreateNews()
        {
            MsgErr(true); // Clean

            try
            {
                //const string format = "yyyy-MM-dd";
                var news = new NewsItem
                    {
                        AddingDate = SQLDataHelper.GetDateTime(txtDate.Text + " " + txtTime.Text),
                        Title = txtTitle.Text,
                        //Picture = file,
                        TextToPublication = FCKTextToPublication.Text,
                        TextAnnotation = CKEditorControlAnnatation.Text,
                        TextToEmail = String.Empty,
                        NewsCategoryID = dboNewsCategory.SelectedValue.TryParseInt(),
                        ShowOnMainPage = chkOnMainPage.Checked,
                        UrlPath = txtStringID.Text,
                        Meta = new MetaInfo
                            {
                                MetaDescription = txtMetaDescription.Text,
                                Title = txtHeadTitle.Text,
                                MetaKeywords = txtMetaKeys.Text,
                                H1 = txtH1.Text
                            }
                    };
                var id = NewsService.InsertNews(news);
                if (FileUpload1.HasFile)
                {
                    var tempName = PhotoService.AddPhoto(new Photo(0, id, PhotoType.News) { OriginName = FileUpload1.FileName });
                    if (!string.IsNullOrWhiteSpace(tempName))
                    {
                        using (Image image = Image.FromStream(FileUpload1.FileContent))
                            FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.News, tempName), SettingsPictureSize.NewsImageWidth, SettingsPictureSize.NewsImageHeight, image);
                    }
                }
                SendNews();
                if (lblError.Visible == false)
                {
                    txtTitle.Text = string.Empty;
                    FCKTextToPublication.Text = string.Empty;
                    //FCKTextToEmail.Text = string.Empty;
                    rbToAll.Checked = true;
                }
                // close
            }
            catch (Exception ex)
            {
                MsgErr(ex.Message + " CreateNews main");
                Debug.LogError(ex);
            }
        }