예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RedisKeyService redisKeyService = new RedisKeyService();

            NewsService newsService = new NewsService();

            newsService.Add(new NewsEntity
            {
                Id     = 123,
                Title  = "Demo title",
                Status = 1
            });
            newsService.Add(new NewsEntity
            {
                Id     = 1234,
                Title  = "Demo title",
                Status = 1
            });

            redisKeyService.Add(new RedisKeyEntity
            {
                Id     = 123567,
                Name   = "Nguyễn Văn A",
                Status = 1
            });

            var obj = redisKeyService.Get(typeof(RedisKeyEntity).Name);

            var obj2 = newsService.GetList(typeof(NewsEntity).Name);

            //Response.Write(obj2[0].Title + "<br/>"+obj.Name);
        }
예제 #2
0
        protected void btnSubmit_OnClick(object sender, EventArgs e)
        {
            Model.News news = new Model.News()
            {
                News_Title   = this.txtName.Text,
                News_Content = this.txtNewsContent.Value,
                News_Image   = upFileName(FileUpload1, "../../upload/news/")
            };

            var       res = newsSvc.Add(news);
            ReturnMsg rs  = res > 0
                ? new ReturnMsg()
            {
                Code    = StatusCode.Ok,
                Message = "添加新闻成功",
                Data    = null
            }
                : new ReturnMsg()
            {
                Code    = StatusCode.Error,
                Message = "添加新闻失败",
                Data    = null
            };

            Session["Msg"] = rs;
            Response.Redirect("News_List.aspx");
        }
예제 #3
0
        public ActionResult Add()
        {
            var news = new News {
                Title = "智障专用", Author = "cl", ImagePath = "hello", NewsMsg = "1290dgwstrsdgfsgfsd", SubTime = DateTime.Now.ToString()
            };
            var result = NewsService.Add(news);

            return(Content("ok:添加成功"));
        }
예제 #4
0
 public ActionResult NewsAdd(int?id, string date, int?views, int category, string title, string shortDesc, string body, HttpPostedFileBase image)
 {
     if (Session["userId"] == null)
     {
         return(Redirect("/Home/Authorization"));
     }
     try
     {
         string path = null;
         if (image != null)
         {
             path = GetImageUrl(Path.GetExtension(image.FileName)) + Path.GetExtension(image.FileName);
             image.SaveAs(path);
             path = Path.GetFileName(path);
         }
         NewsService service = new NewsService(Server.MapPath("~/Content/Upload/Entities/"));
         if (id.HasValue)
         {
             service.UpdElement(new News
             {
                 Title         = title,
                 Body          = body,
                 CategoryId    = category,
                 DateCreate    = DateTime.Parse(date),
                 Description   = shortDesc,
                 Id            = id.Value,
                 ImageUrl      = path,
                 NumberOfViews = views.Value,
                 UserId        = (int)Session["userId"]
             });
         }
         else
         {
             service.Add(new News
             {
                 Title       = title,
                 Body        = body,
                 CategoryId  = category,
                 Description = shortDesc,
                 ImageUrl    = path,
                 UserId      = (int)Session["userId"]
             });
         }
         return(Redirect("/Message/MessageShow/?message=" + "Успешно сохранено" + "&href=" + Request.Url));
     }
     catch (Exception ex)
     {
         string message = "";
         while (ex != null)
         {
             message = ex.Message;
             ex      = ex.InnerException;
         }
         message = message.Replace('\n', ' ');
         return(Redirect("/Message/MessageShow/?message=" + message + "&href=" + Request.Url));
     }
 }
예제 #5
0
        public void AddTest()
        {
            News data = new News();

            data.Title   = "Toshiba shares slide on renewed earnings delay";
            data.Content = "The extension still needs regulatory approval. Failure to obtain that will mean Toshiba has to submit earnings by 27 March or face delisting from the stock exchange.";

            var target = new NewsService();

            Assert.IsTrue(target.Add(data));
        }
