public async Task <IActionResult> Delete(int id)
        {
            if (id != 0)
            {
                try
                {
                    var currencyInDb = await unitOfWork.currencyRepository.GetByIdAsync(id);

                    var currencyHistory = new CurrencyHistory
                    {
                        OldName  = currencyInDb.Name,
                        NewName  = "",
                        OldValue = currencyInDb.Value,
                        NewValue = 0,
                        Status   = "Deleted",
                        Time     = DateTime.Now
                    };
                    await unitOfWork.currencyHistoryRepository.Add(currencyHistory);

                    unitOfWork.currencyRepository.Delete(currencyInDb);
                    unitOfWork.Commit();
                }
                catch
                {
                    unitOfWork.Rollback();
                }
            }

            return(Redirect("/Currency/Currencyhistory"));
        }
            private static CurrencyHistory CreateTestHistory()
            {
                DateTime d1 = new DateTime(2020, 01, 01);
                DateTime d2 = new DateTime(2020, 01, 02);
                DateTime d3 = new DateTime(2020, 01, 03);
                DateTime d4 = new DateTime(2020, 01, 04);

                CurrencyRate[] r1 =
                {
                    new CurrencyRate("HUF", 1), new CurrencyRate("FOO", 10), new CurrencyRate("BAR", 100)
                };

                CurrencyRate[] r2 =
                {
                    new CurrencyRate("HUF", 2), new CurrencyRate("FOO", 20), new CurrencyRate("BAR", 200)
                };

                CurrencyRate[] r3 =
                {
                    new CurrencyRate("HUF", 3), new CurrencyRate("FOO", 30), new CurrencyRate("BAR", 300)
                };

                CurrencyRate[] r4 =
                {
                    new CurrencyRate("HUF", 4), new CurrencyRate("FOO", 40), new CurrencyRate("BAR", 400)
                };

                CurrencyRatesSnapshot s1 = new CurrencyRatesSnapshot(d1, r1);
                CurrencyRatesSnapshot s2 = new CurrencyRatesSnapshot(d2, r2);
                CurrencyRatesSnapshot s3 = new CurrencyRatesSnapshot(d3, r3);
                CurrencyRatesSnapshot s4 = new CurrencyRatesSnapshot(d4, r4);

                return(CurrencyHistory.CreateFromSnapshots(new[] { s1, s2, s3, s4 }));
            }
Beispiel #3
0
        public async Task GoodSymbols()
        {
            var tz   = DateTimeZoneProviders.Tzdb.GetZoneOrNull("Europe/London");
            var date = new LocalDate(2020, 1, 7); //.At(new LocalTime(16,0,0)).InZoneStrictly(tz);

            var currencyHistory = new CurrencyHistory(Logger).FromDate(date);

            var rate1 = await GetRate("USD", "JPY", date);

            Assert.Equal(108.61, rate1);

            var rate2 = await GetRate("EUR", "USD", date); // inverted

            Assert.Equal(1.114, Math.Round(rate2, 3));

            var rate3 = await GetRate("EUR", "JPY", date);

            Assert.Equal(121.000, Math.Round(rate3, 3));

            var EurJpy = rate1 * rate2;

            Assert.Equal(Math.Round(EurJpy, 3), Math.Round(rate3, 3));

            // local method
            async Task <double> GetRate(string symbol, string symbolBase, LocalDate date)
            {
                var list = await currencyHistory.GetRatesAsync(symbol, symbolBase);

                var result = list[0];

                Assert.Equal(date, result.Date.InZone(tz).Date);
                return(result.Rate);
            }
        }
        public async Task <IActionResult> Update(EditCurrencyViewModel request)
        {
            try
            {
                var id       = request.Currency.Id;
                var currency = await _currencyRepository.GetByIdAsync(id);

                var currencyHistory = new CurrencyHistory
                {
                    OldName  = currency.Name,
                    NewName  = request.Currency.Name,
                    OldValue = currency.Value,
                    NewValue = request.Currency.Value,
                    Status   = "Edited",
                    Time     = DateTime.Now
                };
                await unitOfWork.currencyHistoryRepository.Add(currencyHistory);

                currency.Name  = request.Currency.Name;
                currency.Value = request.Currency.Value;
                unitOfWork.currencyRepository.Update(currency);
                unitOfWork.Commit();
            }
            catch
            {
                unitOfWork.Rollback();
            }

            return(Redirect("/Currency"));
        }
