コード例 #1
0
        private News GetNewsInfoFromSkin()
        {
            int? newsId = null;
            if (UtilityMethod.GetRequestParameter("nwsId").IsInt32())
                newsId = Convert.ToInt32(UtilityMethod.GetRequestParameter("nwsId"));

            News news = newsId.HasValue ? News_DataProvider.GetNews(newsId.Value) : new News();
            news.Title = txtTitle.Text;
            news.Summary = summaryCtrl.Text;
            news.Body = txtHTMLNewsbody.Text;
            //news.ShowInMarque = isShowInMarqueCtrl.Checked;
            //news.ShowInFirstPage = chkIsShowInFirstPage.Checked;
            //news.ShowInTab = chkShowInTab.Checked;


            news.CreateDateTime = ucNewsDateDime.SelectedDateTime.Value;

            news.StartTracking();
            foreach (GridViewRow newsCat in NewCatsGrid.Rows)
            {

                int catId = (newsCat.FindControl("hdnCategoryId") as HiddenField).Value.ToInt32();
                var catCheck = (newsCat.FindControl("chkCategory") as CheckBox);

                if (news.NewsCategories.Any(o => o.NewsCategoryId == catId))
                {
                    if (!catCheck.Checked)
                        news.NewsCategories.Remove(news.NewsCategories.First(o => o.NewsCategoryId == catId));
                }
                else
                {
                    if (catCheck.Checked)
                    {
                        var cat = new NewsCategory { NewsCategoryId = catId };
                        cat.MarkAsUnchanged();
                        news.NewsCategories.Add(cat);
                    }
                }

            }



            string smallPic = FileUploadUtil.SaveUploadeFile(SmallPicAddress, SystemConfigs.UrlNewsFilesPath, UploadFileType.Pictures, UploadFileSizeLimitation.Unlimited);
            if (!string.IsNullOrWhiteSpace(smallPic))
                news.SmallPicAddress = smallPic;

            string largePic = FileUploadUtil.SaveUploadeFile(PicAddress, SystemConfigs.UrlNewsFilesPath, UploadFileType.Pictures, UploadFileSizeLimitation.Unlimited);
            if (!string.IsNullOrWhiteSpace(largePic))
                news.PicAddress = largePic;

            string bodyFileAddress = FileUploadUtil.SaveUploadeFile(bodyFile, SystemConfigs.UrlNewsFilesPath, UploadFileType.Document, UploadFileSizeLimitation.Unlimited);
            if (!string.IsNullOrWhiteSpace(bodyFileAddress))
                news.BodyFileAddress = bodyFileAddress;

            string mediaFileAddress = FileUploadUtil.SaveUploadeFile(mediaFile, SystemConfigs.UrlNewsFilesPath, UploadFileType.Video | UploadFileType.Sounde, UploadFileSizeLimitation.Unlimited);
            if (!string.IsNullOrWhiteSpace(mediaFileAddress))
                news.MediaFileAddress = mediaFileAddress;

            string realFileAddress = FileUploadUtil.SaveUploadeFile(realFile, SystemConfigs.UrlNewsFilesPath, UploadFileType.Video | UploadFileType.Sounde, UploadFileSizeLimitation.Unlimited);
            if (!string.IsNullOrWhiteSpace(realFileAddress))
                news.RealFileAddress = realFileAddress;


            return news;

        }
コード例 #2
0
        public static void SaveNewsCategory(NewsCategory nwsCat)
        {
            using (var ctx = new BMIKidsEntities(ConnectionString))
            {
                if (nwsCat.ChangeTracker.State == ObjectState.Unchanged)
                    nwsCat.MarkAsModified();

                ctx.NewsCategories.ApplyChanges(nwsCat);
                ctx.SaveChanges();
                nwsCat.AcceptChanges();
            }
        }