public ActionResult CommunityDelete([DataSourceRequest] DataSourceRequest request, CommunityItem communityItem) { if (communityItem != null) { service.DeleteCommunity(communityItem); } return(Json(new[] { communityItem }.ToDataSourceResult(request, ModelState))); }
public void Should_not_delete_community_when_community_id_does_not_exists() { var fakeRepo = Substitute.For <ICommunityRepository>(); fakeRepo.GetCommunity(Arg.Is(2)).ReturnsNull(); var communityService = new CommunityService(fakeRepo); communityService.DeleteCommunity(2).ConfigureAwait(false); fakeRepo.DidNotReceive().DeleteCommunity(Arg.Is(2)); }
public void Should_delete_community_when_community_id_exists() { var community = _fixture.Build <CommunityModel>() .With(x => x.Id, 2) .Create(); var fakeRepo = Substitute.For <ICommunityRepository>(); fakeRepo.GetCommunity(Arg.Is(2)).Returns(community); var communityService = new CommunityService(fakeRepo); communityService.DeleteCommunity(2).ConfigureAwait(false); fakeRepo.Received(1).DeleteCommunity(Arg.Is(2)); }
public void Create_Community_Success() { var res = communityService.CreateCommunity(new CreateCommunity() { Local = "Lisboa", UserId = "1", Name = "silicon valey", Tags = new int[] { 3, 7 }, Sponsors = new int[] { 1 } }).Result; var res2 = communityService.GetByIdAsync(res.Result).Result; Assert.AreEqual(res2.Result.name, "silicon valey"); Assert.AreEqual(2, res2.Result.tag.Count()); var id = communityService.DeleteCommunity(new CreateCommunity() { UserId = "1", Id = res2.Result.id }).Result; }
public async Task <ActionResult> DeleteCommunity(DeleteCommunity community) { CommunityService service = CommunityService.GetInstance(); var res = await service.GetByIdAsync(community.Id); if (res.Success) { if (res.Result.name == community.Name) { var deleted = await service.DeleteCommunity(new CreateCommunity { Id = community.Id, UserId = User.Identity.GetUserId() }); if (deleted.Success) { return(RedirectToAction("Index", "Home")); } } else { return(PartialView("_DeleteCommunity", community)); } } return(View()); }