Exemplo n.º 1
0
        public static Result <Order> Create(SaleMethod saleMethod, Customer customer, Address address)
        {
            if (saleMethod == null)
            {
                throw new ArgumentNullException(nameof(saleMethod));
            }
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            var order = new Order
            {
                Status          = OrderStatus.Pending,
                DateTime        = SystemTime.Now(),
                Customer        = customer,
                ShippingAddress = address,
                SaleMethod      = saleMethod
            };

            return(Result.Ok(order));
        }
Exemplo n.º 2
0
        public override async Task <Result> Handle(NewSaleMethod command, CancellationToken cancellationToken)
        {
            var title = Title.New(command.Title);

            if (title.Failed)
            {
                return(Fail(title.Message, title.Failures));
            }

            var saleMethod = SaleMethod.Create(title.Value, SaleNature.FastFood);

            if (saleMethod.Failed)
            {
                return(Fail(saleMethod.Message, saleMethod.Failures));
            }

            await _repository.InsertAsync(saleMethod.Value);

            return(Ok());
        }