コード例 #1
0
        public ICommandResult Handle(UpdateNodeCommand command)
        {
            //Fail Fast Validation
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, Messages.Ex_ExceptionGeneric, command.Notifications));
            }

            var node = _repository.GetById(command.Id);

            node.UpdateNode(command.Title);

            _repository.Update(node);

            return(new GenericCommandResult(true, Messages.Act_Update, node));
        }
コード例 #2
0
ファイル: Value.cs プロジェクト: MaciejMatyaszek/Tree.API
        public async Task <IActionResult> Edit([FromBody] UpdateNodeCommand node)
        {
            if (ModelState.IsValid)
            {
                var nodeToUpdate = await _context.Node.FindAsync(node.Id);

                if (nodeToUpdate != null)
                {
                    nodeToUpdate.Name     = node.Name;
                    nodeToUpdate.ParentId = node.ParentId;
                    await _context.SaveChangesAsync();

                    return(NoContent());
                }
            }

            return(BadRequest());
        }
コード例 #3
0
 public GenericCommandResult Update([FromBody] UpdateNodeCommand command, [FromServices] NodeHandler handler)
 {
     return((GenericCommandResult)handler.Handle(command));
 }