public void GetCurrencyViewModelTest() { var currencyDto = CreateCurrency(); var currency = ModelsMapper.GetCurrencyViewModel(currencyDto); Assert.IsNotNull(currency); Assert.IsTrue(currency.Code == currencyDto.Code); Assert.IsTrue(currency.ShortName.Equals(currencyDto.ShortName, StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(currency.FullName.Equals(currencyDto.FullName, StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(currency.Symbol.Equals(currencyDto.Symbol, StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// Returns the currency with the specified <paramref name="code"/>. /// </summary> /// <param name="code"> /// The currency numeric code (see ISO 421). /// </param> /// <returns> /// The currency with the specified <paramref name="code"/> or <b>null</b> if currency doesn't exist. /// </returns> public CurrencyViewModel GetCurrencyByCode(int code) { Currency currency; using (var repositry = Factory.GetCurrencyRepository()) { currency = repositry.FirstOrDefault(c => c.Code == code); } return(ModelsMapper.GetCurrencyViewModel(currency)); }
/// <summary> /// Returns the currency with the specified <paramref name="name"/>. /// </summary> /// <param name="name"> /// The currency name (see ISO 421). /// </param> /// <returns> /// The currency with the specified <paramref name="name"/> or <b>null</b> if currency doesn't exist. /// </returns> public CurrencyViewModel GetCurrencyByName(string name) { Currency currency; using (var repositry = Factory.GetCurrencyRepository()) { currency = repositry.FirstOrDefault(c => c.ShortName.Equals(name.Trim(), StringComparison.OrdinalIgnoreCase)); } return(ModelsMapper.GetCurrencyViewModel(currency)); }
private CurrencyViewModel GetUserCurrencyFromDb() { Currency currency = null; using (var repository = RepositoryFactory.GetUserDataRepository()) { var userData = repository.FirstOrDefault(u => u.UserId == CurrentUser.Id, u => u.UserCurrency); if (userData != null) { currency = userData.UserCurrency; } } return(ModelsMapper.GetCurrencyViewModel(currency)); }
public ActionResult Edit(int id = 0) { if (id <= 0) { return(RedirectToAction("Index", "Currency", new { area = "Admin" })); } Currency currency; using (var currencyRepository = RepositoryFactory.GetCurrencyRepository()) { currency = currencyRepository.GetById(id); } if (currency == null) { return(HttpNotFound("Валюты с указанным id не существует")); } CurrencyViewModel model = ModelsMapper.GetCurrencyViewModel(currency); return(View(model)); }