public async Task <IActionResult> Create([Bind("Id,Amount,TransactionTime,CountryId,Type,IBAN,BankId")] AddRefundViewModel refund, ICollection <IFormFile> files) { if (!ModelState.IsValid) { return(View(refund)); } //user is only allowed to create one refund at a time. when a refund status is "Paid" "Canceled" or "Rejected" it is considered finished, if the status is " Recieved","Accepted" or "Approved" it is considered Open. so only allow if finished. if (HasOpenRequest()) { return(BadRequest("HasOpenRequest")); } var newRefund = new Refund() { Applicant = await GetCurrentUserAsync(), Status = refund.Status, Amount = refund.Amount, TransactionTime = refund.TransactionTime, Type = refund.Type, IBAN = refund.IBAN, Bank = _applicationDbContextcontext.Banks.FirstOrDefault(b => b.Id == refund.BankId), Country = _applicationDbContextcontext.Countries.FirstOrDefault(c => c.Id == refund.CountryId) }; _applicationDbContextcontext.Add(newRefund); await _applicationDbContextcontext.SaveChangesAsync(); return(RedirectToAction("Index")); }
// GET: Requests/Create public IActionResult Create() { if (HasOpenRequest()) { return(BadRequest("HasOpenRequest")); } var countries = _applicationDbContextcontext.Countries.OrderBy(c => c.Name) .Select(x => new { Id = x.Id, Value = x.Name }); var banks = _applicationDbContextcontext.Banks.OrderBy(c => c.ArabicName) .Select(x => new { Id = x.Id, Value = x.ArabicName }); var model = new AddRefundViewModel() { BankList = new SelectList(banks, "Id", "Value"), CountryList = new SelectList(countries, "Id", "Value") }; return(View(model)); }