示例#1
0
        public void IsValid_Id_Return_True()
        {
            //arrange
            _command.Id          = Guid.NewGuid();
            _command.Name        = "Name";
            _command.Description = "Description";

            //act
            var result = _command.IsValid();

            //assert
            Assert.True(result);
        }
示例#2
0
 public Task <object> Handle(UpdateInvoiceCommand command, CancellationToken cancellationToken)
 {
     if (!command.IsValid())
     {
         NotifyValidationErrors(command);
     }
     else
     {
         List <InvoiceItem> items = new List <InvoiceItem>();
         foreach (InvoiceItemModel invoiceItem in command.Items)
         {
             InvoiceItem item = new InvoiceItem
                                (
                 new Identity((uint)invoiceItem.ID),
                 new Entities.Product(new Identity((uint)invoiceItem.ProductID), null, null, null, null, null, null, null),
                 new Entities.Unit(new Identity((uint)invoiceItem.UnitID), null),
                 new Price(invoiceItem.Price),
                 new Note(invoiceItem.Note),
                 new Quantity(invoiceItem.Quantity),
                 new Weight(invoiceItem.Weight),
                 new Price(invoiceItem.TotalPrice),
                 new Deliveried(false),
                 new Quantity(0)
                                );
             items.Add(item);
         }
         Entities.Invoice Invoice = new Entities.Invoice
                                    (
             new Identity((uint)command.ID),
             new Entities.Customer((uint)command.CustomerID, null, null, null, null, null, null, null, null),
             new DeliveryTime(command.DeliveryTime),
             new Price(command.TotalPrice),
             new Note(command.Note),
             new Weight(command.WeightTotal),
             new Code(command.Code),
             items
                                    );
         bool result = _InvoiceRepository.Update(Invoice);
         return(Task.FromResult(result as object));
     }
     return(Task.FromResult(null as object));
 }
        public async Task <bool> Handle(UpdateInvoiceCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                await _mediatorHandler.RaiseEvent(new DomainValidationEvent(request.ValidationResult.ToString()));

                return(false);
            }

            var oldInvoice = _invoiceRepository.GetById(request.Id);

            if (oldInvoice == null)
            {
                await _mediatorHandler.RaiseEvent(new NotFoundEvent(request.Id, "Invoice", "Invoice not found"));

                return(false);
            }

            var getByName = _invoiceRepository.GetByName(request.Name);

            if (getByName != null && getByName.Id != request.Id)
            {
                await _mediatorHandler.RaiseEvent(new DuplicatedRecordEvent("Name", "Invoice", "{0} is already present. Please select another Invoice Name"));

                return(false);
            }

            var model = _mapper.Map <Invoice>(request);

            _invoiceRepository.Update(model);

            await _mediatorHandler.RaiseEvent(new InvoiceUpdatedEvent()
            {
                Old = oldInvoice,
                New = model
            });

            return(true);
        }