public void GetByShortcutTest() { var bitcoin = new Currency { Name = "bitcoin", Shortcut = "BTC" }; Assert.AreEqual(null, _repository.GetByShortcut(bitcoin.Shortcut)); _repository.AddCurrency(bitcoin); Assert.AreEqual(bitcoin, _repository.GetByShortcut(bitcoin.Shortcut)); }
private void Button_Click(object sender, RoutedEventArgs e) { var currency = cmbCurrencies.SelectedItem as Currency; _currencyRepository.AddCurrency(currency); Close(); }
public async Task <IActionResult> Create([Bind("Code,Name")] Currency currency) { if (ModelState.IsValid) { _currency.AddCurrency(currency); await _currency.SaveCurrency(); return(RedirectToAction(nameof(Index))); } return(View(currency)); }
public IActionResult CreateCurrency([FromBody] Currency Currency) { if (Currency == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdCurrency = _CurrencyRepository.AddCurrency(Currency); return(Created("Currency", createdCurrency)); }
public HttpResponseMessage Post([FromBody] Models.currency currency) { try { if (string.IsNullOrEmpty(currency.currency_name)) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Currency is Empty" }, formatter)); } else { if (currencyRepository.CheckDuplicateCurrency(currency.currency_name)) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Currency Already Exists" }, formatter)); } else { currency insert_currency = new currency { currency_name = currency.currency_name }; currencyRepository.AddCurrency(insert_currency); var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "success", msg = "Currency save successfully" }, formatter)); } } } catch (Exception ex) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = ex.ToString() }, formatter)); } }
public IActionResult Add(CurrencyViewModel currencyViewModel) { var currencyList = _currency.GetCurrencies(); ViewBag.currency = currencyList; ViewBag.CurrencyTypeId = new SelectList(_type.GetCurrencyTypes(), "Id", "Name", currencyViewModel.CurrencyTypeId); if (currencyViewModel.CurrencyTypeId == null) { ModelState.AddModelError("", "الرجاء تحديد نوع العملة"); } if (currencyViewModel.Id == 0) { ModelState.Remove("Id"); ModelState.Remove("CurrencyTypeId"); if (ModelState.IsValid) { var currency = _mapper.Map <Currency>(currencyViewModel); _currency.AddCurrency(currency); _toastNotification.AddSuccessToastMessage("تم أضافةالعملة بنجاح"); return(RedirectToAction(nameof(Index))); } return(View(nameof(Index), currencyViewModel)); } else { ModelState.Remove("CurrencyTypeId"); if (ModelState.IsValid) { var currency = _mapper.Map <Currency>(currencyViewModel); _currency.UpdateCurrency(currencyViewModel.Id, currency); _toastNotification.AddSuccessToastMessage("تم تعديل العملة بنجاح"); return(RedirectToAction(nameof(Index))); } return(View(nameof(Index), currencyViewModel)); } }