public async Task <IActionResult> Create(CardCreateViewModel model) { var fileName = Path.GetFileName(ContentDispositionHeaderValue.Parse(model.FilePath.ContentDisposition).FileName.Value.Trim('"')); var fileExt = Path.GetExtension(fileName); if (!AllowedExtensions.Contains(fileExt)) { this.ModelState.AddModelError(nameof(model.FilePath), "This file type is prohibited"); } if (ModelState.IsValid) { var card = new Card { FileName = model.FileName, RandNum = _randomNumbersService.GetRandomNumber() }; var picPath = Path.Combine(_hostingEnvironment.WebRootPath, "pics", card.Id.ToString("N") + fileExt); card.FilePath = $"/pics/{card.Id:N}{fileExt}"; using (var fileStream = new FileStream(picPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read)) { await model.FilePath.CopyToAsync(fileStream); } _context.Add(card); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }
// GET: prepaidCards/Create public IActionResult Create() { CardCreateViewModel createViewModel = new CardCreateViewModel() { CardCode = PassWordHelper.GenerateCheckCode(8), CarsSecret = PassWordHelper.GenerateCheckCode(8) }; return(View(createViewModel)); }
public async Task <IActionResult> Create() { var userAccounts = await this.GetAllAccountsAsync(this.GetCurrentUserId()); var model = new CardCreateViewModel { BankAccounts = userAccounts }; return(this.View(model)); }
public async Task <IActionResult> Create() { var userId = await this.userService.GetUserIdByUsernameAsync(this.User.Identity.Name); var userAccounts = await this.GetAllAccountsAsync(userId); var model = new CardCreateViewModel { BankAccounts = userAccounts }; return(this.View(model)); }
public async Task <IActionResult> Create(CardCreateViewModel model) { var userId = await this.userService.GetUserIdByUsernameAsync(this.User.Identity.Name); if (!this.ModelState.IsValid) { model.BankAccounts = await this.GetAllAccountsAsync(userId); return(this.View(model)); } var account = await this.bankAccountService.GetByIdAsync <BankAccountDetailsServiceModel>(model.AccountId); if (account == null || account.UserUserName != this.User.Identity.Name) { return(this.Forbid()); } var serviceModel = Mapper.Map <CardCreateServiceModel>(model); serviceModel.UserId = userId; serviceModel.Name = account.UserFullName; serviceModel.ExpiryDate = DateTime.UtcNow.AddYears(GlobalConstants.CardValidityInYears) .ToString(GlobalConstants.CardExpirationDateFormat, CultureInfo.InvariantCulture); bool isCreated = await this.cardService.CreateAsync(serviceModel); if (!isCreated) { this.ShowErrorMessage(NotificationMessages.CardCreateError); return(this.RedirectToHome()); } this.ShowSuccessMessage(NotificationMessages.CardCreatedSuccessfully); return(this.RedirectToAction(nameof(this.Index))); }