예제 #6
0
        public ActionResult AddNews(News data)
        {
            if (data == null)
            {
                return(View("Index"));
            }

            var service  = new NewsService();
            var viewList = service.Add(data);

            System.Threading.Thread.Sleep(1000);
            return(View("Index"));
        }
        protected void btnKaydet_Click(object sender, EventArgs e)
        {
            try
            {
                News     news           = new News();
                string   selectLanguage = ddlLanguage.SelectedItem.Text;
                Language language       = (from l in db.Language where l.LanguageName == selectLanguage && l.IsActive == true select l).FirstOrDefault();
                Users    newsUser       = (Users)Session["user"];

                news.Title        = txtBaslik.Text;
                news.SmallWriting = txtKucukYazi.Text;
                news.BigWriting   = txtBuyukYazi.Text;
                news.Image        = lblInfo.Text;
                news.NewsDate     = DateTime.Now;
                news.UserID       = newsUser.ID;
                news.LanguageID   = language.ID;
                if (int.Parse(RadioButtonList1.SelectedItem.Value) == 1)
                {
                    news.IsActive = true;
                }
                else
                {
                    news.IsActive = false;
                }
                news.CreatedBy   = newsUser.ID;
                news.CreatedDate = DateTime.Now;

                _news.Add(news);

                clear();
                Butonvisible(true);
                panelVisible(true, true, false, false);
                Uyari("Kayıt işlemi başarıyla gerçekleşti", true);
            }
            catch (Exception)
            {
                if (txtBaslik.Text.Length > 100)
                {
                    Uyari("Başlık 100 karakterden daha uzun girilemez!", false);
                }
                else if (txtKucukYazi.Text.Length > 500)
                {
                    Uyari("Küçük yazı 500 karakterden daha uzun girilemez!", false);
                }
                else
                {
                    Uyari("Kayıt işlemi sırasında bir hata oluştu", false);
                }
            }
        }
예제 #8
0
        private async void Add()
        {
            ProgressDialog dialog = new ProgressDialog(this);

            dialog.SetTitle("评论");
            dialog.SetMessage("提交评论中.....");
            string body      = edit_content.Text.TrimEnd().TrimStart();
            var    userToken = UserTokenUtil.GetToken(this);

            if (userToken.IsExpire)
            {
                AlertDialog.Builder alertDialog = new AlertDialog.Builder(this)
                                                  .SetTitle("登录提示")
                                                  .SetMessage("未登录或登录token已经过期")
                                                  .SetPositiveButton("授权", (s, e) =>
                {
                    StartActivity(new Intent(this, typeof(loginactivity)));
                })
                                                  .SetNegativeButton("取消", (s, e) =>
                {
                    return;
                });
                alertDialog.Create().Show();
            }
            if (string.IsNullOrEmpty(body))
            {
                AlertUtil.ToastShort(this, "请输入内容");
                return;
            }
            dialog.Show();
            var result = await NewsService.Add(userToken, PARENTID, POSTID, body);

            if (result.Success)
            {
                dialog.Hide();
                AlertUtil.ToastShort(this, "评论成功");
                edit_content.Text  = "";
                btn_submit.Enabled = false;
                OnRefresh();
            }
            else
            {
                dialog.Hide();
                AlertUtil.ToastShort(this, result.Message);
                btn_submit.Enabled = true;
            }
        }
예제 #9
0
        public virtual IHttpActionResult Add(NewsAddRequest request)
        {
            var entity = new News
            {
            };
            var result = _newsService.Add(entity);

            if (result > 0)
            {
                return(Succeed(new NewsAddResponse
                {
                    Id = entity.Id
                }, "新增成功"));
            }
            else
            {
                return(Fail("新增失败"));
            }
        }
