public OutcomesViewModel() { OutSrvc = new OutcomeService(); loadOutcomes(); loadTotal(); CurrentOutcome = new MoneyDTO(); CurrentOutcome.Duration = 1; addCommand = new CommandManager(Add); }
public IncomesViewModel() { InSrvc = new IncomeService(); loadIncomes(); loadTotal(); CurrentIncome = new MoneyDTO(); CurrentIncome.Duration = 1; addCommand = new CommandManager(Add); }
public List <MoneyDTO> convertToObject(DataTable input) { //hàm convert từ DataTable sang list<object> List <MoneyDTO> output = new List <MoneyDTO>(); foreach (DataRow dr in input.Rows) { MoneyDTO obj = new MoneyDTO(); obj.MoneyID = Convert.ToInt32(dr["MoneyID"]); obj.MoneyValue = Convert.ToInt32(dr["MoneyValue"]); output.Add(obj); } return(output); }
public List <MoneyDTO> getMoney() { try { List <MoneyDTO> lstmoney = new List <MoneyDTO>(); string queryString = "SELECT * FROM Money"; SqlCommand cmd = new SqlCommand(queryString, DataConnection.connect); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { MoneyDTO amoney = new MoneyDTO(int.Parse(dr["MoneyID"].ToString()), long.Parse(dr["MoneyValue"].ToString())); lstmoney.Add(amoney); } dr.Close(); DataConnection.closeConnection(); return(lstmoney); } catch (Exception) { DataConnection.closeConnection(); return(null); } }
public ShippingRateResult GetShippingRate( string shippingMethod, Cart cart, CommercePipelineExecutionContext context, GetSellableItemCommand getSellableItemCommand ) { if (cart == null || !cart.HasComponent <PhysicalFulfillmentComponent>() || string.IsNullOrEmpty(shippingMethod) ) { return(null); } context.Logger.LogInformation($"{this.GetType().Name} - Begin GetShippingRate", Array.Empty <object>()); var policy = context.CommerceContext.GetPolicy <ShipEnginePolicy>(); var component = cart.GetComponent <PhysicalFulfillmentComponent>(); var shippingParty = component?.ShippingParty; var countryCode = Get2DigitCountryCode(shippingParty.CountryCode); Carrier carrier = policy.DefaultCarrier; var shipment = new AddressValidatingShipment() { Confirmation = policy.ShipDeliveryConfirmation, InsuranceProvider = policy.ShipInsuranceProvider, CarrierId = carrier.CarrierId, ServiceCode = carrier.Services.FirstOrDefault().ServiceCode, // "usps_priority_mail" edvin change Packages = new List <ShipmentPackage>(), ShipFrom = new AddressDTO( name: String.IsNullOrWhiteSpace(policy.ShipperName) ? context.CommerceContext.CurrentShopName() : policy.ShipperName, phone: policy.ShipperPhone, companyName: String.IsNullOrWhiteSpace(policy.ShipperCompany) ? context.CommerceContext.CurrentShopName() : policy.ShipperCompany, addressLine1: policy.ShipperAddressLine1, addressLine2: policy.ShipperAddressLine2, addressLine3: policy.ShipperAddressLine3, cityLocality: policy.ShipperCityLocality, stateProvince: policy.ShipperStateProvince, postalCode: policy.ShipperPostalCode, countryCode: policy.ShipperCountryCode ), ShipTo = new AddressDTO( name: shippingParty.AddressName, phone: shippingParty.PhoneNumber, companyName: shippingParty.Name, addressLine1: shippingParty.Address1, addressLine2: shippingParty.Address2, addressLine3: string.Empty, cityLocality: shippingParty.City, stateProvince: Get2DigitStateCode(countryCode, shippingParty.State), postalCode: shippingParty.ZipPostalCode, countryCode: countryCode ), }; // Address validation handled in ResolveAddressBlock shipment.ValidateAddress = AddressValidatingShipment.ValidateAddressEnum.NoValidation; shipment.WarehouseId = policy.GetWearhouseId(shipment.ShipTo); // Get sellableItem weight and dimensions // var shipmentPackages = new List <ShipmentPackage>(); var dim = new Dimensions(Dimensions.UnitEnum.Inch); MoneyDTO insuredValue = null; foreach (var cartLineItem in cart.Lines) { var sellableItem = getSellableItemCommand.Process(context.CommerceContext, cartLineItem.ItemId, filterVariations: true).Result; // get specific weight value // var itemSpec = sellableItem.GetComponent <ItemSpecificationsComponent>(); if (itemSpec == null || String.IsNullOrWhiteSpace(itemSpec.DimensionsUnitOfMeasure)) { var errorMessage = string.Format("{0} - no Item Specification (Weight, Dimension) exists for SellableItem {1}, productId {2}", this.GetType().Name, sellableItem.Name, sellableItem.ProductId); context.CommerceContext.AddMessage( context.GetPolicy <KnownResultCodes>().Error, "InvalidOrMissingPropertyValue", new object[] { errorMessage }) ; context.Logger.LogError(errorMessage); return(new ShippingRateResult() { ErrorMessage = errorMessage, IsErrorAddedToCommerceContext = true }); } var globalPolicy = context.GetPolicy <GlobalPhysicalFulfillmentPolicy>(); // Get the unit for dimension and weight as required by ShipEngine // // Handle edge case of Feet and Meters by converting them to inches and centimeters switch (itemSpec.DimensionsUnitOfMeasure.ToLower().Substring(0, 2)) { case "fe": // feet case "fo": // foot itemSpec.Length *= 12; itemSpec.Width *= 12; itemSpec.Height *= 12; itemSpec.DimensionsUnitOfMeasure = "Inch"; break; case "me": // Meters itemSpec.Length *= 100; itemSpec.Width *= 100; itemSpec.Height *= 100; itemSpec.DimensionsUnitOfMeasure = "Centimeter"; break; case "mi": // Millimeter itemSpec.Length = Math.Max(itemSpec.Length / 10, 1); itemSpec.Width = Math.Max(itemSpec.Width / 10, 1); itemSpec.Height = Math.Max(itemSpec.Height / 10, 1); itemSpec.DimensionsUnitOfMeasure = "Centimeter"; break; } var dimensionUnit = policy.StringToDimensionUnit( string.IsNullOrEmpty(itemSpec.DimensionsUnitOfMeasure) ? globalPolicy.MeasurementUnits : itemSpec.DimensionsUnitOfMeasure ); var weightUnit = policy.StringToWeightUnit( string.IsNullOrEmpty(itemSpec.WeightUnitOfMeasure) ? globalPolicy.WeightUnits : itemSpec.WeightUnitOfMeasure ); if (policy.ShipInsuranceProvider != AddressValidatingShipment.InsuranceProviderEnum.None) { insuredValue = policy.GetInsuredAmount(sellableItem, context); } if (!isSellableItemWeightWithInPolicyLimit(itemSpec, policy, globalPolicy)) { context.Logger.LogError( string.Format("{0} - Item weight ({1}) Exceeding golbal policy MaximumShippingWeigh ({2}) for SellableItem {3}, productId {4}", this.GetType().Name, itemSpec.Weight, globalPolicy.MaxShippingWeight, sellableItem.Name, sellableItem.ProductId) ); } shipmentPackages.Add(new ShipmentPackage { Weight = new Weight(itemSpec.Weight, weightUnit), Dimensions = new Dimensions(dimensionUnit, itemSpec.Length, itemSpec.Width, itemSpec.Height), InsuredValue = insuredValue, LabelMessages = null }); } //Func<Rate, bool> shippingMethodMatchDelegate = rate => rate.ServiceCode?.IndexOf(shippingMethod, StringComparison.InvariantCultureIgnoreCase) >= 0; MoneyDTO shipmentAmount = null; // Get shipping rate if the fullfilment center supports multi-package shipment // RatesApi shippingRate = new RatesApi(); if (carrier.HasMultiPackageSupportingServices ?? false) { shipment.Packages = shipmentPackages; var rateShipmentRequest = new RateShipmentRequest(shipment: shipment, rateOptions: new RateRequest(new List <string> { carrier.CarrierId })); rateShipmentRequest.Shipment.Confirmation = policy.GetShippingConfirmationMethod(); var shipmentResponse = shippingRate.RatesRateShipment(rateShipmentRequest, policy.ApiKey); shipmentAmount = GetShippingResponseRatesAsync(shipmentResponse, shippingMethod, context).Result; } // If multi-package shipment is not supported; then we will get rate for // each package and and calculate the total sum as shipping rate. // else { var currency = (MoneyDTO.CurrencyEnum)Enum.Parse(typeof(MoneyDTO.CurrencyEnum), context.CommerceContext.CurrentCurrency()); shipmentAmount = new MoneyDTO(currency, amount: 0); foreach (var package in shipmentPackages) { shipment.Packages.RemoveAll(s => true); shipment.Packages.Add(package); var rateShipmentRequest = new RateShipmentRequest(shipment: shipment, rateOptions: new RateRequest(new List <string> { carrier.CarrierId })); var shipmentRate = shippingRate.RatesRateShipment(rateShipmentRequest, policy.ApiKey); var amount = GetShippingResponseRatesAsync(shipmentRate, shippingMethod, context).Result; if (amount == null) { return(null); } shipmentAmount.Amount += amount.Amount; insuredValue.Amount += package.InsuredValue.Amount; } } context.Logger.LogInformation($"{this.GetType().Name} - End GetShippingRate", Array.Empty <object>()); return(new ShippingRateResult() { ShippingRate = shipmentAmount, InsuranceAmount = insuredValue }); }
/// <summary> /// /// </summary> /// <exception cref="ShipEngine.ApiClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="cost"></param> /// <param name="apiKey">API Key</param> /// <returns>Task of ApiResponse (MoneyDTO)</returns> public async System.Threading.Tasks.Task <ApiResponse <MoneyDTO> > InsuranceAddFundsAsyncWithHttpInfo(MoneyDTO cost, string apiKey) { // verify the required parameter 'cost' is set if (cost == null) { throw new ApiException(400, "Missing required parameter 'cost' when calling InsuranceApi->InsuranceAddFunds"); } // verify the required parameter 'apiKey' is set if (apiKey == null) { throw new ApiException(400, "Missing required parameter 'apiKey' when calling InsuranceApi->InsuranceAddFunds"); } var localVarPath = "/v1/insurance/shipsurance/add_funds"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <String, String> >(); var localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json", "text/json" }; String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json", "text/json" }; String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (apiKey != null) { localVarHeaderParams.Add("api-key", this.Configuration.ApiClient.ParameterToString(apiKey)); // header parameter } if (cost != null && cost.GetType() != typeof(byte[])) { localVarPostBody = this.Configuration.ApiClient.Serialize(cost); // http body (model) parameter } else { localVarPostBody = cost; // byte array } // authentication (api-key) required if (!String.IsNullOrEmpty(this.Configuration.GetApiKeyWithPrefix("api-key"))) { localVarHeaderParams["api-key"] = this.Configuration.GetApiKeyWithPrefix("api-key"); } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath, Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("InsuranceAddFunds", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <MoneyDTO>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (MoneyDTO)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(MoneyDTO)))); }
/// <summary> /// /// </summary> /// <exception cref="ShipEngine.ApiClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="cost"></param> /// <param name="apiKey">API Key</param> /// <returns>Task of MoneyDTO</returns> public async System.Threading.Tasks.Task <MoneyDTO> InsuranceAddFundsAsync(MoneyDTO cost, string apiKey) { ApiResponse <MoneyDTO> localVarResponse = await InsuranceAddFundsAsyncWithHttpInfo(cost, apiKey); return(localVarResponse.Data); }
/// <summary> /// /// </summary> /// <exception cref="ShipEngine.ApiClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="cost"></param> /// <param name="apiKey">API Key</param> /// <returns>MoneyDTO</returns> public MoneyDTO InsuranceAddFunds(MoneyDTO cost, string apiKey) { ApiResponse <MoneyDTO> localVarResponse = InsuranceAddFundsWithHttpInfo(cost, apiKey); return(localVarResponse.Data); }