Beispiel #1
0
        public async Task ShoudNotCreateOrderWhenThereIsOverLappingDates()
        {
            var gasStation = _orderDateFixture.GasStations.First();

            var orderInputDTO = new OrderInputDTO
            {
                CarrierId = _orderDateFixture.Carriers.First().Id,
                Comments  = "Manual Order",
                OrderType = _orderDateFixture.OrderStrategies
                            .First(x => x.GasStationId == gasStation.Id)
                            .OrderType,
                FromDateTime = new DateTime(2020, 9, 9, 4, 0, 0),
                ToDateTime   = new DateTime(2020, 9, 9, 8, 0, 0),
                GasStationId = gasStation.Id,
                LineItems    = gasStation.Tanks.Select(
                    x => new OrderInputDTO.OrderProductInputDTO
                {
                    TankId   = x.Id,
                    Quantity = 500,
                    Unit     = TankMeasurement.Gallons
                })
            };

            var result = await _orderApp.AddAsync(orderInputDTO);

            Assert.False(result.IsSuccess);
            Assert.True(result.OrderId == default(int));
            Assert.Single(result.Message);
            Assert.True(result.Message.First() == OrderConstant.duplicateOrderMessage);
            _mockHelper.MockManagerOrderRepository.Verify(repo =>
                                                          repo.GetOrderByGasStationIdDeliveryDateAsync(It.IsAny <Guid>(), It.IsAny <DateTimeRange>()),
                                                          Times.Never);
            _mockHelper.MockManagerOrderRepository.Verify(repo =>
                                                          repo.UpsertAsync(It.IsAny <ManageOrder>()), Times.Never);
        }
        public void MakeOrder(OrderInputDTO order)
        {
            var customer   = this.userService.GetUserById(order.CustomerId);
            var seller     = this.userService.GetUserById(order.SellerId);
            var withdrawal = this.sellerService.GetWithdrawalById(order.WithdrawalId);

            this.customerService.MakeOrder(new Order
            {
                Customer   = customer,
                Seller     = seller,
                Withdrawal = withdrawal,
                Status     = 0
            });
        }
Beispiel #3
0
        public ActionResult <OrderOutputDTO> PurchaseItem(OrderInputDTO itemPurchased)
        {
            ClaimsIdentity ci       = HttpContext.User.Identities.FirstOrDefault();
            Claim          c        = ci.FindFirst("UserName");
            string         username = c.Value;
            Order          o        = new Order {
                UserName = username, ProductID = itemPurchased.ProductID, Quantity = itemPurchased.Quantity
            };
            Order          newOrder = _repository.newOrder(o); //ProductID is always valid in A2
            OrderOutputDTO orderOut = new OrderOutputDTO {
                Id        = newOrder.Id,
                UserName  = newOrder.UserName,
                ProductID = newOrder.ProductID,
                Quantity  = newOrder.Quantity
            };

            return(Ok(orderOut));
        }
Beispiel #4
0
        public async Task <OrderViewModel> AddAsync(OrderInputDTO orderInput)
        {
            var inputOrder = new InputOrder
            {
                Comments     = orderInput.Comments,
                CarrierId    = orderInput.CarrierId,
                FromTime     = orderInput.FromDateTime,
                ToTime       = orderInput.ToDateTime,
                GasStationId = orderInput.GasStationId,
                OrderType    = orderInput.OrderType,
                LineItems    = orderInput.LineItems.Select(
                    x => new InputOrderProduct
                {
                    Quantity = x.Quantity,
                    TankId   = x.TankId
                })
            };

            try
            {
                var gasStation = await _gasStationRepository
                                 .FindByKeyAsync(orderInput.GasStationId)
                                 .ConfigureAwait(false);

                if (gasStation != null)
                {
                    var result = Order.Create(inputOrder, gasStation);

                    if (result.IsSuccess)
                    {
                        var order = await _orderGenerator.SaveAsync(result.Entity !);

                        if (!order.IsConflicting)
                        {
                            order = await _manageOrderRepository
                                    .GetOrderByGasStationIdDeliveryDateAsync(order.GasStationId,
                                                                             order.DispatchDate);

                            return(new OrderViewModel
                            {
                                IsSuccess = true,
                                Message = new[] { OrderConstant.successMessage },
                                OrderId = order.Id
                            });
                        }
                        else
                        {
                            return(new OrderViewModel
                            {
                                IsSuccess = false,
                                Message = new[] { OrderConstant.duplicateOrderMessage }
                            });
                        }
                        //catch (Exception e) when (e.InnerException.GetType() == typeof(SqlException))
                    }
                    else
                    {
                        return(new OrderViewModel
                        {
                            IsSuccess = false,
                            Message = result.ErrorMessages !
                        });
                    }
Beispiel #5
0
 public void MakeOrder(OrderInputDTO order)
 {
     this.customerAppService.MakeOrder(order);
 }