Ejemplo n.º 1
0
        public Task <bool> Handle(UpdateSellerCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                Task.FromResult(false);
            }
            var seller         = new Seller(request.SellerId, request.Name, request.Email, request.PhoneNumber);
            var existingSeller = _sellerRepository.GetById(seller.SellerId);

            if (existingSeller != null && existingSeller.SellerId == seller.SellerId)
            {
                if (!existingSeller.Equals(seller))
                {
                    _bus.RaiseEvent(new DomainNotification(request.MessageType, "The seller has already been created."));
                    return(Task.FromResult(false));
                }
            }
            _sellerRepository.Update(seller);
            if (Commit())
            {
                _bus.RaiseEvent(new SellerUpdatedEvent(seller.SellerId, seller.Name, seller.Email, seller.PhoneNumber));
            }
            return(Task.FromResult(true));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Put(int id, [FromBody] UpdateSellerCommand command)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var response = await this._mediator.Send(command);

            return(this.Ok());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Update(long id, UpdateSellerCommand command)
        {
            if (id != command.sellerDto.SellerID)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
Ejemplo n.º 4
0
        public void DeleteSeller(UpdateSellerCommand updatedSellerCommand, int id)
        {
            var repo = new SellerRepository();

            var deletedSeller = new Seller
            {
                Name = updatedSellerCommand.Name
            };

            repo.DeleteSeller(deletedSeller, id);
        }