public IHttpActionResult SetOrdersShipped(HttpRequestMessage request, [FromBody]ApiOrderShipmentRequest orderShipmentRequest) { ExternalOrderShippedResult shippedResult = new ExternalOrderShippedResult(); if (orderShipmentRequest.ShippedOrders.Count == 0) { shippedResult.Success = false; shippedResult.ErrorMessage = "No Order selected for shipment"; return Ok(shippedResult); } try { shippedResult = externalOrderActivity.SetExternalOrderShipped(orderShipmentRequest); int successCount = shippedResult.ShippingResults.Where(x => x.Success).Count(); int errorCount = shippedResult.ShippingResults.Where(x => x.Success == false).Count(); shippedResult.Success = shippedResult.Success; return Ok(shippedResult); } catch (Exception ex) { shippedResult.Success = false; shippedResult.ErrorMessage = ex.Message; return Ok(shippedResult); } }
public ExternalOrderShippedResult SetExternalOrderShipped(ApiOrderShipmentRequest orderShipmentRequest) { ExternalOrderShippedResult shippedResult = new ExternalOrderShippedResult(); shippedResult = new ExternalOrderClient().SetOrdersShipped(orderShipmentRequest); try { if (shippedResult != null && shippedResult.ShippingResults.Count > 0) { using (InnoventoryDBContext dbContext = new InnoventoryDBContext()) { DbSet<ExternalOrder> externalOrderSet = dbContext.ExternalOrderSet; foreach (ShippingResult shippingResult in shippedResult.ShippingResults) { ExternalOrder shippedOrder = externalOrderSet.Where(x => x.StoreOrderHeaderId == shippingResult.ExternalOrderHeaderId).FirstOrDefault(); if (shippedOrder != null) { if (shippingResult.Success) { try { shippedOrder.ShippedDate = shippingResult.ShippedDate.Value; shippedOrder.OrderStatus = (int)StoreOrderStatusEnum.Shipped; shippedOrder.StoreOrderStatus = StoreOrderStatusEnum.Shipped.ToString(); externalOrderSet.Attach(shippedOrder); dbContext.Entry(shippedOrder).State = EntityState.Modified; dbContext.SaveChanges(); } catch(DbEntityValidationException dbEx) { string errorMessage = string.Join("; ", dbEx.EntityValidationErrors); shippedResult.ErrorMessage = shippedResult.ErrorMessage + "; " + errorMessage; } } } } } shippedResult.Success = true; } } catch (Exception ex) { shippedResult.ErrorMessage = shippedResult.ErrorMessage + "; " +ex.Message; shippedResult.Success = false; } return shippedResult; }
public ExternalOrderShippedResult SetOrderShipped(IOrderShipmentRequest shipmentRequests) { CompleteSaleCall completeSales = new CompleteSaleCall(eBayContext); ExternalOrderShippedResult result = new ExternalOrderShippedResult() { Success = false, ShippingResults = new List<ShippingResult>() }; bool allSuccess = true; int successCount = 0; int failedCount = 0; StringBuilder errorBuilder = new StringBuilder(); foreach (eBayOrderShipmentIfo request in shipmentRequests.ShipmentList) { ShippingResult shippingResult = new ShippingResult() { StoreProviderOrderId = request.OrderId, ExternalOrderHeaderId = request.ExternalOrderHeaderId, ShippedDate = request.ShipmentDate, }; try { completeSales.OrderID = request.OrderId; ShipmentType shipment = new ShipmentType(); shipment.ShippedTime = request.ShipmentDate; completeSales.Shipment = shipment; completeSales.Shipped = true; completeSales.Site = SiteCodeType.UK; completeSales.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); completeSales.Execute(); if (completeSales.ApiResponse.Ack == AckCodeType.Success) { shippingResult.Success = true; successCount += 1; } else { allSuccess = false; shippingResult.Success = false; StringBuilder sb = new StringBuilder(); foreach (ErrorType error in completeSales.ApiResponse.Errors) { sb.Append(error.LongMessage + "; "); } shippingResult.ErrorMessage = string.Format("eBay Code returned : {0}; Error: {1}", completeSales.ApiResponse.Ack.ToString(), sb.ToString().Trim()); errorBuilder.Append(sb.ToString() + " | "); failedCount += 1; } } catch (Exception ex) { allSuccess = false; shippingResult.Success = false; shippingResult.ErrorMessage = string.Format("Error occurred while updating shipping info: {0}, Error: {1}", request.OrderId, ex.Message); errorBuilder.Append(shippingResult.ErrorMessage + " | "); failedCount += 1; } } if (allSuccess) { result.Success = true; } else { result.Success = false; result.ErrorMessage = "Some orders could not be shipped"; } if (successCount > 0) { result.SuccessMessage = string.Format("Successfully Shipped {0} Orders ", successCount); } if (failedCount > 0) { result.ErrorMessage = string.Format("Failed to Ship {0} Orders, please check and try again.", failedCount); result.ErrorMessage += "<br/> " + errorBuilder.ToString(); } return result; }