public IActionResult GetOrderLinesForOrder(long orderId) { try { var order = _unitOfWork.Orders.GetOrderWithOrderLines(orderId); if (order == null) { return(NotFound("Order Not Exist.")); } var dtos = new List <OrderLineDto>(); foreach (var orderLine in order.OrderLines) { OrderLineDto dto = new OrderLineDto(); dto.Id = orderLine.Id; dto.Note = orderLine.Note; dto.Quantity = orderLine.Quantity; dto.Tax = orderLine.Tax; dto.ItemId = orderLine.Item.Id; dto.ExclAmount = orderLine.ExclAmount; dto.TaxAmount = orderLine.TaxAmount; dto.InclAmount = orderLine.InclAmount; dtos.Add(dto); } return(Ok(dtos)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public void BasketsController_Update_Basket_Order_Line_Return_Correct_Updated_Order_Line() { var baskets = new InMemoryDataStore <Basket>(); var products = new InMemoryDataStore <Product>(); products.Seed(); baskets.Seed(products); var bc = new BasketsController(products, baskets, _mapper); var actionResult = bc.PatchOrderLine(_testBasketId, _testProductId, new JsonPatchDocument <OrderLineUpdateDto>().Add(p => p.Quantity, 12)); OkObjectResult okresult = actionResult as OkObjectResult; Assert.IsNotNull(okresult); OrderLineDto resultOrderLine = okresult.Value as OrderLineDto; Assert.IsNotNull(resultOrderLine); Assert.IsTrue(resultOrderLine.Quantity == 12); OrderLine orderline = null; baskets.Get(_testBasketId)?.OrderLines.TryGetValue(resultOrderLine.ProductId, out orderline); Assert.IsNotNull(orderline); Assert.IsTrue(orderline.Quantity == 12); }
public void BasketsController_Create_Basket_Order_Line_Return_Correct_Order_Line() { var baskets = new InMemoryDataStore <Basket>(); var products = new InMemoryDataStore <Product>(); products.Seed(); baskets.Seed(products); var orderLine = new OrderLineCreateDto() { ProductId = new Guid("3aee1758-77b9-4e86-9c57-77adbbc0956f"), //Watermelon Quantity = 5 }; var bc = new BasketsController(products, baskets, _mapper); var actionResult = bc.PostAddOrderLineToBasket(_testBasketId, orderLine); CreatedAtRouteResult createdresult = actionResult as CreatedAtRouteResult; Assert.IsNotNull(createdresult); OrderLineDto resultOrderLine = createdresult.Value as OrderLineDto; Assert.IsNotNull(resultOrderLine); Assert.AreEqual(resultOrderLine.ProductId, orderLine.ProductId); }
protected virtual async Task <bool> IsPeriodInfoValidAsync(OrderLineDto orderLine) { var periodSchemeId = orderLine.GetBookingPeriodSchemeId(); var periodId = orderLine.GetBookingPeriodId(); var periodScheme = await _periodSchemeAppService.GetAsync(periodSchemeId); var period = periodScheme.Periods.Find(x => x.Id == periodId); return(period is not null); }
public async Task <IActionResult> OnPostAdd(int ProductId) { ProductDto product = await _service.GetProductById(ProductId); if (product == null) { _toastNotification.AddErrorToastMessage("An error occurred. The product was not found"); return(Partial("_NotificationPartial")); } // If an order is already present in the Session, add a new line or increase quantity if (HttpContext.Session.Get("order") != null) { OrderDto order = HttpContext.Session.Get <OrderDto>("order"); // Search for orderline with the product id, and increase quantity OrderLineDto orderLine = order.OrderLines.Find(l => l.ProductId == ProductId); if (orderLine != null) { orderLine.Quantity += 1; } // Else add a new line else { order.OrderLines.Add(new OrderLineDto() { ProductId = ProductId, ProductName = product.Name, ProductUnitPrice = product.UnitPrice, Quantity = 1 }); } HttpContext.Session.Set("order", order); } // No order found in session, create a new else { OrderDto order = new OrderDto(); order.OrderLines.Add(new OrderLineDto() { ProductId = ProductId, ProductName = product.Name, Quantity = 1, ProductUnitPrice = product.UnitPrice }); HttpContext.Session.Set("order", order); } _toastNotification.AddSuccessToastMessage($"{product.Name} added to cart"); return(Partial("_NotificationPartial")); }
private void WireEvents() { uxPageNumber.Value = 1; { CustomerRequestResponse r = Client.Get <CustomerRequestResponse>(address + "customer_request"); bdsCustomer.DataSource = new[] { new CustomerDto { CustomerId = 0, CustomerName = "--SELECT Customer--" } }.Union(r.CustomerDtos); } { ProductRequestResponse r = Client.Get <ProductRequestResponse>(address + "product_request"); IEnumerable <ProductDto> products = new[] { new ProductDto { ProductId = 0, ProductName = "--SELECT Product--" } }.Union(r.ProductDtos); bdsProduct.DataSource = products; bdsProduct.PositionChanged += (s, e) => { OrderLineDto ol = (OrderLineDto)bdsOrderLine.Current; ProductDto px = (ProductDto)bdsProduct.Current; ol.ProductoId = px.ProductId; ol.ProductDescription = px.ProductDescription; bdsOrderLine.EndEdit(); grd.Refresh(); }; bdsOrder.CurrentItemChanged += (s, e) => { OrderDto x = (OrderDto)bdsOrder.Current; uxOrderEntryTab.Text = "Order # " + x.OrderId; }; bdsFreebie.DataSource = products; } }
public void BasketsController_Get_Basket_Order_Line_Return_Correct_Order_Line() { var baskets = new InMemoryDataStore <Basket>(); var products = new InMemoryDataStore <Product>(); products.Seed(); baskets.Seed(products); var bc = new BasketsController(products, baskets, _mapper); var actionResult = bc.GetBasketOrderLine(_testBasketId, _testProductId); OkObjectResult okresult = actionResult as OkObjectResult; Assert.IsNotNull(okresult); OrderLineDto resultOrderLine = okresult.Value as OrderLineDto; Assert.IsNotNull(resultOrderLine); Assert.AreEqual(resultOrderLine.ProductId, _testProductId); }
private Task <AuthorizationHandlerContext> CreateAuthorizationHandlerContextAsync() { var orderLine1 = new OrderLineDto { Id = BookingTestConsts.OrderLine1Id, ProductId = BookingTestConsts.BookingProduct1Id, ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id, Quantity = 1, ExtraProperties = new ExtraPropertyDictionary() }; orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId, BookingTestConsts.PeriodScheme1Id); orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id); orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingAssetId, BookingTestConsts.Asset1Id); orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate); orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime, BookingTestConsts.Period1StartingTime); orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration); orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume); var orderLine2 = new OrderLineDto { Id = BookingTestConsts.OrderLine2Id, ProductId = BookingTestConsts.BookingProduct1Id, ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id, Quantity = 1, ExtraProperties = new ExtraPropertyDictionary() }; orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId, BookingTestConsts.PeriodScheme1Id); orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id); orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingAssetCategoryId, BookingTestConsts.AssetCategory1Id); orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate); orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime, BookingTestConsts.Period1StartingTime); orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration); orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume); var currentPrincipalAccessor = ServiceProvider.GetRequiredService <ICurrentPrincipalAccessor>(); return(Task.FromResult(new AuthorizationHandlerContext( new[] { new PaymentOperationAuthorizationRequirement(PaymentOperation.Creation) }, currentPrincipalAccessor.Principal, new PaymentCreationResource { Input = new CreatePaymentDto { PaymentMethod = "Free", OrderIds = new List <Guid> { BookingTestConsts.Order1Id } }, Orders = new List <OrderDto> { new() { Id = BookingTestConsts.Order1Id, OrderLines = new List <OrderLineDto> { orderLine1, orderLine2 } } } })));
protected virtual OccupyAssetInfoModel CreateOccupyAssetInfoModel(Guid assetId, OrderLineDto orderLine) { return(new OccupyAssetInfoModel( assetId, orderLine.GetBookingVolume(), orderLine.GetBookingDate(), orderLine.GetBookingStartingTime(), orderLine.GetBookingDuration() )); }