public async Task <IActionResult> Add(News news)
        {
            if (ModelState.IsValid)
            {
                News new_news = new News();
                new_news.SubCategoryId = news.SubCategoryId;
                new_news.ShortDesc     = news.ShortDesc;
                new_news.Text          = news.Text;
                new_news.CreatedDate   = DateTime.Now;

                db.News.Add(new_news);

                foreach (var photo in news.PhotoNames)
                {
                    NewsPhoto newsPhoto = new NewsPhoto();
                    newsPhoto.News  = new_news;
                    newsPhoto.Photo = photo;
                    db.NewsPhotos.Add(newsPhoto);
                }

                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Exemple #2
0
        private void lstHaberler_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            Haberler haber = (Haberler)lstHaberler.SelectedItem;

            NewsPhoto.Load(haber.Image);
            lblDescription.Text = haber.Description;
        }
Exemple #3
0
        public async Task UpdateNewsPhoto(NewsPhoto newsPhotoToUpdate, NewsPhoto newsPhoto)
        {
            newsPhotoToUpdate.Main       = newsPhoto.Main;
            newsPhotoToUpdate.ModifiedAt = DateTime.Now;
            newsPhotoToUpdate.ModifiedBy = newsPhoto.ModifiedBy;

            await _context.SaveChangesAsync();
        }
Exemple #4
0
        public async Task RemovePhotoById(int id)
        {
            NewsPhoto newsPhoto = await _context.NewsPhotos.FindAsync(id);

            var n = await _context.NewsPhotos.Where(e => e.NewsId == newsPhoto.NewsId && e.OrderBy > newsPhoto.OrderBy).OrderBy(e => e.OrderBy).ToListAsync();

            _context.NewsPhotos.Remove(newsPhoto);
            await _context.SaveChangesAsync();

            foreach (var item in n)
            {
                item.OrderBy -= 1;
                await _context.SaveChangesAsync();
            }
        }
Exemple #5
0
        public ActionResult UploadNewsPhotos(string[] photoFiles, string[] photoNames, int id)
        {
            var _res = _NewsService.GetNewsByID(id);

            for (int i = 0; i < photoFiles.Length; i++)
            {
                byte[] bytes = Convert.FromBase64String(photoFiles[i].Split(',')[1]);
                var    path  = _storageService.SetNewsPhotoStoragePath(Server.MapPath(GlobalConst.FolderName.Storage + GlobalConst.ConstantChar.DoubleBackSlash + GlobalConst.FolderName.Org + _res.OrganizationID), photoNames[i]);
                using (System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.Create))
                {
                    stream.Write(bytes, 0, bytes.Length);
                    stream.Flush();
                }
                NewsPhoto newsPhotoobj = new NewsPhoto();
                newsPhotoobj.NewsID     = id;
                newsPhotoobj.NewsPhotos = Path.GetFileName(path);
                var NewsPhotoID = _NewsService.AddNewsPhoto(Mapper.Map <HCRGUniversityMgtApp.NEPService.NewsService.NewsPhoto>(newsPhotoobj));
            }

            return(Json("Photos added Successfully", GlobalConst.Message.text_html));
        }
Exemple #6
0
        public IActionResult Upload(IFormFile file, int?newsId, int?orderBy)
        {
            var filename = _fileManager.Upload(file);
            var publicId = _cloudinaryService.Store(filename);

            _fileManager.Delete(filename);
            if (newsId != null)
            {
                NewsPhoto newsPhoto = new NewsPhoto
                {
                    ModifiedBy = _admin.Fullname,
                    CreatedAt  = DateTime.Now,
                    Image      = publicId,
                    NewsId     = (int)newsId,
                    OrderBy    = (int)orderBy
                };
                _newsService.AddPhoto(newsPhoto);
            }
            return(Ok(new
            {
                filename = publicId,
                src = _cloudinaryService.BuildUrl(publicId)
            }));
        }
