private void ProcessOrderData(OrderTypeCollection orders) { foreach (OrderType orderDto in orders) { try { PersistOrder(orderDto); } catch (Exception e) { _logger.Error(string.Format("Order ( {1} | {0} ) synchronization failed: {2}", orderDto.ShippingDetails.SellingManagerSalesRecordNumber, _marketplace.Code, e.Message)); } } _dataContext.SaveChanges(); var combinedOrders = orders.ToArray().Where(p => p.TransactionArray.Count > 1); foreach (OrderType orderDto in combinedOrders) { RemoveParentOrder(orderDto); } _dataContext.SaveChanges(); }
private void btnDone_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Are you sure you want to commit changes ?", "Confirm", MessageBoxButtons.YesNo); if (dr.Equals(DialogResult.No)) { return; } foreach (ProductStock product in _scanProducts) { product.ApplyChanges(); Bsi_LocationLog logEntry = new Bsi_LocationLog(); logEntry.Item = product.Item; logEntry.User = _user; logEntry.BeforeChange = product.PreviousBin; logEntry.Location = "+ " + _scanBin; logEntry.UpdateDate = DateTime.Now; logEntry.Quantity = product.QtyScan; } _dataContext.SaveChanges(); this.Close(); }
private void Persist(ListingDto listingDto, string sellingState) { using (berkeleyEntities dataContext = new berkeleyEntities()) { BonanzaListing listing = new BonanzaListing(); listing.MarketplaceID = _marketplace.ID; listing.Code = listingDto.Code; listing.FullDescription = listingDto.FullDescription; listing.Title = listingDto.Title; listing.Status = sellingState; listing.LastSyncTime = DateTime.UtcNow; listing.Sku = listingDto.Sku; listing.IsVariation = listingDto.IsVariation; foreach (ListingItemDto listingItemDto in listingDto.Items) { BonanzaListingItem listingItem = new BonanzaListingItem(); listingItem.Listing = listing; listingItem.Item = dataContext.Items.Single(p => p.ItemLookupCode.Equals(listingItemDto.Sku)); listingItem.Quantity = listingItemDto.Qty.Value; listingItem.Price = listingItemDto.Price.Value; } dataContext.SaveChanges(); } }
private void btnAccept_Click(object sender, EventArgs e) { var locations = lbDeleteList.Items.Cast <string>(); if (locations.Count() == 0) { MessageBox.Show("delete list is empty"); return; } DialogResult dr = MessageBox.Show("Are you sure you want to clean all locations in delete list ?", "Confirm", MessageBoxButtons.OKCancel); if (dr.Equals(DialogResult.Cancel)) { return; } int deleteCount = 0; using (berkeleyEntities dataContext = new berkeleyEntities()) { foreach (string location in locations) { var items = dataContext.Items.Where(p => p.BinLocation.Contains(location)); foreach (Item item in items) { List <string> currentBins = item.BinLocation.Split(new Char[1] { ' ' }).ToList(); currentBins.ForEach(p => p = p.ToUpper().Trim()); if (currentBins.Any(p => p.Equals(location))) { Bsi_LocationLog logEntry = new Bsi_LocationLog(); logEntry.Item = item; logEntry.Location = "- " + location; logEntry.Quantity = 0; logEntry.User = _user; logEntry.UpdateDate = DateTime.Now; logEntry.BeforeChange = item.BinLocation; deleteCount += currentBins.RemoveAll(p => p.Equals(location)); item.BinLocation = String.Join(" ", currentBins).Trim(); } } } dataContext.SaveChanges(); } MessageBox.Show(deleteCount.ToString() + " locations deleted"); this.Close(); }
private void Update(string code, string status) { using (berkeleyEntities dataContext = new berkeleyEntities()) { BonanzaListing listing = dataContext.BonanzaListings.Single(p => p.MarketplaceID == _marketplace.ID && p.Code.Equals(code)); listing.Status = status; listing.LastSyncTime = DateTime.UtcNow; dataContext.SaveChanges(); } }
private void Update(ListingDto listingDto) { using (berkeleyEntities dataContext = new berkeleyEntities()) { BonanzaListing listing = dataContext.BonanzaListings.Single(p => p.MarketplaceID == _marketplace.ID && p.Code.Equals(listingDto.Code)); if (!string.IsNullOrWhiteSpace(listingDto.FullDescription)) { listing.FullDescription = listingDto.FullDescription; } if (!string.IsNullOrWhiteSpace(listingDto.Title)) { listing.Title = listingDto.Title; } foreach (ListingItemDto listingItemDto in listingDto.Items) { Item item = dataContext.Items.Single(p => p.ItemLookupCode.Equals(listingItemDto.Sku)); BonanzaListingItem listingItem = listing.ListingItems.SingleOrDefault(p => p.Item.ID == item.ID); if (listingItem == null) { listingItem = new BonanzaListingItem() { Item = item, Listing = listing }; } if (listingItemDto.Qty.HasValue) { listingItem.Quantity = listingItemDto.Qty.Value; } if (listingItemDto.Price.HasValue) { listingItem.Price = listingItemDto.Price.Value; } } listing.LastSyncTime = DateTime.UtcNow; dataContext.SaveChanges(); } }
//public void SynchronizeListings(int marketplaceID) //{ // using (berkeleyEntities dataContext = new berkeleyEntities()) // { // EbayMarketplace marketplace = dataContext.EbayMarketplaces.Single(p => p.ID == marketplaceID); // ListingSynchronizer synchronizer = new ListingSynchronizer(marketplace, dataContext); // DateTime syncTime = DateTime.UtcNow.AddMinutes(-3); // if (marketplace.ListingSyncTime.HasValue && marketplace.ListingSyncTime.Value > syncTime.AddDays(-2)) // { // DateTime from = marketplace.ListingSyncTime.Value.AddMinutes(-5); // synchronizer.SyncByCreatedTime(from, syncTime); // try // { // synchronizer.SyncByModifiedTime(from, syncTime); // } // catch (ApiException e) // { // if (e.Errors.ToArray().Any(p => p.ErrorCode.Equals("21917062"))) // { // synchronizer.SyncActiveListings(); // } // } // } // else // { // synchronizer.SyncActiveListings(); // } // marketplace.ListingSyncTime = syncTime; // dataContext.SaveChanges(); // } //} //public void SynchronizeOrders(int marketplaceID) //{ // using (berkeleyEntities dataContext = new berkeleyEntities()) // { // EbayMarketplace marketplace = dataContext.EbayMarketplaces.Single(p => p.ID == marketplaceID); // OrderSynchronizer synchronizer = new OrderSynchronizer(marketplace, dataContext); // DateTime syncTime = DateTime.UtcNow.AddMinutes(-3); // DateTime from = marketplace.OrdersSyncTime.HasValue ? marketplace.OrdersSyncTime.Value.AddMinutes(-5) : DateTime.UtcNow.AddDays(-29); // synchronizer.SyncOrdersByModifiedTime(from, syncTime); // marketplace.OrdersSyncTime = syncTime; // dataContext.SaveChanges(); // } //} //public void FixOverpublished(int marketplaceID) //{ // using (berkeleyEntities dataContext = new berkeleyEntities()) // { // EbayMarketplace marketplace = dataContext.EbayMarketplaces.Single(p => p.ID == marketplaceID); // if (!marketplace.ListingSyncTime.HasValue || marketplace.ListingSyncTime.Value < DateTime.UtcNow.AddHours(-1)) // { // throw new InvalidOperationException(marketplace.Name + " listings must be synchronized in order to fix overpublished"); // } // if (!marketplace.OrdersSyncTime.HasValue || marketplace.OrdersSyncTime.Value < DateTime.UtcNow.AddHours(-1)) // { // throw new InvalidOperationException(marketplace.Name + " orders must be synchronized in order to fix overpublished"); // } // var listings = dataContext.EbayListings.Where(p => p.Status.Equals(EbayMarketplace.STATUS_ACTIVE) && p.MarketplaceID == marketplace.ID).ToList(); // foreach (EbayListing listing in listings.Where(p => !p.ListingItems.Any(s => s.Item == null))) // { // if(listing.Format.Equals(EbayMarketplace.FORMAT_AUCTION)) // { // var listingItem = listing.ListingItems.First(); // if(listingItem.Item.AuctionCount > listingItem.Item.QtyAvailable) // { // try // { // End(marketplaceID, listing.Code); // } // catch (Exception e) // { // _logger.Error(e.Message); // } // } // } // else // { // var listingItems = listing.ListingItems.ToList(); // if (listingItems.Any(p => p.Quantity > p.Item.QtyAvailable)) // { // List<ListingItemDto> listingItemDtos = new List<ListingItemDto>(); // foreach (var listingItem in listingItems) // { // if (listingItem.Quantity > listingItem.Item.QtyAvailable) // { // listingItemDtos.Add(new ListingItemDto() { Sku = listingItem.Item.ItemLookupCode, Qty = listingItem.Item.QtyAvailable, QtySpecified = true }); // } // else // { // listingItemDtos.Add(new ListingItemDto() { Sku = listingItem.Item.ItemLookupCode, Qty = listingItem.Quantity, QtySpecified = true }); // } // } // if (listingItemDtos.All(p => p.Qty == 0)) // { // try // { // End(marketplaceID, listing.Code); // } // catch (Exception e) // { // _logger.Error(e.Message); // } // } // else // { // ListingDto listingDto = new ListingDto(); // listingDto.MarketplaceID = marketplaceID; // listingDto.Code = listing.Code; // listingDto.Items.AddRange(listingItemDtos); // listingDto.IsVariation = (bool)listing.IsVariation; // try // { // Revise(listingDto, false, false); // } // catch (Exception e) // { // _logger.Error(e.Message); // } // } // } // } // } // } //} public void SynchronizeListing(int marketplaceID) { using (berkeleyEntities dataContext = new berkeleyEntities()) { BonanzaMarketplace marketplace = dataContext.BonanzaMarketplaces.Single(p => p.ID == marketplaceID); ListingSynchronizer synchronizer = new ListingSynchronizer(marketplace, dataContext); string[] status = new string[] { "for_sale", "ready_to_post", "missing_fields", "sold", "pending_pickup", "reserved" }; marketplace.ListingSyncTime = DateTime.UtcNow; synchronizer.SyncByStatus(status); dataContext.SaveChanges(); } }
public void SavePriceDataChanges(IEnumerable <AmazonEnvelopeMessage> msgs) { using (berkeleyEntities dataContext = new berkeleyEntities()) { foreach (AmazonEnvelopeMessage msg in msgs) { Price priceData = (Price)msg.Item; AmznListingItem listingItem = dataContext.AmznListingItems .Single(p => p.Item.ItemLookupCode.Equals(priceData.SKU) && p.MarketplaceID == _marketplace.ID && p.IsActive); listingItem.Price = priceData.StandardPrice.Value; } dataContext.SaveChanges(); } }
public void SaveInventoryDataChanges(IEnumerable <AmazonEnvelopeMessage> msgs) { using (berkeleyEntities dataContext = new berkeleyEntities()) { foreach (AmazonEnvelopeMessage msg in msgs) { Inventory inventoryData = (Inventory)msg.Item; AmznListingItem listingItem = dataContext.AmznListingItems .Single(p => p.Item.ItemLookupCode.Equals(inventoryData.SKU) && p.MarketplaceID == _marketplace.ID && p.IsActive); listingItem.Quantity = Convert.ToInt32(inventoryData.Item); } dataContext.SaveChanges(); } }
public List <AmznListingItem> SaveProductDataChanges(IEnumerable <AmazonEnvelopeMessage> msgs) { var added = _dataContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(p => p.Entity).Cast <AmznListingItem>(); List <AmznListingItem> listingItems = new List <AmznListingItem>(); using (berkeleyEntities dataContext = new berkeleyEntities()) { foreach (var msg in msgs) { Product product = (Product)msg.Item; if (dataContext.Items.Any(p => p.ItemLookupCode.Equals(product.SKU))) { AmznListingItem listingItem = dataContext.AmznListingItems .SingleOrDefault(p => p.Item.ItemLookupCode.Equals(product.SKU) && p.MarketplaceID == _marketplace.ID); listingItems.Add(added.Single(p => p.Item.ItemLookupCode.Equals(product.SKU))); if (listingItem == null) { listingItem = new AmznListingItem(); listingItem.Item = dataContext.Items.Single(p => p.ItemLookupCode.Equals(product.SKU)); listingItem.Sku = product.SKU; listingItem.Marketplace = dataContext.AmznMarketplaces.Single(p => p.ID == _marketplace.ID); listingItem.OpenDate = DateTime.UtcNow; listingItem.LastSyncTime = DateTime.UtcNow; listingItem.ASIN = "UNKNOWN"; listingItem.Quantity = 0; listingItem.Price = 0; listingItem.Title = product.DescriptionData.Title; } listingItem.IsActive = true; } } dataContext.SaveChanges(); } return(listingItems); }
public void bckWorker_DoWork(object sender, DoWorkEventArgs e) { _proxy = new Mage_Api_Model_Server_V2_HandlerPortTypeClient(); _sessionID = _proxy.login("berkeleyJuan", "genesis13"); _catalogProductFactories.ForEach(p => p.Initiliaze(_proxy, _sessionID)); using (berkeleyEntities dataContext = new berkeleyEntities()) { var posts = dataContext.bsi_posts.Where(p => p.marketplace == 512 && p.status == 10 && p.purchaseOrder.Equals(_currentWorkOrder)).ToList(); double processed = 0; double totalPending = posts.Count(); _succesfulUploads = 0; _errorCount = 0; if (totalPending > 0) { foreach (bsi_posts post in posts) { try { CreateOrUpdateCatalogProduct(post); _succesfulUploads += post.bsi_quantities.Count; post.status = 0; } catch (NotImplementedException ex) { foreach (bsi_quantities postItem in post.bsi_quantities) { _errorCount++; this.Log(postItem.itemLookupCode + ": " + ex.Message); } } dataContext.SaveChanges(); processed++; _bckWorker.ReportProgress((int)((processed / totalPending) * 100)); } } } }
public void Update() { List <InventoryEntry> entryGroups = _dataContext.InventoryEntries.Where(p => p.PhysicalInventory.ID == _inventoryRef.ID).ToList(); var groups = entryGroups.GroupBy(p => p.Item.ID); //var entryGroups = _dataContext.InventoryEntries.Where(p => p.PhysicalInventory.ID == _inventoryRef.ID && p.Bin.Equals("WALL")).GroupBy(p => p.Item.ID); foreach (var entryGroup in groups) { Item item = _dataContext.Items.Single(p => p.ID == entryGroup.Key); var expectedBins = item.BinLocation.Split(new Char[1] { ' ' }).Distinct().Where(p => !string.IsNullOrWhiteSpace(p)); var actualBins = entryGroup.Select(p => p.Bin); List <string> currentBin = new List <string>(expectedBins); currentBin.ForEach(p => p = p.Trim().ToUpper()); foreach (string bin in expectedBins.Except(actualBins)) { Bsi_LocationLog log = new Bsi_LocationLog(); log.Item = item; log.Location = "- " + bin; log.Quantity = 0; log.UpdateDate = DateTime.Now; log.User = _inventoryRef.Code; log.BeforeChange = string.Join(" ", currentBin); currentBin.Remove(bin); } foreach (InventoryEntry entry in entryGroup) { Bsi_LocationLog log = new Bsi_LocationLog(); log.Item = item; log.Location = "+ " + entry.Bin; log.Quantity = entry.Counted; log.UpdateDate = DateTime.Now; log.User = entry.User + " (" + _inventoryRef.Code + ")"; log.BeforeChange = string.Join(" ", currentBin); if (!currentBin.Any(p => p.Equals(entry.Bin))) { currentBin.Add(entry.Bin); } } var newBin = string.Join(" ", currentBin); if (newBin.Count() > 20) { item.BinLocation = newBin.Substring(0, 20); } else { item.BinLocation = newBin; } //int charCount = currentBin.Sum(s => s.Count()) + (currentBin.Count() - 1); //List<string> notesField = new List<string>(); //while (charCount > 20) //{ // string bin = currentBin.First(); // currentBin.Remove(bin); // notesField.Add(bin); // charCount = currentBin.Sum(s => s.Count()) + (currentBin.Count() - 1); //} //if (notesField.Count > 0) //{ // item.Notes = item.Notes.Trim() + string.Join(" ", notesField); //} } _dataContext.SaveChanges(); }
public void SaveChanges() { _dataContext.SaveChanges(); _dataContext.Dispose(); }
static void CreateOrder(string id) { Order order = new Order(); order.id = id; OrderAddressInfo address1 = new OrderAddressInfo(); address1.Address1 = "testing ship"; address1.Address2 = "testing"; address1.City = "Narnia"; address1.Country = "Atlantis"; address1.Email = "*****@*****.**"; address1.Name = new OrderAddressInfoName() { First = "Romulo Bentancourt", Full = "testing", Last = "testing" }; address1.Phone = "555*666-beast"; address1.State = "MA"; address1.type = "ship"; address1.Zip = 01844; OrderAddressInfo address2 = new OrderAddressInfo(); address2.Address1 = "testing bill"; address2.Address2 = "testing"; address2.City = "Narnia"; address2.Country = "Atlantis"; address2.Email = "*****@*****.**"; address2.Name = new OrderAddressInfoName() { First = "Romulo Bentancourt", Full = "testing", Last = "testing" }; address2.Phone = "555*666-beast"; address2.State = "MA"; address2.type = "bill"; address2.Zip = 01844; order.AddressInfo = new OrderAddressInfo[] { address1, address2 }; OrderItem item = new OrderItem(); item.Code = "10061-10-M"; item.Description = "CASH MONEY HOE"; item.Id = 6666666; item.Quantity = 10; item.UnitPrice = 100; order.Item = new OrderItem[] { item }; OrderLine orderLine = new OrderLine(); orderLine.name = "testing"; orderLine.type = "type"; orderLine.Value = 1000; order.Total = new OrderLine[] { orderLine }; StringWriter stringWriter = new StringWriter(); XmlSerializer serializer = new XmlSerializer(typeof(Order)); serializer.Serialize(stringWriter, order); using (berkeleyEntities dataContext = new berkeleyEntities()) { Exchange exchange = new Exchange(); exchange.Data = stringWriter.ToString(); exchange.Comment = "testing"; exchange.DateCreated = DateTime.UtcNow; exchange.ProcessorCode = "YahooStore"; exchange.Status = 0; exchange.LastUpdated = DateTime.UtcNow; dataContext.Exchanges.AddObject(exchange); dataContext.SaveChanges(); } }