public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Code,BidPrice,AskPrice,Data")] CurrencyDBModel cashDBModel) { if (id != cashDBModel.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cashDBModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CashDBModelExists(cashDBModel.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cashDBModel)); }
public async Task <string> GetLastOneCurrency(string iso) { iso.ToUpper(); CurrencyDBModel query = get.GetLastOne(iso, _context); CurrencyModel result = new CurrencyModel(query); await Task.CompletedTask; return(JsonConvert.SerializeObject(result, Formatting.Indented)); }
public async Task <IActionResult> Create([Bind("ID,Name,Code,BidPrice,AskPrice,Data")] CurrencyDBModel cashDBModel) { if (ModelState.IsValid) { _context.Add(cashDBModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cashDBModel)); }
public CurrencyDBModel DownloadActualCurrency(string iso) { string url = "http://api.nbp.pl/api/exchangerates/rates/c/" + iso + "/?today/?format=json"; string reply = webClient.DownloadString(url); dynamic jObject = JObject.Parse(reply); DateTime date = DateTime.Now; string name = jObject.currency; string code = jObject.code; float askPrice = jObject.rates[0].ask; float bidPrice = jObject.rates[0].bid; CurrencyDBModel _cashModel = new CurrencyDBModel(name, code, bidPrice, askPrice, date); return(_cashModel); }
private void CheckAndSendAlert(CashDBContext _context, IMailService _mailService, List <CurrencyDBModel> listOfCash) { var alerts = _context.Remainders.ToList(); foreach (Remainder item in alerts) { if (item.Price == "Less") { CurrencyDBModel todayPrice = listOfCash.FirstOrDefault(s => s.Code == item.Code); if (todayPrice != null) { if (item.BidPrice > todayPrice.BidPrice) { var user = _context.userDBModels.FirstOrDefault(s => s.ID == item.UserID); if (user != null) { _mailService.SendMail(user.Email, "Alert kursu", MakeMessageForAlert(todayPrice.Code, "sprzedaży", todayPrice.BidPrice)); } } } } if (item.Price == "More") { CurrencyDBModel todayPrice = listOfCash.FirstOrDefault(s => s.Code == item.Code); if (todayPrice != null) { if (item.AskPrice < todayPrice.AskPrice) { var user = _context.userDBModels.FirstOrDefault(s => s.ID == item.UserID); if (user != null) { _mailService.SendMail(user.Email, "Alert kursu", MakeMessageForAlert(todayPrice.Code, "kupna", todayPrice.AskPrice)); } } } } if (item.EndDateOfAlert < DateTime.Now) { _context.Remove(item); _context.SaveChanges(); } } }