Exemple #7
0
        protected void btnSave2_Click(object sender, EventArgs e)
        {
            try
            {
                hdTabIndex.Value = "2";
                if (string.IsNullOrEmpty(tbTitle2.Text.Trim()))
                {
                    lbErr2.Text = "请输入标题";
                    tbTitle2.Focus();
                    return;
                }
                HttpFileCollection files=HttpContext.Current.Request.Files;
                if (files.Count==0)
                {
                    lbErr.Text = "请上传图片";
                    file.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(tbContentUrl2.Text.Trim()))
                {
                    lbErr2.Text = "请输入内容地址";
                    tbContentUrl2.Focus();
                    return;
                }
                HttpPostedFile postedFile = files[0];
                if (postedFile.ContentLength > 20971520)
                {

                    lbErr2.Text = "图片不能大于20M,请重新上传";
                    file.Focus();
                    return;
                }
                string fileSHowName = postedFile.FileName;
                int dotIndex = postedFile.FileName.IndexOf("\\");
                string fileName = string.Empty;
                if (dotIndex == -1)
                {
                    fileName = CY.Utility.Common.FileUtility.GetFileName(postedFile.FileName);//文件名
                }
                else
                {
                    string fileNameTemp = CY.Utility.Common.FileUtility.GetFileName(postedFile.FileName);
                    int indElx = fileNameTemp.LastIndexOf("\\") + 1;
                    fileName = fileNameTemp.Substring(indElx);
                }
                string fileExtension = CY.Utility.Common.FileUtility.GetFileExtension(postedFile.FileName);//后缀名
                if (fileExtension != ".jpg" && fileExtension != ".jpeg" && fileExtension != ".gif" && fileExtension != ".bmp" && fileExtension != ".png")
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('请选择正确的图片格式');</script>");
                    return;
                }
                else
                {
                    string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;//绝对路径
                    string dirPath = appPath + CY.Utility.Common.AnnexUtility.PhotoNewsDir;
                    DirectoryInfo dir = new DirectoryInfo(dirPath);
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                    string saveFileName = fileName + DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString();
                    postedFile.SaveAs(dirPath + "\\" + saveFileName + fileExtension);
                    string photosrc = "../../../Content/PhotoNews/" + saveFileName + fileExtension;
                    NewsPhoto newsPhoto = new NewsPhoto();
                    newsPhoto.Title = tbTitle2.Text.Trim();
                    newsPhoto.PhotoSrc = photosrc;
                    newsPhoto.ContentUrl = tbContentUrl2.Text.Trim();
                    newsPhoto.AddDate = DateTime.Now;
                    newsPhoto.Author = userSession.Code;//Session["UserName"]
                    newsPhoto.Save();
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('新增成功');window.location.href='PhotoNewsList.aspx'</script>");
                }
            }
            catch (Exception ex)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('" + ex.Message + "')</script>");
            }
        }
Exemple #8
0
 /*没用*/
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         hdTabIndex.Value = "1";
         if (string.IsNullOrEmpty(tbTitle.Text.Trim()))
         {
             lbErr.Text = "请输入标题";
             tbTitle.Focus();
             return;
         }
         if (string.IsNullOrEmpty(tbSrc.Text.Trim()))
         {
             lbErr.Text = "请输入图片地址";
             tbSrc.Focus();
             return;
         }
         if (string.IsNullOrEmpty(tbContentUrl.Text.Trim()))
         {
             lbErr.Text = "请输入内容地址";
             tbContentUrl.Focus();
             return;
         }
         NewsPhoto newsPhoto = new NewsPhoto();
         newsPhoto.Title = tbTitle.Text.Trim();
         newsPhoto.PhotoSrc = tbSrc.Text.Trim();
         newsPhoto.ContentUrl = tbContentUrl.Text.Trim();
         newsPhoto.AddDate = DateTime.Now;
         newsPhoto.Author = userSession.Code;;//Session["UserName"]
         newsPhoto.Save();
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('新增成功');window.location.href='PhotoNewsList.aspx'</script>");
     }
     catch (Exception ex)
     {
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"","<script>alert('"+ex.Message+"')</script>");
     }
 }
