public ActionResult Create() { CurrencyDTO model = new CurrencyDTO(); model.IsActive = true; return(View(model)); }
public ActionResult Create(CurrencyDTO model) { try { // Remove white space model.Symbol = RemoveSpecChar(model.Symbol); //============================= string msg = ""; bool result = _factory.CreateOrEdit(model, CurrentUser.UserId, ref msg); if (result) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("Name", msg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(View(model)); } } catch (Exception ex) { NSLog.Logger.Error("Currency_Create: ", ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public ActionResult Delete(CurrencyDTO model) { try { string msg = ""; var result = _factory.Delete(model.ID, CurrentUser.UserId, ref msg); if (!result) { Response.StatusCode = (int)HttpStatusCode.BadRequest; CurrencyViewModels tmp = new CurrencyViewModels(); var listData = _factory.GetListData(); tmp.ListItem = listData; return(PartialView("_ListData", tmp)); } return(RedirectToAction("Index")); } catch (Exception ex) { NSLog.Logger.Error("Currency_Delete: ", ex); ModelState.AddModelError("Name", "Have an error when you delete a Currency"); Response.StatusCode = (int)HttpStatusCode.BadRequest; CurrencyViewModels tmp = new CurrencyViewModels(); var listData = _factory.GetListData(); tmp.ListItem = listData; return(PartialView("_ListData", tmp)); } }
public async Task <IEnumerable <CurrencyDTO> > GetRatesFromAPI() { var currencies = new List <CurrencyDTO>(); var request = new HttpRequestMessage() { RequestUri = new Uri(_exchangeAPISettings.DefaultFetchRatesUrl), Method = HttpMethod.Get }; using var httpClient = new HttpClient(); var response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { var responseString = await response.Content.ReadAsStringAsync(); var currenciesDTO = JsonConvert.DeserializeObject <ForeignExchangeRatesDTO>(responseString); foreach (var rate in currenciesDTO.Rates) { var rateDTO = new CurrencyDTO() { Code = rate.Key, Rate = rate.Value, }; currencies.Add(rateDTO); } } else { _logger.LogWarning("Error while fetching currency rates.", await response.Content.ReadAsStringAsync()); } return(currencies); }
public static async Task <Double> Convert(String symbolFrom, String symbolTo, Wallet wallet, Double toConvertoQuantity) { CurrencyDTO to = await App.DatabaseCurrencies.GetLastUpdateTimeString(symbolTo + "=X"); CurrencyDTO from = await App.DatabaseCurrencies.GetLastUpdateTimeString(symbolFrom + "=X"); if (to != null && from != null) { Double convertedQuantity = new APIHandler().Convert(from, to, toConvertoQuantity); Double diff = wallet.Quantity - toConvertoQuantity; wallet.Quantity = diff; if (diff >= 0.1) { await App.Database.SaveItemAsync(wallet); } else { await App.Database.DeleteItemAsync(wallet); } await App.Database.SaveOrUpdateItemAsync(new Wallet(convertedQuantity, symbolTo)); return(convertedQuantity); } return(-1); }
public async Task <CurrencyDTO> GetById(Guid id) { Currencies response = await _context.Currency.FirstOrDefaultAsync(m => m.Id == id); CurrencyDTO data = new CurrencyDTO() { Id = response.Id , Value = (decimal)response.Value , Applied = new CurrencyNameDTO() { Name = response.AppliedName, Symbol = response.AppliedSymbol } , Replacement = new CurrencyNameDTO() { Name = response.ReplacementName, Symbol = response.ReplacementSymbol } , OutputValue = response.OutputValue , Date = response.Date }; return(data); }
public async Task <CurrencyDTO> GetCurrencyByIdAsync(string currencyId) { Currency currency = null; string urlPath = _apiUrl + currencyId; using (var client = new HttpClient()) using (var response = await client.GetAsync(urlPath)) using (var content = response.Content) { if (response.IsSuccessStatusCode) { try { var apiResponse = await content.ReadAsStringAsync(); var serializedResponse = JsonConvert.DeserializeObject <List <Currency> >(apiResponse); currency = serializedResponse[0]; } catch (JsonSerializationException) { // Add additional exception handling here if we do not wont to just return null object. } } } return(CurrencyDTO.ConvertToCurrencyDTO(currency)); }
public Currency Add(CurrencyDTO currencyDTO) { Currency currency = _mapper.Map <Currency>(currencyDTO); _currenciesRepo.Add(currency); return(currency); }
public async Task <List <CurrencyDTO> > GetAll() { List <CurrencyDTO> listData = new List <CurrencyDTO>(); List <Currencies> response = await _context.Currency.ToListAsync(); response.ForEach(element => { CurrencyDTO data = new CurrencyDTO() { Id = element.Id , Value = (decimal)element.Value , Applied = new CurrencyNameDTO() { Name = element.AppliedName, Symbol = element.AppliedSymbol } , Replacement = new CurrencyNameDTO() { Name = element.ReplacementName, Symbol = element.ReplacementSymbol } , OutputValue = element.OutputValue , Date = element.Date }; listData.Add(data); }); return(listData); }
public CurrencyDTO GetDetail(string ID) { CurrencyDTO model = new CurrencyDTO(); try { GetCurrencyRequest paraBody = new GetCurrencyRequest(); paraBody.ID = ID; NSLog.Logger.Info("Currency Get Detail Request", paraBody); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.CurrencyAPIGetList, null, paraBody); NSLog.Logger.Info("Currency Get Detail Response", paraBody); dynamic data = result.Data; var lstDataRaw = data["ListCurrency"]; var lstObject = JsonConvert.SerializeObject(lstDataRaw); model = JsonConvert.DeserializeObject <List <CurrencyDTO> >(lstObject)[0]; NSLog.Logger.Info("Currency_GetDetail", model); return(model); } catch (Exception e) { NSLog.Logger.Error("Currency_GetDetail_Fail", e); return(model); } }
public ActionResult CurrencyCalc(string firstValute, string secondValute, decimal firstValuteCount = 1) { using (BankDB bankDB = new BankDB()) { if (firstValute == null && secondValute == null) { CurrencyDTO firstCurrencyDefault = bankDB.Currency.FirstOrDefault(x => x.CurrencyCharCode == "AUD"); CurrencyDTO secondCurrencyDefault = bankDB.Currency.FirstOrDefault(x => x.CurrencyCharCode == "AUD"); ViewBag.FisrtValuteName = firstCurrencyDefault.CurrencyName; ViewBag.SecondValuteName = secondCurrencyDefault.CurrencyName; ViewBag.Result = firstCurrencyDefault.CurrencyRate * firstValuteCount / secondCurrencyDefault.CurrencyRate; return(PartialView("_CurrencyCalc")); } else { CurrencyDTO firstCurrency = bankDB.Currency.FirstOrDefault(x => x.CurrencyCharCode == firstValute); CurrencyDTO secondCurrency = bankDB.Currency.FirstOrDefault(x => x.CurrencyCharCode == secondValute); ViewBag.FisrtValuteName = firstCurrency.CurrencyName; ViewBag.SecondValuteName = secondCurrency.CurrencyName; ViewBag.Result = firstCurrency.CurrencyRate * firstValuteCount / secondCurrency.CurrencyRate; return(PartialView("_CurrencyCalc")); } } }
public Double Convert(String symbolFrom, String symbolTo, Double qtd, List <CurrencyDTO> list) { CurrencyDTO from = null; CurrencyDTO to = null; foreach (CurrencyDTO currency in list) { if (currency.Symbol != null && currency.Symbol.Length > 0) { var symbol = currency.Symbol.Substring(0, currency.Symbol.Length - 2); if (symbol.CompareTo(symbolFrom) == 0) { from = currency; if (to != null) { break; } continue; } if (symbol.CompareTo(symbolTo) == 0) { to = currency; if (from != null) { break; } continue; } } } return(Convert(from, to, qtd)); }
public async Task <ActionResult <Currency> > WithDrawCurrency(int userid, [FromBody] CurrencyDTO currency) { if (currency is null) { return(NoContent()); } var user = _repo.GetUserById(userid).Result; if (user is null) { throw new ArgumentNullException(nameof(user)); } var result = await _repo.IfExistCurrency(userid, currency.Count, currency.TypeOfCurrency); if (result) { var currencyForChange = user.Currencies.FirstOrDefault(c => c.TypeOfCurrency.Equals(currency.TypeOfCurrency)); if (currencyForChange != null) { currencyForChange.Count += currency.Count; } _repo.Update(currencyForChange); } else { await _repo.AddNewCurrency(userid, currency.Count, currency.TypeOfCurrency); } if (await _repo.SaveAll()) { return(CreatedAtAction("GetCurrency", new { id = currency.Id }, currency)); } throw new System.Exception($"Creating currency {currency.Id} filed on create"); }
public async Task <ActionResult> pvwCurrency([FromBody] CurrencyDTO _sarpara) { CurrencyDTO _Currency = new CurrencyDTO(); try { string baseadress = config.Value.urlbase; HttpClient _client = new HttpClient(); _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token")); var result = await _client.GetAsync(baseadress + "api/Currency/GetCurrencyById/" + _sarpara.CurrencyId); string valorrespuesta = ""; if (result.IsSuccessStatusCode) { valorrespuesta = await(result.Content.ReadAsStringAsync()); _Currency = JsonConvert.DeserializeObject <CurrencyDTO>(valorrespuesta); } if (_Currency == null) { _Currency = new CurrencyDTO(); } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } return(PartialView(_Currency)); }
public async Task <CreditCardDTO> Topup(int amount, CreditCardDTO dtoObject, CurrencyDTO currencyDto, UserDTO user) { CreditCardDTO dbCreditCardDto = await this.GetAsync(dtoObject.Id); if (dbCreditCardDto.UserId != user.UserId) { Common.Helper.ExceptionHelper.ThrowAPIException(Core.Constant.Message.CreditCard_InvalidCard); } else { AccountDTO accountDto = await this._accountService.GetAccountByUserId(user.UserId); if (accountDto == null) { accountDto = new AccountDTO(); accountDto.Balance = amount; accountDto.Currency = currencyDto; accountDto.User = dtoObject.User; await this._accountService.CreateAsync(accountDto); } else { accountDto.Balance = accountDto.Balance + amount; await this._accountService.UpdateAsync(accountDto); } } return(dtoObject); }
public Currency Update(CurrencyDTO currencyDTO) { Currency currency = _mapper.Map <Currency>(currencyDTO); _currenciesRepo.Update(currency); return(currency); }
public List <CurrencyDTO> GetAllCurrencies() { List <Currency> currencies = null; string urlPath = _apiUrl; using (var client = new HttpClient()) using (var response = client.GetAsync(urlPath).Result) using (var content = response.Content) { if (response.IsSuccessStatusCode) { try { var apiResponse = content.ReadAsStringAsync().Result; currencies = JsonConvert.DeserializeObject <List <Currency> >(apiResponse); } catch (JsonSerializationException) { // Add additional exception handling here if we do not wont to just return null object. } } } List <CurrencyDTO> result = new List <CurrencyDTO>(); foreach (var currency in currencies) { if (currency != null) { result.Add(CurrencyDTO.ConvertToCurrencyDTO(currency)); } } return(result); }
public async Task <IActionResult> Create(CurrencyDTO data, [FromServices] ExchangeRateCommandHandler handler) { if (ModelState.IsValid) { (var currenciesApplied, var currenciesReplacement) = await _exchangeRateQuery.GetListCurrencyNames(Settings.COINLORE_CURRENCIES_URL, Settings.COINLORE_EXCHANGE_RATE_URL); currenciesApplied.ForEach(currency => { if (data.Applied.Symbol == currency.Symbol) { data.Applied.Name = currency.Name; } }); currenciesReplacement.ForEach(currency => { if (data.Replacement.Symbol == currency.Symbol) { data.Replacement.Name = currency.Name; } }); ExchangeResgisterCommand command = new ExchangeResgisterCommand(data.Value, data.Applied, data.Replacement); await handler.Handle(command); return(RedirectToAction(nameof(History))); } (ViewBag.DataApplied, ViewBag.DataReplacement) = await _exchangeRateQuery.GetListCurrencyNames(Settings.COINLORE_CURRENCIES_URL, Settings.COINLORE_EXCHANGE_RATE_URL); return(View(data)); }
public async Task UpdateItem(CurrencyDTO currency) { var currencyEntity = _mapper.Map <Currency>(currency); _dbContext.Currencies.Update(currencyEntity); await _dbContext.SaveChangesAsync(); }
public ActionResult <CurrencyDTO> Add([FromBody] CurrencyDTO currencyDTO) { var addedCurrency = _srv.Add(currencyDTO); _unitOfWork.Commit(); return(CreatedAtAction(nameof(GetById), new { id = addedCurrency.Id }, _srv.MapToDTO(addedCurrency))); }
public IActionResult CurrencyAdd(CurrencyDTO model) { if (ModelState.IsValid) { _currencyService.Add(model); } return(RedirectToAction("CurrencyAdd")); }
public CurrencyDTO Update([FromBody] CurrencyDTO currencyDTO) { var updatedCurrency = _srv.Update(currencyDTO); _unitOfWork.Commit(); return(_srv.MapToDTO(updatedCurrency)); }
public async Task InsertItem(CurrencyDTO currencyDTO) { var accountEntity = _mapper.Map <Account>(currencyDTO); _dbContext.Accounts.Add(accountEntity); await _dbContext.SaveChangesAsync(); }
public CurrencyVM(CurrencyDTO row) { Id = row.Id; CurrencyName = row.CurrencyName; CurrencyCharCode = row.CurrencyCharCode; CurrencyRate = row.CurrencyRate; ExchangeDate = row.ExchangeDate; }
public async Task <CurrencyDTO> UpdateAsync(CurrencyDTO dto) { var model = _mapper.Map <Currency>(dto); _unitOfWork.CurrencyRepository.Update(model); await _unitOfWork.SaveAsync(); return(_mapper.Map <CurrencyDTO>(model)); }
public IActionResult Currency() { CurrencyDTO currencyDTO = new CurrencyDTO { Currencies = _currencyService.GetAll() }; return(View(currencyDTO)); }
private void frmUpdateCurrent_Load_1(object sender, EventArgs e) { CurrencyDTO curDTO = curBUS.getCurrentcy(maPhieuNhan); txtMa.Text = curDTO.iMaTT; txtTen.Text = curDTO.iTenTT; calTyGia.Text = curDTO.iTGQD.ToString(); check.Checked = curDTO.iActive; }
public async Task <IActionResult> AddCurrency([FromBody] CurrencyDTO currency) { if (!ModelState.IsValid) { return(BadRequest() as IActionResult); } var info = await service.AddAsync(currency); return(info ? Ok() : StatusCode(400)); }
public static BaseCurrencyDTO ToBaseCurrencyDto(this CurrencyDTO token) { return(new BaseCurrencyDTO { CurrencyId = token.CurrencyId , CurrencyName = token.CurrencyName , ISO = token.ISO , Symbol = string.IsNullOrEmpty(token.Symbol) ? token.ISO : token.Symbol }); }
public static BundlePriceDTO Entity2BundlePriceDTO(this CRS_Bundles entity, CurrencyDTO currency) { return(new BundlePriceDTO { BundleId = entity.BundleId // ,Price = entity.Price.ItemPrice2DisplayPrice() // ,MonthlySubscriptionPrice = entity.MonthlySubscriptionPrice.ItemPrice2DisplayPrice() , AffiliateCommission = entity.AffiliateCommission , Currency = currency.ToBaseCurrencyDto() }); }
public void AddToCurrencies(CurrencyDTO currencyDTO) { base.AddObject("Currencies", currencyDTO); }
public static CurrencyDTO CreateCurrencyDTO(int ID) { CurrencyDTO currencyDTO = new CurrencyDTO(); currencyDTO.Id = ID; return currencyDTO; }