public object AssignWarehouseCarrier(int FulOrderId, int WarehouseId, int CarrierId, int CarrierServiceId) { try { int FulStatusId = (from fs in context.FulOrderStatus where fs.Name.ToUpper() == _iconfiguration["ASSIGNED"] select fs.FulOrderStatusId).FirstOrDefault(); bool FulOrderAutoHold_FLG = (from cs in context.CarrierService where cs.CarrierServiceId == CarrierServiceId select cs.FulOrderAutoHold_FLG).FirstOrDefault(); int OnHoldReasonId = (from r in context.OnHoldReason where r.Name.ToUpper() == _iconfiguration["EXPENSIVE_SERVICE_WAS_ASSIGNED"] select r.OnHoldReasonId).FirstOrDefault(); FulOrder FulOrderObj = (from fo in context.FulOrder where fo.FulOrderId == FulOrderId select fo).FirstOrDefault(); if (FulOrderObj != null) { FulOrderObj.AssignedWarehouseId = WarehouseId; FulOrderObj.AssignedCarrierId = CarrierId; FulOrderObj.AssignedCarrierServiceId = CarrierServiceId; FulOrderObj.FulOrderStatusId = FulStatusId; FulOrderObj.Assignment_DT = DateTime.Now; if (FulOrderAutoHold_FLG) { FulOrderObj.OnHold_FLG = true; FulOrderObj.OnHoldReasonId = OnHoldReasonId; } context.FulOrder.Update(FulOrderObj); context.SaveChanges(); return(true); } else { return(false); } } catch (Exception Ex) { LogServiceObj.LogException(Ex); MailServiceObj.SendMail(Ex.Message ?? "", (Ex.InnerException != null) ? Ex.InnerException.Message : "", Ex.StackTrace ?? ""); return(false); } }
public Object EditFulorder(FulfillOrderViewDTO FulOrder) { try { bool isSuccess = false; string result = string.Empty; int fulOrderId = FulOrder.fulOrderId; FulOrder FulOrderObj = (from fo in context.FulOrder where fo.FulOrderId == fulOrderId select fo).FirstOrDefault(); if (FulOrderObj != null) { FulOrderObj.Error_FLG = FulOrder.errorFlag == "No" ? false : true; FulOrderObj.OnHold_FLG = FulOrder.onHoldFlag == "No" ? false : true; FulOrderObj.OnHoldReasonId = Convert.ToInt32(FulOrder.onHoldReason); FulOrderObj.ErrorReasonId = Convert.ToInt32(FulOrder.errorReason); context.FulOrder.Update(FulOrderObj); context.SaveChanges(); result = _iconfiguration["FULORDER_EDITED_SUCCESSFUL"]; isSuccess = true; } return(new { status = isSuccess, fulOrderID = FulOrder.fulOrderId, message = result }); } catch (Exception ex) { if (ex.InnerException != null) { return(new { status = false, fulOrderID = FulOrder.fulOrderId, message = ex.InnerException.Message }); } else { return(new { status = false, fulOrderID = FulOrder.fulOrderId, message = ex.Message }); } throw ex; } }
public Object PalletizeFulOrder(string trackingNumber, int palletId) { try { Guid TrackingNumber; if (!Guid.TryParse(trackingNumber, out TrackingNumber)) { return(new { status = false, message = _iconfiguration["INVALID_TRACKINGFORMAT"] }); } /*get FulOrder information based on given tracking number and palletId*/ Shipment shipmentObj = new Shipment(); shipmentObj = (from s in context.Shipment where s.TrackingNumber == TrackingNumber select s).FirstOrDefault(); if (shipmentObj == null) { return(new { status = false, message = _iconfiguration["TRACKINGNO_NOTFOUND"] }); } Pallet PalletObj = (from p in context.Pallet where p.PalletId == palletId select p).FirstOrDefault(); if (PalletObj == null) { return new { status = false, message = _iconfiguration["PALLETID_NOTFOUND"] } } ; int?CarrierServiceTypeId = (from cs in context.CarrierService where cs.CarrierServiceId == shipmentObj.CarrierServiceId && cs.CarrierId == shipmentObj.CarrierId select cs.CarrierServiceTypeId).FirstOrDefault(); if (PalletObj.CarrierId != shipmentObj.CarrierId || PalletObj.CarrierServiceTypeId != CarrierServiceTypeId) { return new { status = false, message = _iconfiguration["PALLET_SHIPMENT_CARRIER_NOT_MATCH"] } } ; if (shipmentObj.CarrierId == PalletObj.CarrierId && CarrierServiceTypeId != null && CarrierServiceTypeId == PalletObj.CarrierServiceTypeId) { FulOrder FulOrderObj = new FulOrder(); FulOrderObj = (from fo in context.FulOrder join fos in context.FulOrderStatus on fo.FulOrderStatusId equals fos.FulOrderStatusId where fo.FulOrderId == shipmentObj.FulOrderId && fos.Name == _iconfiguration["PACKAGED"] select fo).FirstOrDefault(); if (FulOrderObj == null) { return new { status = false, message = _iconfiguration["FULORDER_NOT_IN_PACKAGE"] } } ; FulOrderStatus FulOrderStatusObj = (from fos in context.FulOrderStatus where fos.Name.ToUpper() == _iconfiguration["PALLETIZED"] select fos).FirstOrDefault(); FulOrderObj.FulOrderStatusId = FulOrderStatusObj.FulOrderStatusId; FulOrderObj.PalletId = palletId; context.FulOrder.Update(FulOrderObj); context.SaveChanges(); Product ProductObj = new Product(); ProductObj = (from fi in context.FulItem join p in context.Product on fi.ProductId equals p.ProductId select p).FirstOrDefault(); ProductSKU productSKUObj = (from ps in context.ProductSKU where ps.ProductId == ProductObj.ProductId select ps).FirstOrDefault(); UpdateTrackingDTO response = new UpdateTrackingDTO(); response.fulOrderId = FulOrderObj.FulOrderId; response.fulOrderStatus = FulOrderStatusObj.Name; response.productName = ProductObj.Name; response.sku = productSKUObj.SKU; response.trackingNumber = shipmentObj.TrackingNumber.ToString(); return(new { status = true, data = response, message = string.Format(_iconfiguration["PALLETIZED_SUCCESS"], FulOrderObj.FulOrderId.ToString()) }); } return(new { status = false, message = _iconfiguration["ERROR_NOFULORDERPACKAGEFOUND"] }); } catch (Exception Ex) { LogServiceObj.LogException(Ex); MailServiceObj.SendMail(Ex.Message ?? "", (Ex.InnerException != null) ? Ex.InnerException.Message : "", Ex.StackTrace ?? ""); return(new { status = false, message = _iconfiguration["ERROR_CREATEPALLET"] }); } }
public object CreatePackage(int fulOrderId) { try { UpdateTrackingDTO response = new UpdateTrackingDTO(); FulOrder FulOrderObj = (from fo in context.FulOrder join fos in context.FulOrderStatus on fo.FulOrderStatusId equals fos.FulOrderStatusId where fo.FulOrderId == fulOrderId && fos.Name.ToUpper() == _iconfiguration["LABELCREATED"] select fo).FirstOrDefault(); if (FulOrderObj == null) { return new { status = false, message = _iconfiguration["FULORDER_NOT_LABELED"] } } ; FulOrderStatus FulOrderStatus = (from fos in context.FulOrderStatus where fos.Name.ToUpper() == _iconfiguration["PACKAGED"] select fos).FirstOrDefault(); Product productObj = (from fi in context.FulItem join p in context.Product on fi.ProductId equals p.ProductId where fi.FulOrderId == fulOrderId select p).FirstOrDefault(); ProductSKU productSKU = (from p in context.Product join ps in context.ProductSKU on p.ProductId equals ps.ProductId join pt in context.ProductSKUType on ps.SKUTypeId equals pt.ProductSKUTypeId where p.ProductId == productObj.ProductId && pt.Name.ToUpper() == _iconfiguration["SKU"] select ps).FirstOrDefault(); Shipment shipmentObj = (from s in context.Shipment where s.FulOrderId == fulOrderId select s).FirstOrDefault(); FulOrderObj.FulOrderStatusId = FulOrderStatus.FulOrderStatusId; context.FulOrder.Update(FulOrderObj); context.SaveChanges(); if (productObj != null && productSKU != null && shipmentObj != null) { response.fulOrderId = fulOrderId; response.fulOrderStatus = FulOrderStatus.Name; response.productName = productObj.Name; response.sku = productSKU.SKU; response.trackingNumber = shipmentObj.TrackingNumber.ToString(); } else if (productObj == null) { return(new { status = false, message = _iconfiguration["PRODUCTNOTFOUND"] }); } else if (productSKU == null) { return(new { status = false, message = _iconfiguration["PRODUCTSKUNOTFOUND"] }); } else if (shipmentObj == null) { return(new { status = false, message = _iconfiguration["SHIPMENTNOTFOUND"] }); } return(new { status = true, message = string.Format(_iconfiguration["PACKAGE_SUCCESS"], fulOrderId.ToString()), data = response }); } catch (Exception Ex) { LogServiceObj.LogException(Ex); MailServiceObj.SendMail(Ex.Message ?? "", (Ex.InnerException != null) ? Ex.InnerException.Message : "", Ex.StackTrace ?? ""); return(new { status = false, message = _iconfiguration["ERROR_PACKAGE"] }); } }
public object GenerateLabel(string UPC) { try { Product ProductObj = (from p in context.Product join ps in context.ProductSKU on p.ProductId equals ps.ProductId join pt in context.ProductSKUType on ps.SKUTypeId equals pt.ProductSKUTypeId where pt.Name.ToUpper() == _iconfiguration["SKU"] && p.UPC == UPC select p).FirstOrDefault(); Guid?RandomTrackingNumberStr = Guid.Empty; if (ProductObj != null) { bool GenerateShipment = false; string ProductSKU = (from psku in context.ProductSKU join pskutype in context.ProductSKUType on psku.SKUTypeId equals pskutype.ProductSKUTypeId where psku.ProductId == ProductObj.ProductId && pskutype.Name.ToUpper() == _iconfiguration["SKU"] select psku.SKU).FirstOrDefault(); FulOrder fulOrderObj = (from fi in context.FulItem join fo in context.FulOrder on fi.FulOrderId equals fo.FulOrderId join fs in context.FulOrderStatus on fo.FulOrderStatusId equals fs.FulOrderStatusId where fs.Name.ToUpper() == _iconfiguration["LABELCREATED"] && (fo.OnHold_FLG ?? false) == false && fi.ProductId == ProductObj.ProductId select fo).OrderBy(fo => fo.OrderId).FirstOrDefault(); if (fulOrderObj != null) { GenerateShipment = true; RandomTrackingNumberStr = (from s in context.Shipment where s.FulOrderId == fulOrderObj.FulOrderId select s.TrackingNumber).FirstOrDefault(); } else { fulOrderObj = (from fi in context.FulItem join fo in context.FulOrder on fi.FulOrderId equals fo.FulOrderId join fs in context.FulOrderStatus on fo.FulOrderStatusId equals fs.FulOrderStatusId where fs.Name.ToUpper() == _iconfiguration["PICKING"] && (fo.OnHold_FLG ?? false) == false && (fo.Error_FLG ?? false) == false && fi.ProductId == ProductObj.ProductId select fo).OrderBy(fo => fo.OrderId).FirstOrDefault(); } if (fulOrderObj == null) { return new { status = false, message = _iconfiguration["UPC_PICKED_NOTFOUND"] } } ; FulOrderStatus fulOrderStatusObj = (from fs in context.FulOrderStatus where fs.Name.ToUpper() == _iconfiguration["LABELCREATED"] select fs).FirstOrDefault(); Box BoxObj = (from b in context.Box where b.BoxId == ProductObj.BoxId select b).FirstOrDefault(); if (!GenerateShipment && fulOrderObj != null && ProductObj != null) { fulOrderObj.FulOrderStatusId = fulOrderStatusObj.FulOrderStatusId; RandomTrackingNumberStr = Guid.NewGuid(); /* Insertion of Shipment record */ Shipment ShipmentObj = new Shipment(); ShipmentObj.CarrierId = fulOrderObj.AssignedCarrierId ?? 0; ShipmentObj.CarrierServiceId = fulOrderObj.AssignedCarrierServiceId ?? 0; ShipmentObj.FulOrderId = fulOrderObj.FulOrderId; ShipmentObj.Height = (BoxObj != null) ? BoxObj.Height : 0; ShipmentObj.Length = (BoxObj != null) ? BoxObj.Length : 0; ShipmentObj.StatusUpdatedDT = DateTime.Now; ShipmentObj.Width = (BoxObj != null) ? BoxObj.Width : 0; ShipmentObj.Weight = ProductObj.Weight; ShipmentObj.TrackingNumber = RandomTrackingNumberStr; ShipmentObj.ShippingLabel = null; ShipmentObj.ShipmentStatusId = (from ss in context.ShipmentStatus where ss.Name.ToUpper() == _iconfiguration["ACTIVE"] select ss.ShipmentStatusId).FirstOrDefault(); context.Shipment.Add(ShipmentObj); context.FulOrder.Update(fulOrderObj); context.SaveChanges(); } UpdateTrackingDTO TrackingDTOObj = new UpdateTrackingDTO(); TrackingDTOObj.fulOrderId = fulOrderObj.FulOrderId; TrackingDTOObj.productName = ProductObj.Name; TrackingDTOObj.fulOrderStatus = fulOrderStatusObj.Name; TrackingDTOObj.sku = ProductSKU; TrackingDTOObj.trackingNumber = (RandomTrackingNumberStr != null) ? RandomTrackingNumberStr.ToString() : ""; return(new { status = true, data = TrackingDTOObj }); } else { return(new { status = false, message = _iconfiguration["UPC_NOT_FOUND"] }); } } catch (Exception Ex) { LogServiceObj.LogException(Ex); MailServiceObj.SendMail(Ex.Message ?? "", (Ex.InnerException != null) ? Ex.InnerException.Message : "", Ex.StackTrace ?? ""); return(new { status = false, message = _iconfiguration["UNHANDLEDEXCEPTION"] }); } }
private bool SaveFulfillOrders(string OrderNumber, List <OrderLine> OrderLineList) { try { /*Pending Part: Need to check whether inventory is available or not*/ List <FulOrder> FulOrderList = new List <FulOrder>(); List <FulItem> FulItemList = new List <FulItem>(); List <ProductInventory> ProductInvListUpdate = new List <ProductInventory>(); List <Order> OrderListUpdate = new List <Order>(); Order OrderObj = (from o in context.Order where o.OrderNumber == OrderNumber select o).FirstOrDefault(); bool isPrime = OrderObj.IsPrime_FLG; string CarrierDescription = OrderObj.CarrierDescription; DateTime ShipByDT = OrderObj.ShipByDT; int FulOrderStatusId = context.FulOrderStatus.Where(StatusRec => StatusRec.Name.ToUpper() == _iconfiguration["ENTERED"]).Select(StatusRec => StatusRec.FulOrderStatusId).FirstOrDefault(); foreach (OrderLine OrdrLineObj in OrderLineList) { ProductInventory ProductInvObj = context.Product.Join(context.ProductVersion, p => p.ProductId, PI => PI.ProductId, (p, PI) => PI) .Join(context.ProductInventory, pi => pi.ProductVersionId, pv => pv.ProductVersionId, (pi, pv) => new { pi, pv }) .Where(pv => pv.pi.ProductId == OrdrLineObj.ProductId).Select(x => x.pv).FirstOrDefault(); if (ProductInvObj != null && ProductInvObj.Quantity >= OrdrLineObj.Quantity) { Product productObj = context.Product.Where(P => P.ProductId == OrdrLineObj.ProductId).Select(p => p).FirstOrDefault(); if (productObj != null && productObj.ShipsAlone_FLG) { int iteration = 0; while (iteration < OrdrLineObj.Quantity) { iteration++; FulOrder FulOrderObj = new FulOrder(); FulOrderObj.OrderId = OrdrLineObj.OrderId; FulOrderObj.FulOrderStatusId = FulOrderStatusId; FulOrderObj.OnHold_FLG = false; FulOrderObj.Error_FLG = false; FulOrderObj.IsPrime_FLG = isPrime; FulOrderObj.CarrierDescription = CarrierDescription; FulOrderObj.ShipByDT = ShipByDT; FulOrderList.Add(FulOrderObj); } } else if (productObj != null && !productObj.ShipsAlone_FLG) { FulOrder FulOrderObj = new FulOrder(); FulOrderObj.OrderId = OrdrLineObj.OrderId; FulOrderObj.FulOrderStatusId = FulOrderStatusId; FulOrderObj.OnHold_FLG = false; FulOrderObj.Error_FLG = false; FulOrderObj.IsPrime_FLG = isPrime; FulOrderObj.CarrierDescription = CarrierDescription; FulOrderObj.ShipByDT = ShipByDT; FulOrderList.Add(FulOrderObj); } } else if (ProductInvObj != null && ProductInvObj.Quantity < OrdrLineObj.Quantity) { MailServiceObj.SendMail(string.Format(_iconfiguration["ProductInventoryShortage"], OrdrLineObj.SKU, OrderNumber ?? "", OrdrLineObj.Quantity.ToString(), ProductInvObj.Quantity.ToString(), (OrdrLineObj.Quantity - ProductInvObj.Quantity).ToString())); } } context.FulOrder.AddRange(FulOrderList); try { context.SaveChanges(); } catch (Exception Ex) { throw Ex; } bool OrderLineSaveResponse = false; if (FulOrderList.Count > 0) { OrderLineSaveResponse = SaveFulItems(OrderLineList, FulOrderList); } return(OrderLineSaveResponse); } catch (Exception ex) { throw ex; } }