예제 #10
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="context"></param>
        public void AddNewsRequest(HttpContext context)
        {
            var response = new ResponseMessage();

            try
            {
                string id      = context.Request.Form["NewsId"];
                string title   = context.Request.Form["Title"];
                string nTypes  = context.Request.Form["NTypes"];
                string content = context.Request.Form["Content"];
                //    var pushTime = Convert.ToDateTime(context.Request.Form["PushTime"]);

                var states = Convert.ToInt32(context.Request.Form["States"]);

                var  path = context.Request.Form["PhotoUrl"];
                News News = new News()
                {
                    NewsId   = Guid.NewGuid().ToString(),
                    Title    = title,
                    NTypes   = nTypes,
                    Content  = content,
                    PhotoUrl = path,
                    States   = states,
                    PushTime = DateTime.Now
                };
                _log.Error($"咨询添加请求体:{SerializeHelp.ToJson(News)}");
                var add = _InfoService.Add(News);

                response.code = add == true ? 0 : 500;
                response.msg  = "添加成功";
                context.Response.Write(SerializeHelp.ToJson(response));
            }
            catch (Exception e)
            {
                string error = e.Message;
                _log.Error($"咨询添加失败:{error}");
                response.code = 500;
                response.msg  = "添加失败";
                context.Response.Write(SerializeHelp.ToJson(response));
            }
        }
        public void AddNewsToDbContext()
        {
            // Arrange
            var mockedCollection = new List <News>();
            var mockedDbSet      = MockDbSet.Mock(mockedCollection.AsQueryable());

            mockedDbSet.Setup(d => d.Add(It.IsAny <News>())).Callback <News>(n => mockedCollection.Add(n));

            var mockedDbContext = new Mock <IDatabaseContext>();

            mockedDbContext.Setup(c => c.News).Returns(mockedDbSet.Object);

            var newsService = new NewsService(mockedDbContext.Object);
            var news        = new News();

            // Act
            newsService.Add(news);

            // Assert
            Assert.IsTrue(mockedCollection.Count == 1);
            Assert.IsTrue(mockedCollection.Contains(news));
        }
