public IActionResult Submit3(ShipmentAddress form) { if (!ModelState.IsValid) { goto Error; } var validationResult = service.ValidateShippingForm(form); if (validationResult != ShippingFormValidationResult.Valid) { goto Error; } bool success = service.SaveShippingInfo(form); if (!success) { ModelState.AddModelError("", "Problem occurred while " + "saving your information, please try again"); goto Error; } return(RedirectToAction("Index", "BillingForm")); Error: Response.Cookies.Append("shipping_error", "1"); return(RedirectToAction("Index", "ShippingForm", form)); }
private bool validate(ShipmentAddress form) { if (!ModelState.IsValid) { return(false); } var validationResult = service.ValidateShippingForm(form); return(validationResult == ShippingFormValidationResult.Valid); }
public IActionResult Submit6(ShipmentAddress form) { if (!validate(form)) { return(shippingFormError()); } bool success = service.SaveShippingInfo(form); if (!success) { reportSaveError(); return(shippingFormError(form)); } return(RedirectToAction("Index", "BillingForm")); }
/// <summary> /// 货物fed物流信息 /// </summary> /// <param name="orderId"></param> /// <returns></returns> public ShipmentEx GetShipmentByOrder(long orderId) { ShipmentEx shipEx = null; try { //shipEx = new ShipmentEx(); Shipment ship = context.Shipment.FirstOrDefault(x => x.OrderId == orderId); if (ship != null) { ShipmentAddress orgAddress = context.ShipmentAddress.FirstOrDefault(x => (x.ShipmentId == ship.Id) && (x.State == "Origin")); ShipmentAddress destAddress = context.ShipmentAddress.FirstOrDefault(x => (x.ShipmentId == ship.Id) && (x.State == "Dest")); List <ShipmentPackage> pkgList = context.ShipmentPackage.Where(x => x.ShipmentId == ship.Id).ToList(); Address orgAddressEx = new Address(orgAddress.Line1, orgAddress.Line2, orgAddress.Line3, orgAddress.City, "", orgAddress.PostalCode, orgAddress.CountryCode); orgAddressEx.CountryName = orgAddress.CountryName; Address destAddressEx = new Address(destAddress.Line1, destAddress.Line2, destAddress.Line3, destAddress.City, "", destAddress.PostalCode, destAddress.CountryCode); destAddressEx.CountryName = destAddress.CountryName; List <Package> pkgExList = new List <Package>(); Package package = null; string packType = string.Empty; foreach (ShipmentPackage item in pkgList) { WeightUnit wUnit = item.ShipWeightUnit == "KG" ? WeightUnit.KG : WeightUnit.LB; LinearUnit lUnit = item.ShipLinearUnit == "CM" ? LinearUnit.CM : LinearUnit.IN; package = new Package(item.Length, item.Width, item.Height, item.Weight, item.InsuredValue, wUnit, lUnit); dicList.TryGetValue(item.PackageType, out packType); dicList.TryGetValue(item.PackageType, out packType); package.PackageType = packType; pkgExList.Add(package); } Rate rate = new Rate(ship.RateProvider, ship.RateProviderCode, ship.RateName, ship.TotalCharges, ship.GurDeliveryDate); shipEx = new ShipmentEx(orgAddressEx, destAddressEx, pkgExList); shipEx.RateValue = rate; } } catch { } return(shipEx); }
public List <ShipmentAddress> GetShipmentAddresses() { string serviceODataURL = ConfigurationManager.AppSettings["NAVODATAUrl"]; string WS_User = ConfigurationManager.AppSettings["NAV_User"]; string WS_Pwd = ConfigurationManager.AppSettings["NAV_Pwd"]; string WS_Domain = ConfigurationManager.AppSettings["NAV_Domain"]; string Company = ConfigurationManager.AppSettings["Company"]; string serviceUri = string.Format(serviceODataURL + "/Company('{0}')", Company); List <ShipmentAddress> indListB2B = new List <ShipmentAddress>(); try { DataServiceContext context = new DataServiceContext(new Uri(serviceUri)); NAV_ODATA.NAV theNav = new NAV_ODATA.NAV(new Uri(serviceUri)); theNav.Credentials = new System.Net.NetworkCredential(WS_User, WS_Pwd, WS_Domain); DataServiceQuery <NAV_ODATA.B2BShipAddress> q = theNav.CreateQuery <NAV_ODATA.B2BShipAddress>("B2BShipAddress"); List <NAV_ODATA.B2BShipAddress> addrList = q.Execute().ToList(); foreach (NAV_ODATA.B2BShipAddress addr in addrList) { ShipmentAddress ind = new ShipmentAddress(); ind.CustomerNo = addr.Customer_No; ind.Code = addr.Code; ind.Name = addr.Name; ind.Address = addr.Address; ind.City = addr.City; ind.County = addr.County; ind.Country = addr.Country_Region_Code; ind.Default = addr.Default_Shipment; indListB2B.Add(ind); } } catch (Exception) { } return(indListB2B); }
public IActionResult Submit5(ShipmentAddress form) { // Our common error handling code that saves the cookie // and redirects back to the entry form for // shipping information. IActionResult error() { Response.Cookies.Append("shipping_error", "1"); return(RedirectToAction("Index", "ShippingForm", form)); } // check if the model state is valid if (!ModelState.IsValid) { return(error()); } // validate the form with server side validation logic. var validationResult = service.ValidateShippingForm(form); // is the validation successful? if (validationResult != ShippingFormValidationResult.Valid) { return(error()); } // save shipping information bool success = service.SaveShippingInfo(form); if (!success) { // failed to save. report the error to the user. ModelState.AddModelError("", "Problem occurred while " + "saving your information, please try again"); return(error()); } // go to the billing form return(RedirectToAction("Index", "BillingForm")); }
private ShipmentAddress[] CreateAddresses() { var originAddress = new ShipmentAddress() { Type = new ResponseStatus() { Description = "Shipper Address" }, Address = CreateOriginAddress() }; var destinationAddress = new ShipmentAddress() { Type = new ResponseStatus() { Description = "ShipTo Address" }, Address = CreateDestinationAddress() }; return(new ShipmentAddress[2] { originAddress, destinationAddress }); }
private IActionResult shippingFormError(ShipmentAddress form = null) { Response.Cookies.Append("shipping_error", "1"); return(RedirectToAction("Index", "ShippingForm", form)); }
/// <summary> /// 保存物流信息 /// </summary> /// <param name="shipment"></param> /// <param name="orderId"></param> public void SaveShipmentEx(ShipmentEx shipment, long orderId) { try { Shipment ship = new Shipment(); Address oriAddress = shipment.OriginAddress; Address destAddress = shipment.DestinationAddress; Rate rate = null; if (shipment.RateValue != null) { rate = shipment.RateValue; } else { rate = new Rate(); rate.GuaranteedDelivery = DateTime.Now; } ship.Id = GenerateNumber(); ship.OrderId = orderId; ship.PackageCount = shipment.PackageCount; ship.TotalPackageWeight = shipment.TotalPackageWeight; if (!string.IsNullOrWhiteSpace(rate.Name)) { ship.RateName = rate.Name.Trim(); } else { ship.RateName = null; } ship.GurDeliveryDate = rate.GuaranteedDelivery == null ? DateTime.Now : Convert.ToDateTime(rate.GuaranteedDelivery); ship.RateProvider = rate.Provider; ship.RateProviderCode = rate.ProviderCode; ship.TotalCharges = rate.TotalCharges; context.Shipment.Add(ship); ShipmentAddress orgAddress = new ShipmentAddress(); orgAddress.ShipmentId = ship.Id; orgAddress.City = oriAddress.City; orgAddress.CountryCode = oriAddress.CountryCode; orgAddress.CountryName = oriAddress.CountryName; orgAddress.Line1 = oriAddress.Line1; orgAddress.Line2 = oriAddress.Line2; orgAddress.Line3 = oriAddress.Line3; orgAddress.State = "Origin"; orgAddress.PostalCode = oriAddress.PostalCode; context.ShipmentAddress.Add(orgAddress); ShipmentAddress DAddress = new ShipmentAddress(); DAddress.ShipmentId = ship.Id; DAddress.City = destAddress.City; DAddress.CountryCode = destAddress.CountryCode; DAddress.CountryName = destAddress.CountryName; DAddress.Line1 = destAddress.Line1; DAddress.Line2 = destAddress.Line2; DAddress.Line3 = destAddress.Line3; DAddress.State = "Dest"; DAddress.PostalCode = destAddress.PostalCode; context.ShipmentAddress.Add(DAddress); //包裹 List <Package> packages = shipment.Packages; ShipmentPackage shipPgk = null; foreach (Package item in packages) { shipPgk = new ShipmentPackage(); shipPgk.ShipmentId = ship.Id; shipPgk.Currency = item.Currency; shipPgk.Height = item.Height; shipPgk.InsuredValue = item.InsuredValue; shipPgk.Length = item.Length; shipPgk.PackageType = item.PackageType; shipPgk.ShipLinearUnit = item.ShipLinearUnit == LinearUnit.CM ? "CM" : "IN"; shipPgk.ShipWeightUnit = item.ShipWeightUnit == WeightUnit.KG ? "KG" : "LB"; shipPgk.Weight = item.Weight; shipPgk.Width = item.Width; context.ShipmentPackage.Add(shipPgk); } context.SaveChanges(); } catch (DbEntityValidationException ex) { } }