/// <summary> /// This will consolidate the products in a single list for /// lawnmover, phonecase and tshirt /// </summary> /// <param name="Currency"></param> /// <returns></returns> public List <Product> GetAll(Currency?Currency) { double newChangePrice = 1; ps = new List <Product>(); if (Currency.HasValue) { switch (Currency.Value) { case Models.Currency.Dollars: newChangePrice = 0.76; break; case Models.Currency.Euros: newChangePrice = 0.67; break; default: break; } } GetProducts(_lawnmowerRepository.GetAll(), ProductType.Lawnmover, newChangePrice); GetProducts(_phoneCaseRepository.GetAll(), ProductType.PhoneCase, newChangePrice); GetProducts(_tShirtRepository.GetAll(), ProductType.TShirt, newChangePrice); // Default sorting by name return(ps.OrderBy(x => x.Type).ToList()); }
private InvoiceOptions CreateInvoiceOptions(InvoiceKind kind, long clientId, DateTime issuedAt, DateTime?dueAt = null, Currency?currency = null, string subject = null, string notes = null, string number = null, long[] projectIds = null, List <InvoiceItem> lineItems = null) { var invoice = new InvoiceOptions() { Kind = kind, ClientId = clientId, IssuedAt = issuedAt, DueAt = dueAt, Currency = currency, Subject = subject, Notes = notes, Number = number, }; if (projectIds != null) { invoice.ProjectsToInvoice = string.Join(",", projectIds.Select(id => id.ToString())); } invoice.SetInvoiceItems(lineItems); return(invoice); }
public JsonResult GetAllProducts(Currency?currency) { ProductDataConsolidator productDataConsolidator = new ProductDataConsolidator(); var products = productDataConsolidator.GetAll(currency); return(Json(new { Success = true, products = JsonConvert.SerializeObject(products) }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Create a new invoice on the authenticated account. Makes both a POST and a GET request to the Invoices resource. /// </summary> /// <param name="kind">The kind of invoice to create</param> /// <param name="clientId">The client the new invoice is for</param> /// <param name="issuedAt">The date the invoice should be issued</param> /// <param name="dueAt">The date the invoice should be due</param> /// <param name="currency">The currency of the invoice</param> /// <param name="subject">The invoice subject</param> /// <param name="notes">Notes to include on the invoice</param> /// <param name="number">The number for the invoice</param> /// <param name="projectIds">The IDs of projects to include in the invoice (useless for FreeForm invoices)</param> /// <param name="lineItems">A collection of line items for the invoice (only for FreeForm invoices)</param> public Invoice CreateInvoice(InvoiceKind kind, long clientId, DateTime issuedAt, DateTime?dueAt = null, Currency?currency = null, string subject = null, string notes = null, string number = null, long[] projectIds = null, List <InvoiceItem> lineItems = null) { var invoice = GetInvoiceOptions(kind, clientId, issuedAt, dueAt, currency, subject, notes, number, projectIds, lineItems); return(CreateInvoice(invoice)); }
/// <summary> /// Update a client on the authenticated account. Makes a PUT and a GET request to the Clients resource. /// </summary> /// <param name="clientId">The ID of the client to update</param> /// <param name="name">The updated name</param> /// <param name="currency">The updated currency</param> /// <param name="details">The updated details</param> /// <param name="highriseId">The updated Highrise ID</param> /// <param name="active">The updated state</param> public Task <Client> UpdateClientAsync(long clientId, string name = null, Currency?currency = null, bool?active = null, string details = null, long?highriseId = null) { var options = GetClientOptions(name, currency, active, details, highriseId); return(UpdateClientAsync(clientId, options)); }
private async Task UpdateCoinsAsync(ICoinBuilder builder) { this.Logger.LogInformation(message: "Updating All CoinInfos"); IReadOnlyCollection <ICoinInfo>[] allCoinInfos = await Task.WhenAll(this._coinClients.Select(this.GetCoinInfoAsync)); var cryptoInfos = allCoinInfos.SelectMany(selector: ci => ci) .GroupBy(keySelector: c => c.Symbol) .Select(selector: c => new { Symbol = c.Key, Coins = c.ToArray() }); foreach (var cryptoInfo in cryptoInfos) { ICoinInfo name = cryptoInfo.Coins[0]; Currency?currency = builder.Get(symbol: cryptoInfo.Symbol, name: name.Name); if (currency != null) { foreach (ICoinInfo info in cryptoInfo.Coins) { currency.AddDetails(info); } } } }
private bool GetCurrencies(string input, [NotNullWhen(returnValue: true)] out Currency?primaryCurrency, out Currency?secondaryCurrency) { primaryCurrency = null; secondaryCurrency = null; int countSeparators = input.Count(predicate: c => this._separators.Contains(c)); if (countSeparators > 1) { return(false); } if (countSeparators == 0) { primaryCurrency = this._currencyManager.Get(input); } else { string first = input.Substring(startIndex: 0, input.IndexOfAny(this._separators)); string second = input.Substring(input.IndexOfAny(this._separators) + 1); primaryCurrency = this._currencyManager.Get(first); secondaryCurrency = this._currencyManager.Get(second); } return(primaryCurrency != null); }
/// <summary> /// Returns the cheapest non-stop tickets, as well as tickets with 1 or 2 stops, for the selected route with departure/return date filters. /// </summary> /// <see href="https://support.travelpayouts.com/hc/en-us/articles/203956163-Travel-insights-with-Travelpayouts-Data-API#cheapest_tickets"/> /// <param name="originIata">The point of departure. The IATA city code or the country code. The length - from 2 to 3 symbols.</param> /// <param name="destinationIata">The point of destination. The IATA city code or the country code. The length - from 2 to 3 symbols.</param> /// <param name="departDate">The month of departure</param> /// <param name="returnDate"></param> /// <param name="currency">The currency of the airline ticket</param> /// <param name="page">The page number</param> public async Task <Dictionary <string, Dictionary <string, V1ApiTicket> > > GetCheapAsync( string originIata, string destinationIata = null, DateTime?departDate = null, DateTime?returnDate = null, Currency?currency = null, int?page = null ) { if (String.IsNullOrEmpty(originIata)) { throw new ArgumentException($"{nameof(originIata)} must be specified!", nameof(originIata)); } var query = GetQueryString(); query .AddValueIfNotNull(QueryParams.Currency, currency) .AddValueIfNotNull(QueryParams.Origin, originIata) .AddValueIfNotNull(QueryParams.Destination, destinationIata) .AddValueIfNotNull(QueryParams.DepartDate, departDate) .AddValueIfNotNull(QueryParams.ReturnDate, returnDate) .AddValueIfNotNull(QueryParams.Page, page) ; var apiResponse = await GetApiResponse <V1ApiResponse>(ApiEndPoints.Cheap, query); return(apiResponse.Data); }
/// <summary> /// Brings back the prices for the directions between the nearest to the target cities. /// </summary> /// <see href="https://support.travelpayouts.com/hc/en-us/articles/203956163#the_prices_for_the_alternative_directions"/> /// <param name="currency">The currency of the airline ticket</param> /// <param name="originIata">The point of departure. The IATA city code or the country code. The length - from 2 to 3 symbols.</param> /// <param name="destinationIata">The point of destination. The IATA city code or the country code. The length - from 2 to 3 symbols.</param> /// <param name="showToAffiliates">False - all the prices, true - just the prices, found using the partner marker (recommended). </param> /// <param name="departDate">The month of departure</param> /// <param name="returnDate"></param> /// <param name="distance"></param> /// <param name="limit"></param> /// <param name="flexibility"></param> /// <returns></returns> public async Task <DetailDataResponse> GetNearestPlacesMatrixAsync( Currency?currency = null, string originIata = null, string destinationIata = null, bool?showToAffiliates = null, DateTime?departDate = null, DateTime?returnDate = null, int?distance = null, int?limit = null, int?flexibility = null ) { var query = GetQueryString(); query .AddValueIfNotNull(QueryParams.Currency, currency) .AddValueIfNotNull(QueryParams.Origin, originIata) .AddValueIfNotNull(QueryParams.Destination, destinationIata) .AddValueIfNotNull(QueryParams.ShowToAffiliates, showToAffiliates) .AddValueIfNotNull(QueryParams.DepartDate, departDate) .AddValueIfNotNull(QueryParams.ReturnDate, returnDate) .AddValueIfNotNull(QueryParams.Distance, distance) .AddValueIfNotNull(QueryParams.Limit, limit) .AddValueIfNotNull(QueryParams.Flexibilty, flexibility) ; var apiResponse = await GetApiResponse <ApiDetailResponse>(ApiEndPoints.NearestPlacesMatrix, query); return(apiResponse.Data); }
private SearchCriteria CreateCriteriaMethod() { var name = NameTextBox.Text.Trim(); var owner = TransactionOwnerComboBox.SelectedItem as User; Currency?c = null; Currency?currency = CurrencyComboBox.SelectedItem == null ? c :(Currency)CurrencyComboBox.SelectedItem; var reason = ReasonComboBox.SelectedItem as TransactionReason; TransactionType?t = null; TransactionType?type = TypeComboBox.SelectedItem == null ? t :(TransactionType)TypeComboBox.SelectedItem; //DateTime? dateFrom = DateFromTimePicker.Value == DateTime.Now ? null : DateFromTimePicker.Value; SearchCriteria criteria = new SearchCriteria { Name = name, Amount = AmountNumericUpDown.Value, TransactionOwner = owner, Currency = currency, // DateFrom = dateFrom, // DateTo = dateTo Reason = reason, TransactionType = type, }; return(criteria); }
public async Task <Invoice> AddCharge(Charge charge, User user) { Currency?chargeCurrency = charge?.GetCurrency(); int month = 0; int year = 0; if (!chargeCurrency.HasValue) { throw new InvalidEntityException(charge); } //Try to get month and year from charge event if (charge.Event != null && charge.Event.Date != default(DateTime)) { month = charge.Event.Date.Month; year = charge.Event.Date.Year; } Invoice foundInvoice = await _invoiceRepository.FindAsync(x => x.User.Id == user.Id && x.Month == month && x.Year == year && x.Currency == chargeCurrency); //If no invoice exists for this user/month/year combination //create a new one if (foundInvoice == null) { Invoice newInvoice = new Invoice( month, year, chargeCurrency.Value, user ); newInvoice.AddCharge(charge); if (newInvoice.IsValid()) { return(_invoiceRepository.Insert(newInvoice)); } else { throw new InvalidEntityException(newInvoice); } } else { //If invoice was found, add charge foundInvoice.AddCharge(charge); if (foundInvoice.IsValid()) { return(_invoiceRepository.Update(foundInvoice)); } else { throw new InvalidEntityException(foundInvoice); } } }
public static Money New(decimal?value, Currency?currency) { return(new Money { Value = value, Currency = currency }); }
/// <summary> /// Create a new invoice on the authenticated account. Makes both a POST and a GET request to the Invoices resource. /// </summary> /// <param name="kind">The kind of invoice to create</param> /// <param name="clientId">The client the new invoice is for</param> /// <param name="issuedAt">The date the invoice should be issued</param> /// <param name="dueAt">The date the invoice should be due</param> /// <param name="currency">The currency of the invoice</param> /// <param name="subject">The invoice subject</param> /// <param name="notes">Notes to include on the invoice</param> /// <param name="number">The number for the invoice</param> /// <param name="projectIds">The IDs of projects to include in the invoice (useless for FreeForm invoices)</param> /// <param name="lineItems">A collection of line items for the invoice (only for FreeForm invoices)</param> public async Task <Invoice> CreateInvoiceAsync(InvoiceKind kind, long clientId, DateTime issuedAt, DateTime?dueAt = null, Currency?currency = null, string subject = null, string notes = null, string number = null, long[] projectIds = null, List <InvoiceItem> lineItems = null, CancellationToken cancellationToken = default(CancellationToken)) { return(await CreateInvoiceAsync(CreateInvoiceOptions(kind, clientId, issuedAt, dueAt, currency, subject, notes, number, projectIds, lineItems), cancellationToken)); }
public static Boolean TryParse(String s, out Money money) { money = Zero; if (s == null) { return(false); } s = s.Trim(); var isNegative = s.StartsWith("(") && s.EndsWith(")"); s = s.Replace("(", "").Replace(")", ""); if (s == String.Empty) { return(false); } Currency?currency = null; Currency currencyValue; // Check for currency symbol (e.g. $, £) if (!Currency.TryParse(s.Substring(0, 1), out currencyValue)) { // Check for currency ISO code (e.g. USD, GBP) if (s.Length > 2 && Currency.TryParse(s.Substring(0, 3), out currencyValue)) { s = s.Substring(3); currency = currencyValue; } } else { s = s.Substring(1); currency = currencyValue; } Decimal value; if (!Decimal.TryParse(s, out value)) { return(false); } if (isNegative) { value = value * (decimal) - 1; } money = currency != null ? new Money(value, currency.Value) : new Money(value); return(true); }
public InterpretedCoinInfo(Currency currency, MarketManager marketManager, Currency?usd, Currency?eth, Currency?btc) { this.Id = currency.Symbol; this.Symbol = currency.Symbol; this.Name = currency.Name; this.PriceUsd = GetPriceFromMarkets(currency: currency, marketManager: marketManager, quoteCurrency: usd); this.PriceEth = GetPriceFromMarkets(currency: currency, marketManager: marketManager, quoteCurrency: eth); this.PriceBtc = GetPriceFromMarkets(currency: currency, marketManager: marketManager, quoteCurrency: btc); }
/// <summary> /// Get current balance /// </summary> /// <param name="currency">Currency in which to get balance</param> /// <returns>Balance information</returns> public IBalance GetBalance(Currency?currency = null) { return (Run("getUserBalance") .WithContitionParameter(currency != null, "currency", (currency == null) ? null : currency.Value.ToString()) .Execute() .To <ResponseImpl <IBalance, BalanceImpl> >(CheckForError) .result); }
//private readonly IConfiguration _configuration; //public static CultureServiceUser(IConfiguration configuration){ // _configuration = configuration; //} public static Currency FindCurrency(Currency?default_price_unit) { Currency currency; if (Enum.TryParse(new RegionInfo(CultureInfo.CurrentCulture.Name).ISOCurrencySymbol, true, out currency)) { return(currency); } return(default_price_unit ?? Currency.USD);// TODO: Get from configuration }
private static ClientOptions GetClientOptions(string name, Currency?currency, bool?active, string details, long?highriseId) { return(new ClientOptions { Name = name, Active = active, Currency = currency, Details = details, HighriseId = highriseId }); }
/// <seealso cref="TryCreate(String, CurrencyTypes)"/> public static Currency Of(string code, CurrencyTypes types) { Currency?cy = TryCreate(code, types); if (!cy.HasValue) { throw new CurrencyNotFoundException(Format.Current(Strings_Money.CurrencyNotFound_UnknownCode, code)); } return(cy.Value); }
/// <summary> /// Creates a new client under the authenticated account. Makes both a POST and a GET request to the Clients resource. /// </summary> /// <param name="name">The name of the client</param> /// <param name="currency">The currency for the client</param> /// <param name="active">The status of the client</param> /// <param name="details">The details (address, phone, etc.) of the client</param> /// <param name="highriseId">The related Highrise ID of the client</param> public Task <Client> CreateClientAsync(string name, Currency?currency = null, bool active = true, string details = null, long?highriseId = null) { if (name == null) { throw new ArgumentNullException(nameof(name)); } var newClient = GetClientOptions(name, currency, active, details, highriseId); return(CreateClientAsync(newClient)); }
public static string ToString(Currency?value) { if (value == null || !value.HasValue) { return(null); } else { return(value.Value.GetEnumName()); } }
/// <summary> /// Update a client on the authenticated account. Makes a PUT and a GET request to the Clients resource. /// </summary> /// <param name="clientId">The ID of the client to update</param> /// <param name="name">The updated name</param> /// <param name="currency">The updated currency</param> /// <param name="details">The updated details</param> /// <param name="highriseId">The updated Highrise ID</param> /// <param name="active">The updated state</param> public Client UpdateClient(long clientId, string name = null, Currency?currency = null, bool?active = null, string details = null, long?highriseId = null) { var options = new ClientOptions() { Name = name, Details = details, HighriseId = highriseId, Currency = currency, Active = active }; return(UpdateClient(clientId, options)); }
public void GetAllProducts(Currency?currency) { string expected1 = ProductType.Lawnmover.ToString(); string expected2 = ProductType.PhoneCase.ToString(); string expected3 = ProductType.TShirt.ToString(); var productConsolidator = new ProductDataConsolidator(); var result = productConsolidator.GetAll(currency); Assert.IsNotNull(result); Assert.IsNotNull(result.Where(x => x.Type.Equals(expected1)).Select(x => x.Type).FirstOrDefault()); Assert.IsNotNull(result.Where(x => x.Type.Equals(expected2)).Select(x => x.Type).FirstOrDefault()); Assert.IsNotNull(result.Where(x => x.Type.Equals(expected3)).Select(x => x.Type).FirstOrDefault()); }
/// <summary> /// Initializes a new instance of the <see cref="Money" /> struct equal to <paramref name="value" />. /// </summary> /// <param name="value"> /// The value. /// </param> public Money(Decimal value) { checkValue(value); _units = (Int64)value; _decimalFraction = (Int32)Math.Round((value - _units) * FractionScale); if (_decimalFraction >= FractionScale) { _units += 1; _decimalFraction = _decimalFraction - (Int32)FractionScale; } _currency = Currency.FromCurrentCulture(); }
/// <summary> /// Invoice constructor /// </summary> /// <param name="id"></param> public Invoice(int id) { //initialize the ID of invoice _id = id; //initialize invoice information clientName = string.Empty; clientAddress = string.Empty; productName = string.Empty; productQuantity = 0; unitPrice = 0; shipDate = null; paymentDueDate = null; currency = null; }
/// <summary> /// Update current invoice with the values of the given invoice /// </summary> /// <param name="invoice"></param> public void Update(Invoice invoice) { _id = invoice.Id; clientName = invoice.ClientName; clientAddress = invoice.ClientAddress; productName = invoice.ProductName; productQuantity = invoice.ProdQuantity; shipDate = invoice.ShipDate; paymentDueDate = invoice.PaymentDueDate; unitPrice = invoice.UnitPrice; currency = invoice.Currency; }
internal ExchangeCurrencies(Currency?From, Currency[] To, DateTime?Date) { if (From == null) { throw new ArgumentNullException("Currency from is needed"); } else { this.From = From.Value; } this.To = To; this.Date = Date; }
private static bool TryParseCurrency(string currencyString, out Currency?currency) { if (currencyString == _nullCodeStr || currencyString == string.Empty) //eğer gelen string NULL ise zero için başarlı kabul edelim. { currency = Currency.NULL; return(true); } if (!Constants.CurrencyFromIsoCode.ContainsKey(currencyString)) { currency = Currency.NULL; return(false); } currency = Constants.CurrencyFromIsoCode[currencyString]; return(true); }
public static Boolean TryParse(String s, out Money money) { money = Zero; if (s == null) { return(false); } s = s.Trim(); if (s == String.Empty) { return(false); } Currency?currency = null; Currency currencyValue; // Check for currency symbol (e.g. $, £) if (!Currency.TryParse(s.Substring(0, 1), out currencyValue)) { // Check for currency ISO code (e.g. USD, GBP) if (s.Length > 2 && Currency.TryParse(s.Substring(0, 3), out currencyValue)) { s = s.Substring(3); currency = currencyValue; } } else { s = s.Substring(1); currency = currencyValue; } Decimal value; if (!Decimal.TryParse(s, out value)) { return(false); } money = currency != null ? new Money(value, currency.Value) : new Money(value); return(true); }
private ClientOptions CreateClientOptions(string name, Currency?currency = null, bool active = true, string details = null, long?highriseId = null) { if (name == null) { throw new ArgumentNullException(nameof(name)); } return(new ClientOptions() { Name = name, Active = active, Currency = currency, Details = details, HighriseId = highriseId }); }