Beispiel #1
0
        // GET: /Tenant/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }

            var tenant = _tenantServices.GetByClientId((int)id);

            if (tenant == null)
            {
                return(HttpNotFound());
            }
            return(View(tenant));
        }
        public async Task <IHttpActionResult> GetTenantCurrencyExRate(int tenantId)
        {
            try
            {
                if (tenantId == 0)
                {
                    return(BadRequest("Tenant id cannot be 0"));
                }
                var             tenantBaseCurrency = _tenantCurrencyRateServices.GetTenantCurrencyById(tenantId);
                var             model           = _tenantCurrencyRateServices.GetTenantCurrencies(tenantId).ToList();
                CurrenciesRates currenciesRates = new CurrenciesRates();
                currenciesRates = await GetCurrencyExchangeRate(tenantBaseCurrency.CurrencyName, model);

                if (!currenciesRates.success)
                {
                    return(NotFound());
                }
                else
                {
                    List <TenantCurrenciesExRates> tenantCurrenciesExRatesList = new List <TenantCurrenciesExRates>();
                    var tenant = _tenantServices.GetByClientId((int)tenantId);
                    foreach (var item in currenciesRates.quotes)
                    {
                        foreach (var itemModel in model)
                        {
                            string Key = item.Key;
                            Key = Key.Substring(3);
                            string currency1 = (itemModel.GlobalCurrency.CurrencyName).Substring(0, 3).ToUpper();

                            if (Key == currency1)
                            {
                                TenantCurrenciesExRates tenantCurrenciesExRates = new TenantCurrenciesExRates();
                                tenantCurrenciesExRates.TenantCurrencyID = itemModel.CurrencyID;
                                tenantCurrenciesExRates.ActualRate       = Convert.ToDecimal(item.Value);
                                tenantCurrenciesExRates.DiffFactor       = Convert.ToDecimal(itemModel.DiffFactor);
                                tenantCurrenciesExRates.Rate             = Convert.ToDecimal(tenantCurrenciesExRates.DiffFactor + tenantCurrenciesExRates.ActualRate);
                                tenantCurrenciesExRates.DateUpdated      = DateTime.UtcNow;
                                SaveTenantCurrencyRate(tenantCurrenciesExRates);
                            }
                        }
                    }
                    return(Ok("Currency rate saved"));
                }
            }
            catch (Exception Exp)
            {
                if (Exp.InnerException != null)
                {
                    _tenantCurrencyRateServices.LogAPI(Exp.InnerException.ToString(), HttpStatusCode.Ambiguous, typeof(ApiCurrencyExRateController));
                    Debug.WriteLine(Exp.InnerException);
                }
                return(BadRequest());
            }
        }