Exemple #1
0
        public async Task <IActionResult> DeleteNews(int id)
        {
            try
            {
                var token = Request.Headers["Authorization"].ToString();

                var deletedEntry = await NewsService.GetByIdAsync <News>(id);

                if (deletedEntry == null)
                {
                    return(NotFound());
                }

                if (JwtHelper.CheckIfUserIsModerator(token) && deletedEntry.PublishedById != JwtHelper.GetUserIdFromJwt(token))
                {
                    return(Forbid());
                }

                await NewsService.Delete <News>(id);

                return(Ok(new Response
                {
                    Status = ResponseType.Successful
                }));
            }
            catch
            {
                return(Ok(new Response {
                    Status = ResponseType.Failed
                }));
            }
        }
Exemple #2
0
        public ActionResult NewsDelete(int id, string fake)
        {
            var service = new NewsService();

            service.Delete(id);
            return(RedirectToAction("GetAllNews"));
        }
Exemple #3
0
        /// <summary>
        ///删除
        /// </summary>
        /// <param name="context"></param>
        public void DeleteNewsRequest(HttpContext context)
        {
            var response = new ResponseMessage();

            try
            {
                var id  = context.Request["id"];
                var del = _InfoService.Delete(id);
                if (del)
                {
                    response.code = 0;
                    response.msg  = "删除成功";
                    context.Response.Write(SerializeHelp.ToJson(response));
                }
                response.code = 500;
                response.msg  = "删除失败";
                context.Response.Write(SerializeHelp.ToJson(response));
            }
            catch (Exception e)
            {
                response.code = 500;
                response.msg  = "删除失败";
                context.Response.Write(SerializeHelp.ToJson(response));
            }
        }
Exemple #4
0
        public ActionResult OnDelete(int id)
        {
            var result = NewsService.Delete(id);

            SetFlashMessage(result == Result.Ok ?
                            "Xóa tin tức thành công." :
                            "Tin tức không tồn tại trên hệ thống.");
            return(RedirectToAction("Index"));
        }
Exemple #5
0
        public ActionResult DeleteNews(Guid newsid, int p)
        {
            News news = newsService.GetByID(newsid);

            newsService.Delete(news);
            newsService.SaveChanges();

            return(RedirectToAction("News", new { p = p }));
        }
Exemple #6
0
        public ActionResult Delete(int id)
        {
            var model = _newsService.Get(id);

            if (model != null)
            {
                _newsService.Delete(model);
            }
            return(RedirectToAction("Index"));
        }
        //删除事件
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            Button bt = (Button)sender;
            int    id = Convert.ToInt32(((HiddenField)(bt.Parent.FindControl("HiddenField1"))).Value);

            if (NewsService.Delete(id) > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javascript' >alert('删除成功!');</script>");
                BindAct();
            }
        }
Exemple #8
0
        /// <summary>
        /// Delete信息
        /// </summary>
        private void DeleteInfo()
        {
            int id  = CRequest.GetInt("id", 0);
            int num = NewsService.Delete(id);

            if (num > 0)
            {
                Response.Redirect("/admin/infoList.aspx");
                //Jscript.AlertAndRedirect("Delete成功","");
            }
        }
Exemple #9
0
        public void Delete_ShouldReturnTrueforVaildId()
        {
            // Arrange
            this.mockNewsRepository.Setup(x => x.Delete(It.IsAny <int>())).Returns(true);
            var service = new NewsService(mockNewsRepository.Object);

            // Act
            var actual = service.Delete(1);

            //Assert
            Assert.True(actual);
        }
        public virtual IHttpActionResult Delete([FromUri] NewsDeleteRequest request)
        {
            var result = _newsService.Delete(a => a.Id == request.Id);

            if (result > 0)
            {
                return(Succeed(result, "删除成功"));
            }
            else
            {
                return(Fail("删除失败"));
            }
        }
Exemple #11
0
        public void DeleteNews(int Id, string Title, DateTime date, int AuthorId, int CategoryId)
        {
            News news = new News()
            {
                Id           = Id,
                Title        = Title,
                Date_of_News = date,
                AuthorId     = AuthorId,
                CategoryId   = CategoryId
            };

            newsService.Delete(news);
        }
        public async Task NewsServiceDeleteShould_DeleteEntry()
        {
            // Arrange

            var context = this.GetDbContext();

            this.PopulateData(context);

            var newsService = new NewsService(context, mapper);

            // Act

            await newsService.Delete(NewsIdForDeleting);

            // Assert
            Assert.True(!context.News.Any(m => m.Id == NewsIdForDeleting));
        }
Exemple #13
0
        public void NewsServiceDeleteShouldReturnDeletedNewsId()
        {
            // Arrange
            var db = this.Context;

            this.PopulateData(db);

            var newsService = new NewsService(db);

            // Act
            var result = newsService.Delete(1);

            // Assert
            result
            .Should()
            .Be(1);
        }
        public async Task <IActionResult> DeleteBitOfNews(string id)
        {
            if (id == null || id == "")
            {
                return(BadRequest(new { message = "id is empty or null" }));
            }

            BitOfNews bitOfNews = await newsService.GetBitOfNews(id);

            if (bitOfNews == null)
            {
                return(NotFound());
            }

            newsService.Delete(bitOfNews);

            return(Ok(bitOfNews));
        }
        protected void btnSilTable_Click(object sender, EventArgs e)
        {
            try
            {
                Button btn = (Button)sender;
                int    ID  = Int32.Parse(btn.CommandArgument);
                lblInfo2.Text = ID.ToString();

                News oldNews = _news.Get(ID);
                _news.Delete(oldNews);

                clear();
                panelVisible(true, true, false, false);
                Uyari("Silme işlemi başarıyla gerçekleşti", true);
            }
            catch (Exception)
            {
                Uyari("Silme işlemi sırasında bir hata oluştu", false);
            }
        }
Exemple #16
0
 public ActionResult DeleteNews(string newsId)
 {
     try
     {
         var pathDefaultPhoto = ConfigurationManager.AppSettings["pathDefaultPhoto"];
         var news             = NewsService.GetbyId(Convert.ToInt32(newsId));
         if (NewsService.Delete(Convert.ToInt32(newsId)))
         {
             if (news.HeadImage != pathDefaultPhoto)
             {
                 DeletePhotoFromServer(news.HeadImage);
             }
             return(RedirectToAction("Index", "News"));
         }
         return(View());
     }
     catch (Exception ex)
     {
         return(Content(ex.Message));
     }
 }
Exemple #17
0
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDel_Click(object sender, EventArgs e)
        {
            string ids = selInfo();
            int    num = 0;

            if (ids.Length == 0)
            {
                Jscript.Alert("请选择要删除的记录!", this.Page);
                return;
            }
            string[] arr = ids.TrimEnd(',').Split(',');
            for (int i = 0; i < arr.Length; i++)
            {
                if (NewsService.Delete(Convert.ToInt32(arr[i])) > 0)
                {
                    num++;
                }
            }

            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('成功删除" + num + "条记录!');", true);
            sp.InitBindData(Repeater1, pager1, "news", "id", sear());
        }
Exemple #18
0
        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);
                }
            };
        }
Exemple #19
0
 public ActionResult DeleteNews([FromBody] News news)
 {
     _newsService.Delete(news.Id);
     return(Ok());
 }