public void GenerateGiftVoucherCode_ShouldReturnUniqueValues() { var results = new List <string>(); results.Add(_service.GenerateGiftVoucherCode()); results.Add(_service.GenerateGiftVoucherCode()); results.Add(_service.GenerateGiftVoucherCode()); results.Add(_service.GenerateGiftVoucherCode()); results.Add(_service.GenerateGiftVoucherCode()); results.Add(_service.GenerateGiftVoucherCode()); results.Add(_service.GenerateGiftVoucherCode()); Assert.IsTrue(results.Count.Equals(results.Distinct().Count())); }
public async Task <bool> Handle(InsertOrderItemCommand request, CancellationToken cancellationToken) { if (request.Order == null) { throw new ArgumentNullException(nameof(request.Order)); } if (request.OrderItem == null) { throw new ArgumentNullException(nameof(request.OrderItem)); } request.Order.OrderItems.Add(request.OrderItem); request.Order.OrderSubtotalExclTax += request.OrderItem.PriceExclTax; request.Order.OrderSubtotalInclTax += request.OrderItem.PriceInclTax; request.Order.OrderTax += (request.OrderItem.PriceInclTax - request.OrderItem.PriceExclTax); request.Order.OrderTotal += request.OrderItem.PriceInclTax; if (request.Order.ShippingStatusId == ShippingStatus.Delivered && request.OrderItem.IsShipEnabled) { request.Order.ShippingStatusId = ShippingStatus.PartiallyShipped; } if (request.Order.ShippingStatusId == ShippingStatus.ShippingNotRequired && request.OrderItem.IsShipEnabled) { request.Order.ShippingStatusId = ShippingStatus.Pending; } //TODO //request.Order.OrderTaxes await _orderService.UpdateOrder(request.Order); //adjust inventory await _inventoryManageService.AdjustReserved(request.Product, -request.OrderItem.Quantity, request.OrderItem.Attributes, request.OrderItem.WarehouseId); //check order status await _mediator.Send(new CheckOrderStatusCommand() { Order = request.Order }); //add a note await _orderService.InsertOrderNote(new OrderNote { Note = "A new order item has been added", DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow, OrderId = request.Order.Id, }); //gift vouchers if (request.Product.IsGiftVoucher) { for (int i = 0; i < request.OrderItem.Quantity; i++) { var gc = new GiftVoucher { GiftVoucherTypeId = request.Product.GiftVoucherTypeId, PurchasedWithOrderItem = request.OrderItem, Amount = request.OrderItem.UnitPriceExclTax, CurrencyCode = request.Order.CustomerCurrencyCode, IsGiftVoucherActivated = false, Code = _giftVoucherService.GenerateGiftVoucherCode(), //TODO //RecipientName = recipientName, //RecipientEmail = recipientEmail, //SenderName = senderName, //SenderEmail = senderEmail, //Message = giftVoucherMessage, IsRecipientNotified = false, CreatedOnUtc = DateTime.UtcNow }; await _giftVoucherService.InsertGiftVoucher(gc); } } return(true); }
public IActionResult GenerateCouponCode() { return(Json(new { CouponCode = _giftVoucherService.GenerateGiftVoucherCode() })); }