public void UpdateAccountantCommandFail()
        {
            var cmd = new UpdateAccountantCommand(_id, string.Empty);

            _handler.Handle(cmd);
            Assert.IsFalse(_handler.Valid, _handler.Notifications.FirstOrDefault().Message);
        }
        public void UpdateAccountantCommandOk()
        {
            var cmd = new UpdateAccountantCommand(_id, "Carlos Alberto de Brito Júnior");

            _handler.Handle(cmd);
            Assert.IsTrue(_handler.Valid);
        }
 /// <summary>
 /// Create new <see cref="Data.Models.Accountant"/> based on <see cref="UpdateAccountantCommand"/>
 /// </summary>
 /// <param name="command">Accountant details</param>
 /// <returns>Data model</returns>
 internal Data.Models.Accountant Create(UpdateAccountantCommand command)
 {
     return(new Data.Models.Accountant
     {
         Id = command.Id,
         FirstName = command.FirstName,
         LastName = command.LastName,
         LastModificationDate = DateTime.UtcNow
     });
 }
        /// <summary>
        /// Handle <see cref="UpdateAccountantCommand"/>
        /// </summary>
        /// <param name="command">Command object</param>
        public async Task HandleImmediateAsync(UpdateAccountantCommand command)
        {
            Data.Models.Accountant model = accountantFactory.Create(command);
            DataContext.Accountants.Attach(model);

            if (!string.IsNullOrEmpty(command.FirstName))
            {
                DataContext.SetPropertyModified(model, nameof(model.FirstName));
            }

            if (!string.IsNullOrEmpty(command.LastName))
            {
                DataContext.SetPropertyModified(model, nameof(model.LastName));
            }

            DataContext.SetPropertyModified(model, nameof(model.LastModificationDate));

            await this.Finalize();
        }
        public Task<bool> Handle(UpdateAccountantCommand command)
        {
            var entity = _repository.Get(command.Id);
            if (entity == null)
            {
                AddNotification("correntista", "Correntista não localizado");
                return Task.FromResult(true);
            }

            entity.Update(new Name(command.Name));
            AddNotifications(entity);

            if (Invalid) return Task.FromResult(false);

            _repository.Update(entity);
            _uow.Commit();

            return Task.FromResult(true);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Update(Guid id, UpdateAccountantViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data model."));
            }

            UpdateAccountantCommand command = new UpdateAccountantCommand(id)
            {
                FirstName = model.FirstName,
                LastName  = model.LastName
            };

            try
            {
                await this.commandBus.SendAsync(command);
            }
            catch
            {
                return(BadRequest("Failed to update accountant."));
            }

            return(Ok());
        }