public ActionResult Operation(News inputs, string oldUrl)
        {
            ViewBag.userName = User.Identity.Name;
            inputs.author    = Session["USER"].ToString();
            String id = Session["userid"].ToString();

            inputs.User_id = int.Parse(id);
            inputs.date    = DateTime.Now;
            PersianCalendar pc = new PersianCalendar();

            inputs.qdate = pc.GetYear(DateTime.Now) + "/" + pc.GetMonth(DateTime.Now) + "/" + pc.GetDayOfMonth(DateTime.Now);
            if (inputs.id == 0)
            {
                //Create Mode
                #region Create News
                inputs.visitCount = 1000;
                var    image = Request.Files[0];
                string url   = "~/Images/NewsFiles/" + DateTime.Now.Millisecond + image.FileName;
                if (image.FileName != "")
                {
                    if (image.ContentType == "image/jpeg" || image.ContentType == "image/jpg" || image.ContentType == "image/png")
                    {
                        if (image.ContentLength <= 1024000)
                        {
                            image.SaveAs(Server.MapPath(url));
                            inputs.imageUrl = url;
                            ViewBag.msg     = NewsTable.Create(inputs);
                        }
                    }
                }
                #endregion
            }
            else
            {
                //Update Mode
                #region Update News
                var    image = Request.Files[0];
                string url   = "~/Images/NewsFiles/" + DateTime.Now.Millisecond + image.FileName;
                if (image.FileName != "")
                {
                    if (image.ContentType == "image/jpeg" || image.ContentType == "image/jpg" || image.ContentType == "image/png")
                    {
                        if (image.ContentLength <= 1024000)
                        {
                            System.IO.File.Delete(Server.MapPath(oldUrl));
                            image.SaveAs(Server.MapPath(url));
                            inputs.imageUrl = url;
                        }
                    }
                }
                else
                {
                    inputs.imageUrl = oldUrl;
                }
                NewsTable.Update(inputs);
                #endregion
            }
            return(Redirect("/Admin/News"));
        }
Exemplo n.º 2
0
        public ServiceResponse Create([FromBody] NewsModel model)
        {
            if (ValidationService.DuplicateValidate(model))
            {
                return(new ServiceResponse {
                    Response = _news.Create(model)
                });
            }

            return(new ServiceResponse {
                ErrorMessage = "该新闻已存在,请重新输入"
            });
        }
Exemplo n.º 3
0
        public void bntCreate_Click(Object sender, EventArgs e)
        {
            var id          = Page.Request.Params["id"];
            var partOfTitle = Transliterate.PrettyUrl(tbTitle.Text).Trim();
            var news        = new News
            {
                Title      = tbTitle.Text.Trim(),
                Body       = tbBody.Text,
                NewsTypeID = Convert.ToInt32(ddlNewsTypeID.SelectedValue),
                ForViewing = cbForViewing.Checked ? 1 : 0,
            };

            if (id == null)
            {
                news.TitleUrl = String.Format("{0}_{1}", partOfTitle, DateTime.Now.ToString("dd-MM-yy"));
                var similarNews = new News {
                    TitleUrl = news.TitleUrl
                };
                var similarNewsTable = similarNews.GetAllItems("ID", "Desc", "TitleUrl");
                if (similarNewsTable.Tables[0].Rows.Count != 0)
                {
                    lblNotif.Text = "Новость с таким названием существует!";
                    return;
                }
                news.Create();
            }
            else
            {
                var oldNews = new News()
                {
                    ID = Convert.ToInt32(id)
                };
                oldNews.GetById();
                if (oldNews.TitleUrl.Remove(oldNews.TitleUrl.Length - 9, 9) != partOfTitle)
                {
                    news.TitleUrl = String.Format("{0}_{1}", partOfTitle, DateTime.Now.ToString("dd-MM-yy"));
                    var similarNews = new News {
                        TitleUrl = news.TitleUrl
                    };
                    var similarNewsTable = similarNews.GetAllItems("ID", "Desc", "TitleUrl");
                    if (similarNewsTable.Tables[0].Rows.Count != 0)
                    {
                        lblNotif.Text = "Новость с таким названием существует!";
                        return;
                    }
                }
                news.ID = Convert.ToInt32(id);
                news.Update();
            }
            Page.Response.Redirect("~/ManagerUI/Menu/Content/NewsView.aspx");
        }
Exemplo n.º 4
0
 private void CreateNews()
 {
     uploadFileNamePath = ApiFile.Upload(uploadFileName, $"news_{((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString()}", ApiFilePath.News);
     News.Create(new News
     {
         title     = TextBoxTitle.Text,
         messages  = TextBoxMessage.Text,
         date      = DateTimePublication.Value,
         image_url = uploadFileNamePath,
         id_user   = User.GetInstance().id
     });
     MetroMessageBox.Show(this, "Новость опубликована", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Question);
     Close();
 }
Exemplo n.º 5
0
        public ActionResult Create(News news, HttpPostedFileBase UpImageUrls)
        {
            if (ModelState.IsValid)
            {
                if (UpImageUrls != null)
                {
                    if (UpImageUrls.ContentType.IndexOf("image", System.StringComparison.Ordinal) == -1)
                    {
                        ViewBag.Message = "檔案型態錯誤!";
                        return(View(news));
                    }

                    news.UpImageUrl = Utility.SaveUpImage(UpImageUrls);
                    Utility.GenerateThumbnailImage(news.UpImageUrl, UpImageUrls.InputStream, Server.MapPath("~/upfiles/images"), "S", 127, 127);
                }
                System.Threading.Thread.Sleep(1000);

                db.News.Add(news);
                news.Create(db, db.News);
                return(RedirectToAction("Index"));
            }

            return(View(news));
        }