public ActionResult ExportOrdersExcelNebim() { try { var orders = _orderService.SearchOrders(null, null, null, null, null, null, null, 0, int.MaxValue); string fileName = string.Format("orders_{0}_{1}.xlsx", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"), CommonHelper.GenerateRandomDigitCode(4)); string filePath = string.Format("{0}content\\files\\ExportImport\\{1}", Request.PhysicalApplicationPath, fileName); _exportManager.ExportOrdersToXlsx(filePath, orders); var bytes = System.IO.File.ReadAllBytes(filePath); return(File(bytes, "text/xls", fileName)); } catch (Exception exc) { ErrorNotification(exc); return(RedirectToAction("List")); } }
public void CanExportOrdersXlsx() { var orders = _orderService.SearchOrders(); var excelData = _exportManager.ExportOrdersToXlsx(orders); var worksheet = GetWorksheets(excelData); var manager = GetPropertyManager <Order>(worksheet); manager.ReadFromXlsx(worksheet, 2); var replacePairs = new Dictionary <string, string> { { "OrderId", "Id" }, { "OrderStatusId", "OrderStatus" }, { "PaymentStatusId", "PaymentStatus" }, { "ShippingStatusId", "ShippingStatus" }, { "ShippingPickupInStore", "PickupInStore" } }; var order = orders.First(); var ignore = new List <string>(); ignore.AddRange(replacePairs.Values); //not exported fields ignore.AddRange(new[] { "BillingAddressId", "ShippingAddressId", "PickupAddressId", "CustomerTaxDisplayTypeId", "RewardPointsHistoryEntryId", "CheckoutAttributeDescription", "CheckoutAttributesXml", "CustomerLanguageId", "CustomerIp", "AllowStoringCreditCardNumber", "CardType", "CardName", "CardNumber", "MaskedCreditCardNumber", "CardCvv2", "CardExpirationMonth", "CardExpirationYear", "AuthorizationTransactionId", "AuthorizationTransactionCode", "AuthorizationTransactionResult", "CaptureTransactionId", "CaptureTransactionResult", "SubscriptionTransactionId", "PaidDateUtc", "Deleted", "PickupAddress", "RedeemedRewardPointsEntryId", "DiscountUsageHistory", "GiftCardUsageHistory", "OrderNotes", "OrderItems", "Shipments", "OrderStatus", "PaymentStatus", "ShippingStatus ", "CustomerTaxDisplayType", "CustomOrderNumber" }); //fields tested individually ignore.AddRange(new[] { "Customer", "BillingAddressId", "ShippingAddressId", "EntityCacheKey" }); AreAllObjectPropertiesPresent(order, manager, ignore.ToArray()); PropertiesShouldEqual(order, manager, replacePairs); var addressFields = new List <string> { "FirstName", "LastName", "Email", "Company", "Country", "StateProvince", "City", "County", "Address1", "Address2", "ZipPostalCode", "PhoneNumber", "FaxNumber" }; const string billingPattern = "Billing"; replacePairs = addressFields.ToDictionary(p => billingPattern + p, p => p); var testBillingAddress = _addressService.GetAddressById(order.BillingAddressId); PropertiesShouldEqual(testBillingAddress, manager, replacePairs, "CreatedOnUtc", "BillingCountry"); manager.GetProperties.First(p => p.PropertyName == "BillingCountry").PropertyValue.Should().Be(_countryService.GetCountryByAddress(testBillingAddress).Name); const string shippingPattern = "Shipping"; replacePairs = addressFields.ToDictionary(p => shippingPattern + p, p => p); var testShippingAddress = _addressService.GetAddressById(order.ShippingAddressId ?? 0); PropertiesShouldEqual(testShippingAddress, manager, replacePairs, "CreatedOnUtc", "ShippingCountry"); manager.GetProperties.First(p => p.PropertyName == "ShippingCountry").PropertyValue.Should().Be(_countryService.GetCountryByAddress(testShippingAddress).Name); }
public void Can_export_orders_xlsx() { var orderGuid = Guid.NewGuid(); var billingAddress = GetTestBillingAddress(); var shippingAddress = GetTestShippingAddress(); var orders = new List <Order> { new Order { Id = 1, OrderGuid = orderGuid, CustomerId = 1, Customer = GetTestCustomer(), StoreId = 1, OrderStatus = OrderStatus.Complete, ShippingStatus = ShippingStatus.Shipped, PaymentStatus = PaymentStatus.Paid, PaymentMethodSystemName = "PaymentMethodSystemName1", CustomerCurrencyCode = "RUR", CurrencyRate = 1.1M, CustomerTaxDisplayType = TaxDisplayType.ExcludingTax, VatNumber = "123456789", OrderSubtotalInclTax = 2.1M, OrderSubtotalExclTax = 3.1M, OrderSubTotalDiscountInclTax = 4.1M, OrderSubTotalDiscountExclTax = 5.1M, OrderShippingInclTax = 6.1M, OrderShippingExclTax = 7.1M, PaymentMethodAdditionalFeeInclTax = 8.1M, PaymentMethodAdditionalFeeExclTax = 9.1M, TaxRates = "1,3,5,7", OrderTax = 10.1M, OrderDiscount = 11.1M, OrderTotal = 12.1M, RefundedAmount = 13.1M, CheckoutAttributeDescription = "CheckoutAttributeDescription1", CheckoutAttributesXml = "CheckoutAttributesXml1", CustomerLanguageId = 14, AffiliateId = 15, CustomerIp = "CustomerIp1", AllowStoringCreditCardNumber = true, CardType = "Visa", CardName = "John Smith", CardNumber = "4111111111111111", MaskedCreditCardNumber = "************1111", CardCvv2 = "123", CardExpirationMonth = "12", CardExpirationYear = "2010", AuthorizationTransactionId = "AuthorizationTransactionId1", AuthorizationTransactionCode = "AuthorizationTransactionCode1", AuthorizationTransactionResult = "AuthorizationTransactionResult1", CaptureTransactionId = "CaptureTransactionId1", CaptureTransactionResult = "CaptureTransactionResult1", SubscriptionTransactionId = "SubscriptionTransactionId1", PaidDateUtc = new DateTime(2010, 01, 01), CustomValuesXml = "<test>test</test>", BillingAddress = billingAddress, ShippingAddress = shippingAddress, ShippingMethod = "ShippingMethod1", ShippingRateComputationMethodSystemName = "ShippingRateComputationMethodSystemName1", Deleted = false, CreatedOnUtc = new DateTime(2010, 01, 04) } }; var excelData = _exportManager.ExportOrdersToXlsx(orders); var worksheet = GetWorksheets(excelData); var manager = GetPropertyManager <Order>(worksheet); manager.ReadFromXlsx(worksheet, 2); var replacePairse = new Dictionary <string, string> { { "OrderId", "Id" }, { "OrderStatusId", "OrderStatus" }, { "PaymentStatusId", "PaymentStatus" }, { "ShippingStatusId", "ShippingStatus" }, { "ShippingPickUpInStore", "PickUpInStore" } }; var order = orders.First(); var ignore = new List <string>(); ignore.AddRange(replacePairse.Values); //not exported fields ignore.AddRange(new[] { "BillingAddressId", "ShippingAddressId", "PickupAddressId", "CustomerTaxDisplayTypeId", "RewardPointsHistoryEntryId", "CheckoutAttributeDescription", "CheckoutAttributesXml", "CustomerLanguageId", "CustomerIp", "AllowStoringCreditCardNumber", "CardType", "CardName", "CardNumber", "MaskedCreditCardNumber", "CardCvv2", "CardExpirationMonth", "CardExpirationYear", "AuthorizationTransactionId", "AuthorizationTransactionCode", "AuthorizationTransactionResult", "CaptureTransactionId", "CaptureTransactionResult", "SubscriptionTransactionId", "PaidDateUtc", "Deleted", "PickupAddress", "RedeemedRewardPointsEntry", "DiscountUsageHistory", "GiftCardUsageHistory", "OrderNotes", "OrderItems", "Shipments", "OrderStatus", "PaymentStatus", "ShippingStatus ", "CustomerTaxDisplayType", "CustomOrderNumber" }); //fields tested individually ignore.AddRange(new[] { "Customer", "BillingAddress", "ShippingAddress" }); AreAllObjectPropertiesPresent(order, manager, ignore.ToArray()); PropertiesShouldEqual(order, manager, replacePairse); var addressFilds = new List <string> { "FirstName", "LastName", "Email", "Company", "Country", "StateProvince", "City", "County", "Address1", "Address2", "ZipPostalCode", "PhoneNumber", "FaxNumber" }; const string billingPatern = "Billing"; replacePairse = addressFilds.ToDictionary(p => billingPatern + p, p => p); PropertiesShouldEqual(billingAddress, manager, replacePairse, "CreatedOnUtc", "BillingCountry"); manager.GetProperties.First(p => p.PropertyName == "BillingCountry").PropertyValue.ShouldEqual(billingAddress.Country.Name); const string shippingPatern = "Shipping"; replacePairse = addressFilds.ToDictionary(p => shippingPatern + p, p => p); PropertiesShouldEqual(shippingAddress, manager, replacePairse, "CreatedOnUtc", "ShippingCountry"); manager.GetProperties.First(p => p.PropertyName == "ShippingCountry").PropertyValue.ShouldEqual(shippingAddress.Country.Name); }
/// <summary> /// Export orders to XLSX /// </summary> /// <param name="orders">Orders</param> public byte[] ExportOrdersToXlsx(IList <Order> orders) { return(_exportManager.ExportOrdersToXlsx(orders)); }