Exemple #9
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddNews_Click(object sender, EventArgs e)
        {
            try
            {
                Guid pID = new Guid();//模块ID
                if (ddlModuleP.SelectedValue == "0")
                {
                    lbErr.Text = "请选择模块";
                    return;
                }
                else if (ddlModuleP.SelectedValue != "0")
                {
                    if (Request.Form["ddlModuleSub"] != "0" && Request.Form["ddlModuleSub"] != null)
                    {
                        pID = new Guid(Request.Form["ddlModuleSub"].ToString());
                    }
                    else
                    {
                        pID = new Guid(ddlModuleP.SelectedValue.ToString());
                    }
                }
                if (string.IsNullOrEmpty(tbTitle.Text.Trim()))
                {
                    lbErr.Text = "请输入标题";
                    tbTitle.Focus();
                    return;
                }
                if (radioIsPhotoY.Checked)//是图片新闻
                {
                    if (!IsPhoto())
                    {
                        lbErr.Text = "内容不包含图片不能设置成图片新闻";
                        radioIsPhotoN.Focus();
                        return;
                    }
                }
                NewsContent newsC = new NewsContent();
                newsC.ModuleID = pID;
                newsC.Title = tbTitle.Text.Trim();
                int tag = 0;
                if (string.IsNullOrEmpty(tbTag.Text.Trim()))
                {
                    newsC.Tag = 2;//没有
                    tag = 2;
                }
                else
                {
                    newsC.Tag = 1;//有
                    tag = 1;
                }
                newsC.Source = tbSource.Text.Trim();
                newsC.Content = fck.Value;
                string status = hdStatus.Value;
                if (status == "1")
                {
                    newsC.Status = 2;//发表
                }
                else if (status == "2")
                {
                    newsC.Status = 1;//保存
                }

                newsC.Author = userSession.Name;
                if (!string.IsNullOrEmpty(tbPubTime.Text.Trim()))
                {
                    newsC.PublishTime = DateTime.Parse(tbPubTime.Text.Trim());
                }
                else
                {
                    newsC.PublishTime = DateTime.Now;
                }
                HttpFileCollection files = HttpContext.Current.Request.Files;
                bool hasAnnex = false;
                if (files[0].FileName == "" || files[0].ContentLength == 0)
                {
                    newsC.Annex = 2;//没有附件
                    hasAnnex = false;
                }
                else
                {
                    newsC.Annex = 1;//有附件
                    hasAnnex = true;
                }
                newsC.Index = int.Parse(ddlIndex.SelectedValue.ToString());
                newsC.Traffic = 0;
                if (!string.IsNullOrEmpty(tbSortTime.Text.Trim()))
                {
                    newsC.SortTime = DateTime.Parse(tbSortTime.Text.Trim());
                }
                else
                {
                    newsC.SortTime = DateTime.Now;
                }
                newsC.Save();
                if (tag == 1)
                {
                    /*Tag*/
                    if (!string.IsNullOrEmpty(tbTag.Text.Trim()))
                    {
                        string tagTemp = tbTag.Text.Trim();
                        if (tagTemp.Contains(","))
                        {
                            tagTemp = tagTemp.Replace(",", ",");
                        }
                        else if (tagTemp.Contains(" "))
                        {
                            tagTemp = tagTemp.Replace(" ", ",");
                        }
                    }
                }
                if (radioIsPhotoY.Checked)
                {
                    /*图片新闻*/
                    string url = GetPhotoSrc(fck.Value);
                    NewsPhoto newsPhoto = new NewsPhoto();
                    newsPhoto.Status = 2;//内容新闻
                    newsPhoto.ContentID = newsC.Id;
                    newsPhoto.Title = newsC.Title;
                    newsPhoto.Author = newsC.Author;
                    newsPhoto.PhotoSrc = url;
                    newsPhoto.AddDate = newsC.PublishTime;
                    newsPhoto.Save();
                }
                if (hasAnnex == true)
                {
                    SaveAttach(newsC.Id);
                }
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript' >alert('新增成功');window.location.href='NewsList.aspx';</script>");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void btnApplication_Click(object sender, EventArgs e)
        {
            Guid pID = new Guid();//模块ID
            if (ddlModuleP.SelectedValue == "0")
            {
                lbErr.InnerText = "请选择模块";
                return;
            }
            else if (ddlModuleP.SelectedValue != "0")
            {
                pID = new Guid(ddlModuleP.SelectedValue);
                List<CY.CSTS.Core.Business.NewsModule> ListM = CY.CSTS.Core.Business.NewsModule.GetNewsModuleList(" WBS like '%" + pID + ".%' ")
                       as List<CY.CSTS.Core.Business.NewsModule>;

                if (ListM.Count > 0 && Request.Form["ddlModuleSub"] != "0" && Request.Form["ddlModuleSub"] != null)
                {
                    string pid = Request.Form["ddlModuleSub"].ToString();
                    pID = new Guid(pid);
                }
                else
                {
                    pID = new Guid(ddlModuleP.SelectedValue.ToString());
                }
            }
            if (string.IsNullOrEmpty(tbTitle.Text.Trim()))
            {
                lbErr.InnerText = "请输入标题";
                tbTitle.Focus();
                return;
            }
            if (radioIsPhotoY.Checked)//是图片新闻
            {
                if (!IsPhoto())
                {
                    lbErr.InnerText = "内容不包含图片不能设置成图片新闻";
                    radioIsPhotoN.Focus();
                    return;
                }
            }

            NewsContent newsC = NewsContent.Load(newsID);
            newsC.Title = tbTitle.Text.Trim();
            newsC.ModuleID = pID;
            int tag = 0;
            if (string.IsNullOrEmpty(tbTagName.Text.Trim()))
            {
                newsC.Tag = 2;//没有
                tag = 2;
            }
            else
            {
                newsC.Tag = 1;//有
                tag = 1;
            }
            if (!string.IsNullOrEmpty(tbPubTime.Text.Trim()))
            {
                newsC.PublishTime = DateTime.Parse(tbPubTime.Text.Trim());
            }
            newsC.Source = tbSource.Text.Trim();
            newsC.Content = fck.Value;

            newsC.Status = 3;//申请
            CY.CSTS.Core.Business.NewsModule m = CY.CSTS.Core.Business.NewsModule.Load(newsC.ModuleID);
            if (m != null)
            {
                if (m.CheckStatus == 1)
                {
                    newsC.Status = 2;//发表状态
                }
            }

            int isAnnex = IsAnnex();
            newsC.Annex = isAnnex;
            newsC.Author = userSession.UserID;
            newsC.Index = int.Parse(ddlIndex.SelectedValue.ToString());
            newsC.SortTime = DateTime.Parse(tbSortTime.Text.Trim());
            newsC.Save();
            if (tag == 1)
            {
                if (!string.IsNullOrEmpty(tbTagName.Text.Trim()))
                {
                    string tagTemp = tbTagName.Text.Trim();
                    if (tagTemp.Contains(","))
                    {
                        tagTemp = tagTemp.Replace(",", ",");
                    }
                    else if (tagTemp.Contains(" "))
                    {
                        tagTemp = tagTemp.Replace(" ", ",");
                    }
                    CY.CSTS.Core.Business.Tag tagCore = new CY.CSTS.Core.Business.Tag();
                    tagCore.ContentID = newsC.Id;
                    tagCore.TagName = tagTemp;
                    tagCore.ContentType = 2;//信息
                    tagCore.Save();
                }
            }
            if (isAnnex == 1)
            {
                SaveAttach(newsC.Id);
            }
            if (radioIsPhotoY.Checked)
            {
                List<NewsPhoto> listPhoto = NewsPhoto.SelectNewsPhotosDynamic(" ContentID ='" + newsC.Id.ToString() + "'")
                                                            as List<NewsPhoto>;
                if (listPhoto.Count > 0)
                {
                   NewsPhoto np = listPhoto[0];
                   string url = GetPhotoSrc(fck.Value);
                   np.Status = 2;//内容新闻
                   np.ContentID = newsC.Id;
                   np.Title = newsC.Title;
                   np.Author = newsC.Author;
                   np.PhotoSrc = url;
                   np.AddDate = newsC.PublishTime;
                   np.Save();
                }
                else
                {
                    /*图片新闻*/
                    string url = GetPhotoSrc(fck.Value);
                    NewsPhoto newsPhoto = new NewsPhoto();
                    newsPhoto.Status = 2;//内容新闻
                    newsPhoto.ContentID = newsC.Id;
                    newsPhoto.Title = newsC.Title;
                    newsPhoto.Author = newsC.Author;
                    newsPhoto.PhotoSrc = url;
                    newsPhoto.AddDate = newsC.PublishTime;
                    newsPhoto.Save();
                }

            }
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('申请成功');window.location.href='UserNewsPreview.aspx?id=" + newsID + "&tabIndex=" + hdTabIndex.Value + "'</script>");
        }
Exemple #11
0
        public async Task AddPhoto(NewsPhoto newsPhoto)
        {
            await _context.NewsPhotos.AddAsync(newsPhoto);

            await _context.SaveChangesAsync();
        }
Exemple #12
0
        //private void BindHeader()
        //{
        //    if (ddlModuleP.SelectedValue != "0")
        //    {
        //        string moduleName = ddlModuleP.SelectedItem.Text;
        //        NewsModule m = NewsModule.SelectByName(moduleName);
        //        int isChedk = m.CheckStatus;
        //        if (isChedk == 1)//不需要审核
        //        {
        //            status = 2;//发表
        //            btnApplication.Visible = false;
        //        }
        //        else if (isChedk == 2)//需要审核
        //        {
        //            status = 3;//申请
        //            btnApplication.Visible = true;
        //        }
        //    }
        //}
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddNews_Click(object sender, EventArgs e)
        {
            string strMidList = hdSelectModuleList.Value;

            if (strMidList != "")
            {
                string[] listMID = strMidList.Split(',');
                for (int i = 0; i < listMID.Length; i++)
                {
                    if (CY.Utility.Common.StringHelper.IsGuid(listMID[i]))
                    {
                        #region 添加新闻
                        try
                        {

                            //Guid pID = new Guid();//模块ID
                            ////if (ddlModuleP.SelectedValue == "0")
                            //{

                            //}
                            ////else if (ddlModuleP.SelectedValue != "0")
                            //{
                            //    pID = new Guid(ddlModuleP.SelectedValue);
                            //    List<CY.CSTS.Core.Business.NewsModule> ListM = CY.CSTS.Core.Business.NewsModule.GetNewsModuleList(" WBS like '%" + pID + ".%' ")
                            //          as List<CY.CSTS.Core.Business.NewsModule>;

                            //    if (ListM.Count > 0 && Request.Form["ddlModuleSub"] != "0" && Request.Form["ddlModuleSub"] != null)
                            //    {
                            //        pID = new Guid(Request.Form["ddlModuleSub"].ToString());
                            //    }
                            //    else
                            //    {
                            //        pID = new Guid(ddlModuleP.SelectedValue.ToString());
                            //    }
                            //}
                            if (string.IsNullOrEmpty(tbTitle.Text.Trim()))
                            {
                                lbErr.Text = "请输入标题";
                                tbTitle.Focus();
                                return;
                            }
                            if (radioIsPhotoY.Checked)//是图片新闻
                            {
                                if (!IsPhoto())
                                {
                                    lbErr.Text = "内容不包含图片不能设置成图片新闻";
                                    radioIsPhotoN.Focus();
                                    return;
                                }
                            }
                            NewsContent newsC = new NewsContent();
                            newsC.ModuleID = new Guid(listMID[i]);
                            newsC.Title = tbTitle.Text.Trim();
                            int tag = 0;
                            if (string.IsNullOrEmpty(tbTag.Text.Trim()))
                            {
                                newsC.Tag = 2;//没有
                                tag = 2;
                            }
                            else
                            {
                                newsC.Tag = 1;//有
                                tag = 1;
                            }
                            newsC.Source = tbSource.Text.Trim();
                            newsC.Content = fck.Value;
                            string status = hdStatus.Value;
                            if (status == "1")
                            {
                                newsC.Status = 2;//发表
                            }
                            else if (status == "2")
                            {
                                newsC.Status = 1;//保存
                            }
                            newsC.Author = userSession.UserID;
                            if (!string.IsNullOrEmpty(tbPubTime.Text.Trim()))
                            {
                                newsC.PublishTime = DateTime.Parse(tbPubTime.Text.Trim());
                            }
                            else
                            {
                                newsC.PublishTime = DateTime.Now;
                            }
                            HttpFileCollection files = HttpContext.Current.Request.Files;
                            bool hasAnnex = false;
                            if (files[0].FileName == "" || files[0].ContentLength == 0)
                            {
                                newsC.Annex = 2;//没有附件
                                hasAnnex = false;
                            }
                            else
                            {
                                newsC.Annex = 1;//有附件
                                hasAnnex = true;
                            }
                            newsC.Index = int.Parse(ddlIndex.SelectedValue.ToString());
                            newsC.Traffic = 0;
                            if (!string.IsNullOrEmpty(tbSortTime.Text.Trim()))
                            {
                                newsC.SortTime = DateTime.Parse(tbSortTime.Text.Trim());
                            }
                            else
                            {
                                newsC.SortTime = DateTime.Now;
                            }
                            newsC.Save();
                            if (tag == 1)
                            {
                                /*Tag*/
                                if (!string.IsNullOrEmpty(tbTag.Text.Trim()))
                                {
                                    string tagTemp = tbTag.Text.Trim();
                                    if (tagTemp.Contains(","))
                                    {
                                        tagTemp = tagTemp.Replace(",", ",");
                                    }
                                    else if (tagTemp.Contains(" "))
                                    {
                                        tagTemp = tagTemp.Replace(" ", ",");
                                    }
                                    CY.CSTS.Core.Business.Tag tagT = new CY.CSTS.Core.Business.Tag();
                                    tagT.ContentID = newsC.Id;
                                    tagT.TagName = tagTemp;
                                    tagT.ContentType = 2;//信息
                                    tagT.Save();
                                }
                            }
                            if (radioIsPhotoY.Checked)
                            {
                                /*图片新闻*/
                                string url = GetPhotoSrc(fck.Value);
                                NewsPhoto newsPhoto = new NewsPhoto();
                                newsPhoto.Status = 2;//内容新闻
                                newsPhoto.ContentID = newsC.Id;
                                newsPhoto.Title = newsC.Title;
                                newsPhoto.Author = newsC.Author;
                                newsPhoto.PhotoSrc = url;
                                newsPhoto.AddDate = newsC.PublishTime;
                                newsPhoto.Save();
                            }
                            if (hasAnnex == true)
                            {
                                SaveAttach(newsC.Id);
                            }
                            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('新增成功');window.location.href='UserNewsList.aspx'</script>");
                        }
                        catch (Exception ex)
                        {
                            lbErr.Text = ex.Message;
                        }
                        #endregion
                    }
                }
            }
            else
            {
                lbErr.Text = "请选择模块";
                return;
            }
        }