public async Task <IActionResult> OnPostDeleteAsync(int id) { //CRUD will be modified to take a user view model as a parameter and work only for the appropriate users. await _articleController.Delete(id, User); return(RedirectToPage("./Index")); }
public async Task Delete_ById_When_Called_Should_Return_OkResult() { int id = 1; var result = await articleController.Delete(id) as OkResult; result.Should().BeOfType <OkResult>().Which.StatusCode.Should().Be(200); }
public async void Delete_ShouldReturn_Ok() { mockArticleRepos.Setup(x => x.Delete(It.IsAny <Article>())); mockArticleRepos.Setup(x => x.SaveChanges()); var target = await controller.Delete(It.IsAny <int>()); Assert.IsType <OkResult>(target); }
public void Remove_ExistingPassed_ReturnsOkResult() { // Arrange var existingGuid = "1234"; // Act var okResponse = _controller.Delete(existingGuid); // Assert Assert.IsType <OkObjectResult>(okResponse); }
protected void btnMultipleDelete_Click(object sender, EventArgs e) { //Get Ids string[] IDs = hdnFldSelectedValues.Value.Trim().Split('|'); string front_image_dir = Server.MapPath(front_image_dir_path); string main_image_dir = Server.MapPath(main_image_dir_path); //Code for deleting items foreach (string Item in IDs) { try { string userid = Session["UserId"].ToString(); int id = int.Parse(Item.ToString()); int i = articles_obj.Delete(userid, id, front_image_dir, main_image_dir); FillDataInGrid(); } catch (InvalidOperationException ef) { ef.ToString(); } } }
protected void lbtnDeleteSelected_Click(object sender, EventArgs e) { foreach (GridViewRow item in gvList.Rows) { CheckBox chkItem = (CheckBox)item.FindControl("chkItem"); if (chkItem.Checked == true) { Label lblId = (Label)item.FindControl("lblId"); ArticleController.Delete(Convert.ToInt32(lblId.Text)); } } BindArticleList(); }
protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e) { ArticleId = Convert.ToInt32(e.CommandArgument); ArticleInfo objArticle = ArticleController.Get(ArticleId); switch (e.CommandName) { case "Select": BindArticle(ArticleId); SetButtonStatus("Select"); break; case "Copy": ArticleInfo objNewArticle = objArticle; objNewArticle.UserId = UserId; ArticleId = ArticleController.Add(objNewArticle); BindArticleList(); BindArticle(ArticleId); SetButtonStatus("Select"); break; case "Del": ArticleController.Delete(ArticleId); ArticleId = -1; BindArticleList(); break; case "Auth": ArticleController.UpdateAuthed(ArticleId, !objArticle.Authed); BindArticleList(); break; case "Active": ArticleController.UpdateActive(ArticleId, !objArticle.Active); BindArticleList(); break; case "Featured": ArticleController.UpdateFeatured(ArticleId, !objArticle.Featured); BindArticleList(); break; case "Draft": ArticleController.UpdateDraft(ArticleId, !objArticle.Draft); BindArticleList(); break; default: break; } }
protected void lbtnDelete_Click(object sender, EventArgs e) { if (ArticleId == -1) { return; } else { ArticleController.Delete(ArticleId); ArticleId = -1; BindArticleList(); SetButtonStatus("Delete"); } }
public void Delete() { //Arrange using (var ctx = new JournalDbContext(DbOptions)) { var controller = new ArticleController(new ArticleService(ctx), MapperConfig.Configure()); //Act var result = controller.Get(); var okObjectResult = result as OkObjectResult; var model = okObjectResult.Value as IEnumerable <ArticleModel>; controller.Delete(model.First().Id); } //Assert using (var ctx = new JournalDbContext(DbOptions)) { Assert.Equal(1, ctx.Articles.Count()); } }