예제 #12
0
        public HtmlString AddNewsPost(int projectId, string text)
        {
            NewsService.Add(new News()
            {
                Text      = text,
                ProjectId = projectId
            });
            return(new HtmlString(string.Format(@"
<div class=""news-list-item"">
<div class=""text"">
		<div class=""DateTime"">
			{0}
		</div>
		<div class=""news-name"">
			{1}
		</div>
		<div class=""news-description mt-3"">
			{2}			
		</div>
	</div>
</div>
", DateTime.Now.ToShortDateString(), text, text)));
        }
예제 #13
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var res = ns.Add(new Model.reception.News()
            {
                Title    = txtTitle.Text.Trim(),
                content  = txtContact.Text.Trim(),
                ParentId = Guid.Parse(txtParentId.Text.Trim()),
                Image    = upFileName(this.FileUpload1, "../../upload/News/"),
            });
            ReturnMsg fs = res > 0 ? new ReturnMsg
            {
                Code    = StatusCode.Ok,
                Message = "新增新闻成功",
                Data    = null
            } : new ReturnMsg
            {
                Code    = StatusCode.Error,
                Message = "新增新闻失败",
                Data    = null
            };

            Session["Msg"] = fs;
            Response.Redirect("News_Add.aspx");
        }
예제 #14
0
파일: NewsModule.cs 프로젝트: ma2000re/Api
        public NewsModule(NewsService newsService)
            : base("/news")
        {
            Get["/"] = p =>
            {
                var news = newsService.Get();
                return(new JsonResponse(news, new JsonNetSerializer()));
            };

            Get["/{id}"] = p =>
            {
                var news = newsService.Get(p.id);
                if (news == null)
                {
                    return(HttpStatusCode.NotFound);
                }
                return(new JsonResponse(news, new JsonNetSerializer()));
            };

            //Get["/byUserId/{id}"] = p =>
            //{
            //    var books = bookService.GetByUser(p.id);
            //    return new JsonResponse(books, new JsonNetSerializer());
            //};

            Post["/"] = p =>
            {
                News post = this.Bind();
                try
                {
                    var result = newsService.Add(post);
                }
                catch (Exception ex)
                {
                    log.errorLog(ex.Message);
                    return(HttpStatusCode.BadRequest);
                }
                return(HttpStatusCode.Created);
            };

            Put["/"] = p =>
            {
                News put = this.Bind();
                try
                {
                    var result = newsService.Update(put);
                }
                catch (Exception ex)
                {
                    log.errorLog(ex.Message);
                    return(HttpStatusCode.BadRequest);
                }
                return(HttpStatusCode.OK);
            };

            Delete["/{id}"] = p =>
            {
                try
                {
                    var result = newsService.Delete(p.id);
                    return(new JsonResponse(result, new DefaultJsonSerializer()));
                }
                catch (Exception ex)
                {
                    log.errorLog(ex.Message);
                    return(HttpStatusCode.BadRequest);
                }
            };
        }
예제 #15
0
 public ActionResult <News> AddNews([FromBody] News news)
 {
     news.DatePosted = DateTime.Now;
     _newsService.Add(news);
     return(Ok(news));
 }
예제 #16
0
        /// <summary>
        /// 发布资讯
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnRelease_Click(object sender, EventArgs e)
        {
            if (Session["loginUser"] == null)
            {
                Jscript.AlertAndRedirect("请登录", "/admin/login.aspx");
                return;
            }
            string spic = "";

            if (this.FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
            {
                if (!Directory.Exists(Server.MapPath(Global_Upload.NewsImgPath)))         //判断目录是否存在
                {
                    Directory.CreateDirectory(Server.MapPath(Global_Upload.NewsImgPath)); //创建目录
                }
                spic = DoClass.UploadFile(FileUpload1.PostedFile, Global_Upload.Imgsize, Global_Upload.ImgType, Global_Upload.NewsImgPath);

                if (spic == "-1")
                {
                    return;
                }
                else if (spic == "0")
                {
                    return;
                }
                else
                {
                    spic = Global_Upload.NewsImgPath + spic;
                    ViewState["newsImg1"] = spic;
                    lblURL.Text           = spic;
                }
            }
            //热点大图
            if (this.FileUpload2.PostedFile != null && FileUpload2.PostedFile.FileName != "")
            {
                if (!Directory.Exists(Server.MapPath(Global_Upload.NewsImgPath)))         //判断目录是否存在
                {
                    Directory.CreateDirectory(Server.MapPath(Global_Upload.NewsImgPath)); //创建目录
                }
                spic = DoClass.UploadFile(FileUpload2.PostedFile, Global_Upload.Imgsize, Global_Upload.ImgType, Global_Upload.NewsImgPath);

                if (spic == "-1")
                {
                    return;
                }
                else if (spic == "0")
                {
                    return;
                }
                else
                {
                    spic = Global_Upload.NewsImgPath + spic;
                    //ViewState["newsImg2"] = spic;
                    this.lblIndexImg.Text = spic;
                }
            }
            News item = new News();

            item.title    = this.txtTitle.Text.Trim();
            item.pageName = txtZhaiYao.Text.Trim();
            item.newsType = 0;
            item.newsType = Convert.ToInt32(ddlCate.SelectedValue);
            item.newImg   = lblURL.Text;


            item.newsContent = this.content1.Value;// Request.Form["content1"]; //this.txtContent.Value;
            item.keyword     = this.txtKeyWord.Text.Trim();
            item.newsDesc    = this.content2.Value.Trim();
            if (id != 0)
            {
                item.linkurl = "/news/" + Convert.ToDateTime(ViewState["addTime"]).ToString("yyyyMMddhhmmss") + ".html";
            }
            else
            {
                item.addTime = DateTime.Now;
                item.linkurl = "/news/" + item.addTime.ToString("yyyyMMddhhmmss") + ".html";
            }
            item.is_tj      = 0;
            item.is_hot     = 0;
            item.ordernum   = 0;
            item.add_userid = Convert.ToInt32((Session["loginUser"] as AdminUser).id);
            item.res_views  = 0;
            item.areaid     = 0;
            item.sid        = txtDesc.Text.Trim();

            item.releaseTime = DateTime.Now;
            item.author      = lblIndexImg.Text;
            if (item.pageName == "")
            {
                this.lblError.Text = "请填写摘要信息";
                return;
            }
            if (id != 0)
            {
                item.id = id;
                int num = NewsService.Update(item);
                if (num > 0)
                {
                    Jscript.AlertAndRedirectJstr("修改成功", "location.href='infoList.aspx?typeId=" + typeId + "';");
                }
                else
                {
                    this.lblError.Text = "修改失败";
                }
            }
            else
            {
                int num = NewsService.Add(item);
                if (num > 0)
                {
                    Jscript.AlertAndRedirectJstr("添加成功", "location.href='infoList.aspx?typeId=" + typeId + "';");
                }
                else
                {
                    this.lblError.Text = "添加失败";
                }
            }
        }