Exemplo n.º 1
0
        public async Task WhenDtoIsValid_ShouldUpdatePartner()
        {
            var partner = (await TestFramework.DataFactory.AddPartners(1)).First();
            var command = new UpdatePartnerCommand()
            {
                Id      = partner.Id,
                Name    = "New PartnerName",
                Address = new AddressDto()
                {
                    City    = "Berlin",
                    Country = "Germany",
                    Street  = "Varnhagenstraße 18-44",
                    ZipCode = "10439"
                }
            };

            await TestFramework.SendAsync(command);

            var updatedPartner = await TestFramework.Data.FindAsync <Partner>(command.Id);

            updatedPartner.Should().NotBeNull();
            updatedPartner.Id.Should().Be(command.Id);
            updatedPartner.Name.Should().Be(command.Name);
            updatedPartner.Address.Should().NotBeNull()
            .And.Subject.Should().BeEquivalentTo(command.Address, o => o.ComparingByMembers <AddressDto>());
        }
Exemplo n.º 2
0
        public async Task ExecuteAsync(UpdatePartnerCommand command)
        {
            if (!command.Validate())
            {
                AddNotification(command.GetNotifications());
                return;
            }

            AddNotification(!partnerRepository.Get().Any(x => x.Id == command.Partner.Id), "Partner Id Not Found");

            if (!IsValid)
            {
                return;
            }


            try
            {
                await partnerRepository.UpdateAsync(command.Partner);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message, ex);
                AddNotification(ex.Message, System.Net.HttpStatusCode.InternalServerError);
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Put([FromBody] Partner partner)
        {
            UpdatePartnerCommand command = new UpdatePartnerCommand(partner);

            await partnerCommandHandler.ExecuteAsync(command);

            return(this.HandleNotification(partnerCommandHandler, partner));
        }
Exemplo n.º 4
0
 public void Handle(ICommandContext context, UpdatePartnerCommand command)
 {
     context.Get <Partner>(command.AggregateRootId).Update(new PartnerInfo(
                                                               command.Mobile,
                                                               command.Region,
                                                               command.Level,
                                                               command.Persent,
                                                               command.CashPersent,
                                                               command.BalanceInterval,
                                                               command.Remark,
                                                               command.IsLocked
                                                               ));
 }
Exemplo n.º 5
0
        public async Task Update_WithIdMismatch_ShouldReturnBadRequest()
        {
            var command = new UpdatePartnerCommand()
            {
                Id = 123
            };

            _mockMediator.Setup(x => x.Send(command, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(Unit.Value));

            var result = await _sut.Update(456, command);

            Assert.IsAssignableFrom(typeof(BadRequestResult), result);
        }
Exemplo n.º 6
0
        public async Task Update()
        {
            var command = new UpdatePartnerCommand()
            {
                Id = 123
            };

            _mockMediator.Setup(x => x.Send(command, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(Unit.Value));

            var result = await _sut.Update(command.Id, command);

            _mockMediator.Verify(x => x.Send(command, It.IsAny <CancellationToken>()),
                                 Times.Once);
        }
Exemplo n.º 7
0
        public async Task <BaseApiResponse> Edit(EditPartnerRequest request)
        {
            request.CheckNotNull(nameof(request));
            //判断
            var partner = _partnerQueryService.Find(request.Id);

            if (partner == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该代理"
                });
            }

            var command = new UpdatePartnerCommand(
                request.Mobile,
                request.Region,
                request.Level,
                request.Persent,
                request.CashPersent,
                request.BalanceInterval,
                request.Remark,
                request.IsLocked
                )
            {
                AggregateRootId = request.Id
            };
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            //添加操作记录
            var currentAdmin = _contextService.GetCurrentAdmin(HttpContext.Current);

            RecordOperat(currentAdmin.AdminId.ToGuid(), "编辑代理", request.Id, request.Region);

            return(new BaseApiResponse());
        }
Exemplo n.º 8
0
        public async Task <BaseApiResponse> Edit([FromBody] EditPartnerRequest request)
        {
            request.CheckNotNull(nameof(request));
            //判断
            var partner = _partnerQueryService.Find(request.Id);

            if (partner == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该代理"
                });
            }

            var command = new UpdatePartnerCommand(
                request.Mobile,
                request.Region,
                request.Level,
                request.Persent,
                request.CashPersent,
                request.BalanceInterval,
                request.Remark,
                request.IsLocked
                )
            {
                AggregateRootId = request.Id
            };
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Exemplo n.º 9
0
        public async Task <ActionResult> UpdatePartner([FromBody] UpdatePartnerCommand command)
        {
            await _Mediator.Send(command);

            return(NoContent());
        }