Exemplo n.º 1
0
        //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();
        }
Exemplo n.º 2
0
        public IHttpActionResult DeleteTopic(int id)
        {
            var command = new DeleteTopicCommand {
                intIdTopic = id
            };

            _mediator.Send(command);
            return(Ok(command));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        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)
                {
                }
            }
        }