public static PrintLabelResult GenerateLabel( IUnitOfWork db, ILabelService labelService, IWeightService weightService, IShippingService shippingService, MailViewModel model, DateTime when, long?by) { var shippingMethod = db.ShippingMethods.GetByIdAsDto(model.ShippingMethodSelected.Value); var orderItems = model.Items.Select(i => i.GetItemDto()).ToList() ?? new List <DTOOrderItem>(); //Fill with additional data MailViewModel.FillItemsWithAdditionalInfo(db, weightService, model.OrderID, orderItems); var mailInfo = new MailLabelDTO { FromAddress = model.FromAddress.GetAddressDto(), ToAddress = model.ToAddress.GetAddressDto(), Notes = model.Notes, Instructions = model.Instructions, OrderId = model.OrderID, WeightLb = model.WeightLb, WeightOz = model.WeightOz, PackageHeight = model.PackageHeight, PackageLength = model.PackageLength, PackageWidth = model.PackageWidth, IsAddressSwitched = model.IsAddressSwitched, IsUpdateRequired = model.UpdateAmazon, IsCancelCurrentOrderLabel = model.CancelCurrentOrderLabel, IsInsured = model.IsInsured, IsSignConfirmation = model.IsSignConfirmation, TotalPrice = model.TotalPrice, TotalPriceCurrency = model.TotalPriceCurrency, ShippingMethod = shippingMethod, ShipmentProviderType = shippingMethod.ShipmentProviderType, Items = orderItems, MarketplaceCode = model.MarketplaceCode, Reason = model.ReasonCode ?? 0, BoughtInTheCountry = MarketBaseHelper.GetMarketCountry((MarketType)model.Market, model.MarketplaceId), }; return(labelService.PrintMailLabel(db, shippingService, mailInfo, when, by, AppSettings.LabelDirectory, AppSettings.TemplateDirectory, AppSettings.IsSampleLabels)); }
public void StoreInfo(MailLabelDTO mailInfo, IList <DTOOrderItem> mailItems, DateTime when, long?by) { var orderId = mailItems.Where(i => i.Quantity > 0).Select(i => i.OrderId).FirstOrDefault(); if (!orderId.HasValue) { orderId = string.IsNullOrEmpty(mailInfo.OrderId) ? null : (long?)unitOfWork.Orders.GetFiltered(o => o.AmazonIdentifier == mailInfo.OrderId || o.CustomerOrderId == mailInfo.OrderId).FirstOrDefault()?.Id; } var sourceAddress = mailInfo.IsAddressSwitched ? mailInfo.FromAddress : mailInfo.ToAddress; var dbMailLabelInfo = new MailLabelInfo { Marketplace = mailInfo.MarketplaceCode, OrderId = orderId, TrackingNumber = mailInfo.TrackingNumber, IntegratorTxIdentifier = mailInfo.IntegratorTxIdentifier, StampsTxId = mailInfo.StampsTxId, StampsShippingCost = mailInfo.StampsShippingCost, ShipmentProviderType = mailInfo.ShipmentProviderType, ShippingMethodId = mailInfo.ShippingMethod.Id, ReasonId = mailInfo.Reason, Notes = mailInfo.Notes, Instructions = mailInfo.Instructions, WeightLb = mailInfo.WeightLb ?? 0, WeightOz = mailInfo.WeightOz ?? 0, IsAddressSwitched = mailInfo.IsAddressSwitched, Name = sourceAddress.FullName, Address1 = sourceAddress.Address1, Address2 = sourceAddress.Address2, City = sourceAddress.City, State = sourceAddress.State, Country = sourceAddress.Country, Zip = sourceAddress.Zip, ZipAddon = sourceAddress.ZipAddon, Phone = sourceAddress.Phone, IsInsured = mailInfo.IsInsured, InsuranceCost = mailInfo.InsuranceCost, InsuredValue = mailInfo.TotalPrice, IsSignConfirmation = mailInfo.IsSignConfirmation, SignConfirmationCost = mailInfo.SignConfirmationCost, UpChargeCost = mailInfo.UpChargeCost, ShippingDate = mailInfo.ShippingDate, EstimatedDeliveryDate = mailInfo.EstimatedDeliveryDate, BuyDate = when, LabelPath = mailInfo.LabelPath, LabelPrintPackId = mailInfo.LabelPrintPackId, IsUpdateRequired = mailInfo.IsUpdateRequired, IsCancelCurrentOrderRequested = mailInfo.IsCancelCurrentOrderLabel, CreateDate = when, CreatedBy = by }; Add(dbMailLabelInfo); unitOfWork.Commit(); foreach (var item in mailItems) { unitOfWork.MailLabelItems.Add(new MailLabelItem() { MailLabelInfoId = dbMailLabelInfo.Id, OrderId = orderId ?? 0, ItemOrderIdentifier = item.ItemOrderId, Quantity = item.Quantity, StyleId = item.StyleEntityId ?? 0, StyleItemId = item.StyleItemId ?? 0, CreateDate = when, CreatedBy = by, }); } unitOfWork.Commit(); }