Beispiel #5
0
        public bool OpenExchangeRates()
        {
            try
            {
                string BaseCurrency = "USD";
                string AppId        = configuration.GetValue <string>("OpenExchange_APIKey");
                string ApiUrl       = "https://openexchangerates.org/api/latest.json?app_id=" + AppId + "&base=" + BaseCurrency;

                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(ApiUrl);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                    HttpResponseMessage response = client.GetAsync(ApiUrl).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        var data = response.Content.ReadAsStringAsync();

                        //dynamic table = data.Result.ConvertFromJson<ExpandoObject>();
                        dynamic table = OptionConfigExtentions
                                        .ConvertFromJson <ExpandoObject>(data.Result);// data.Result.ConvertFromJson<ExpandoObject>();

                        var     result = new Dictionary <string, double>();
                        dynamic rates  = table.rates;

                        foreach (var x in rates)
                        {
                            result.Add(x.Key, x.Value);
                        }

                        double ZARValue = result["ZAR"];

                        List <CurrencyHistory> Currencies = new List <CurrencyHistory>();
                        foreach (var item in result)
                        {
                            CurrencyHistory currency = new CurrencyHistory();
                            currency.ConversionRate = ZARValue / item.Value;
                            currency.Code           = item.Key;
                            currency.DateTimeStamp  = DateTime.UtcNow;
                            Currencies.Add(currency);
                        }

                        Repository.AddMultiple(Currencies);

                        //TO DO SEND EMAIL
                    }

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #6
0
        public async Task <IActionResult> History()
        {
            var rates = await _currencyRateProvider.GetAllRatesAsync();

            CurrencyHistory history = CurrencyHistory.CreateFromSnapshots(rates);

            var result = new
            {
                codes = history.Codes.Select(c => c.Value).ToArray(),
                dates = history.Dates.Select(d => d.ToString("yyyy-MM-dd")).ToArray(),
                data  = history.Select(s => s.ToArray()).ToArray()
            };

            return(Json(result));
        }
            public void ThrowsOnInconsistentInputCount()
            {
                CurrencyRate[] r1 =
                {
                    new CurrencyRate("HUF", 1)
                };

                CurrencyRate[] r2 =
                {
                    new CurrencyRate("HUF", 10), new CurrencyRate("FOO", 20)
                };

                CurrencyRatesSnapshot s1 = new CurrencyRatesSnapshot(DateTime.Now, r1);
                CurrencyRatesSnapshot s2 = new CurrencyRatesSnapshot(DateTime.Now, r2);

                Assert.ThrowsAny <Exception>(() =>
                {
                    CurrencyHistory.CreateFromSnapshots(new[] { s1, s2 });
                });
            }
            public void EurIsIgnored()
            {
                CurrencyRate[] r1 =
                {
                    new CurrencyRate("HUF", 1), new CurrencyRate("EUR", 2)
                };

                CurrencyRate[] r2 =
                {
                    new CurrencyRate("HUF", 10), new CurrencyRate("EUR", 20)
                };

                CurrencyRatesSnapshot s1 = new CurrencyRatesSnapshot(DateTime.Now, r1);
                CurrencyRatesSnapshot s2 = new CurrencyRatesSnapshot(DateTime.Now, r2);

                var history = CurrencyHistory.CreateFromSnapshots(new[] { s1, s2 });

                Assert.Equal(1, history.Count);
                Assert.Equal(1, history.Codes.Count);
                Assert.NotNull(history["huf"]);
            }
        public async Task <IActionResult> Store(EditCurrencyViewModel request)
        {
            var user = await _userManager.GetUserAsync(User);

            try
            {
                var currencyHistory = new CurrencyHistory
                {
                    OldName  = "",
                    NewName  = request.Currency.Name,
                    OldValue = 0,
                    NewValue = request.Currency.Value,
                    Status   = "Created",
                    Time     = DateTime.Now,
                    User     = user
                };
                var currency = new Currency
                {
                    Name  = request.Currency.Name,
                    Value = request.Currency.Value
                };

                await unitOfWork.currencyHistoryRepository.Add(currencyHistory);

                await unitOfWork.currencyRepository.Add(currency);

                unitOfWork.Commit();
            }
            catch
            {
                unitOfWork.Rollback();
                // return ex.InnerException.Message;
            }

            return(Redirect("/Currency"));
        }
        public dynamic DBCurrencyStockhistorydue(CurrencyHistory objlist, int PeopleID) //Order change delivery boy
        {
            try
            {
                var deliveryBoy = context.Peoples.Where(x => x.PeopleID == PeopleID && x.Deleted == false).FirstOrDefault();
                if (objlist != null)
                {
                    var existDatas = context.CurrencyHistoryDB.Where(x => x.Deleted == false).FirstOrDefault();

                    if (existDatas == null)
                    {
                        objlist.UpdatedDate = indianTime;
                        objlist.CreatedDate = indianTime;
                        objlist.DboyName    = deliveryBoy.DisplayName;
                        objlist.status      = "Delivered Boy Currency Inserted InCST";
                        context.CurrencyHistoryDB.Add(objlist);
                        int id = context.SaveChanges();
                    }
                    else
                    {
                        var existData = context.CurrencyHistoryDB.Where(x => x.CurrencyHistoryid == existDatas.CurrencyHistoryid && x.Deleted == false).FirstOrDefault();

                        //CurrencyStock CST = new CurrencyStock();
                        existData.OneRupee      += objlist.OneRupee;
                        existData.onerscount    += objlist.onerscount;
                        existData.TwoRupee      += objlist.TwoRupee;
                        existData.tworscount    += objlist.tworscount;
                        existData.FiveRupee     += objlist.FiveRupee;
                        existData.fiverscount   += objlist.fiverscount;
                        existData.TenRupee      += objlist.TenRupee;
                        existData.tenrscount    += objlist.tenrscount;
                        existData.TwentyRupee   += objlist.TwentyRupee;
                        existData.Twentyrscount += objlist.Twentyrscount;
                        existData.fiftyRupee    += objlist.fiftyRupee;
                        existData.fiftyrscount  += objlist.fiftyrscount;
                        existData.HunRupee      += objlist.HunRupee;
                        existData.hunrscount    += objlist.hunrscount;
                        existData.fiveHRupee    += objlist.fiveHRupee;
                        existData.fivehrscount  += objlist.fivehrscount;
                        existData.twoTHRupee    += objlist.twoTHRupee;
                        existData.twoTHrscount  += objlist.twoTHrscount;
                        existData.TotalAmount   += objlist.TotalAmount;
                        existData.TotalAmount   += objlist.Dueamount;
                        //existData.Dueamount += objlist.Dueamount;
                        existData.UpdatedDate = indianTime;
                        context.CurrencyHistoryDB.Attach(existData);
                        context.Entry(existData).State = EntityState.Modified;
                        context.SaveChanges();
                    }
                    if (deliveryBoy != null)
                    {
                        DBoyCurrency db = context.DBoyCurrencyDB.Where(x => x.DBoyCId == objlist.DBoyCId).FirstOrDefault();

                        db.Dueamountstatus = " Settled ";

                        context.DBoyCurrencyDB.Attach(db);
                        context.Entry(db).State = EntityState.Modified;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(true);
        }
Beispiel #11
0
 public IList <CurrencyHistoryData> GetAllHistory(Guid id)
 {
     return(CurrencyHistory.ToJavaScriptCurrencyHistory(_eventStoreRepository.All(id)));
 }