public void callback(List <OrderResponseDto> orders, List <CartResponseDto> cartItems, string guid, int userId) { string emailHtmlMessage = ""; orders.ForEach(item => emailHtmlMessage += _emailItems.ItemDetailHtml(item.Book.Title, item.Book.Author, item.Book.Image, item.Book.Price, item.Quantity) ); int total = cartItems.Aggregate(0, (sum, item) => sum + (item.Book.Price * item.ItemQuantity) ); string orderDetails = _emailItems.OrderDetailHtml(guid, orders[0].OrderedDate, total); Message message = new Message(new string[] { orders[0].User.Email }, "Order successfully placed!", $"{emailHtmlMessage + orderDetails}"); cartItems.ForEach(item => _cacheRepository.DeleteAsync(userId.ToString(), item.Book.Id)); _mqservice.AddToQueue(message); }
public async Task <OrderResponseDto> Add(OrderRequestDto orderRequest, int userId) { try { var guid = Guid.NewGuid(); OrderResponseDto order = await _repository.Add(userId, orderRequest.bookId, orderRequest.quantity, orderRequest.addressId, guid.ToString()); await _cacheRepository.DeleteAsync(userId.ToString(), orderRequest.bookId); Message message = new Message(new string[] { order.User.Email }, "Order successfully placed!", $"{_emailItems.ItemDetailHtml(order.Book.Title, order.Book.Author, order.Book.Image, order.Book.Price, order.Book.Quantity)+ _emailItems.OrderDetailHtml(order.OrderId, order.OrderedDate, order.Book.Price)}"); _mqServices.AddToQueue(message); return(order); } catch (SqlException e) when(e.Number == SqlErrorNumbers.CONSTRAINT_VOILATION) { throw new BookstoreException("Invalid user!"); } }