//private void _ValidateName(string prop, string value) //{ // ClearErrors(prop); // if (string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value)) // { // SetError(prop, "Name cannot be empty."); // } // AddNewTopicCommand.RaiseCanExecuteChanged(); //} //private void _ValidateUnique(string prop, string value) //{ // //if (string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value)) return; // //ClearErrors(prop); // //if (MeasureService.EntityTopics.Any(x => x.Name == value)) // //{ // // SetError(prop, "Topic title must be unique."); // //} // //AddNewTopicCommand.RaiseCanExecuteChanged(); //} //protected override void ValidateAll() //{ // _ValidateName(ExtractPropertyName(() => NewTopicName), NewTopicName); // _ValidateUnique(ExtractPropertyName(() => NewTopicName), NewTopicName); //} #endregion #region Methods public override void OnImportsSatisfied() { InitData(); EventAggregator.GetEvent <TopicsUpdatedEvent>().Subscribe(RefreshTopicsCollection); new TopicsFilter(this); base.OnImportsSatisfied(); DeleteTopicCommand.RaiseCanExecuteChanged(); }
public IHttpActionResult DeleteTopic(int id) { var command = new DeleteTopicCommand { intIdTopic = id }; _mediator.Send(command); return(Ok(command)); }
public void Handler_GivenInvalidTopicId_ThrowsException() { // Arrange var invalidTopicId = 99; // Act var command = new DeleteTopicCommand { Id = invalidTopicId }; var handler = new DeleteTopicCommand.DeleteTopicCommandHandler(Context); // Assert Should.ThrowAsync <NotFoundException>(() => handler.Handle(command, CancellationToken.None)); }
public async Task Handler_GivenValidTopicId_ShouldRemovePost() { // Arrange var validTopicId = 1; // Act var command = new DeleteTopicCommand { Id = validTopicId }; var handler = new DeleteTopicCommand.DeleteTopicCommandHandler(Context); await handler.Handle(command, CancellationToken.None); // Assert var entity = Context.Topics.Find(command.Id); entity.ShouldBeNull(); }
public async Task <IActionResult> DeleteTopic(long id) { var dfc = new DeleteTopicCommand { Id = id }; var result = await _cp.ProcessAsync(dfc); if (result.Succeeded) { _logger.LogInformation("Deleted topic with id {0}", id); return(RedirectToAction("ManageTopics")); } _logger.LogWarning("Unable to delete topic with id {0}", id); // todo: better error handling return(NotFound()); }
protected void top_ItemCommand(object source, RepeaterCommandEventArgs e) { ImageButton action = (ImageButton)e.CommandSource; string actionString = action.ID; if (action.ID.Equals("delete")) { try { Topic topic = new Topic(); string id = ((Label)top_data.Items[e.Item.ItemIndex].FindControl("Id")).Text; topic.Id = Int32.Parse(id); DeleteTopicCommand cmd = new DeleteTopicCommand(topic); cmd.Execute(); if (topic.Code == 200) { ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme()", true); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertmeErr()", true); } } catch (Exception ex) { } } else if (action.ID.Equals("modify")) { try { string id = ((Label)top_data.Items[e.Item.ItemIndex].FindControl("Id")).Text; Session["Id_top"] = id; Response.Redirect("/site/admin/adm_topic/edit_top.aspx"); } catch (Exception ex) { } } }