public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(BankAccountModel.BankAccount).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BankAccountExists(BankAccountModel.BankAccount.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int id) { if (!ModelState.IsValid) { return(Page()); } player = await _context.Players .Include(p => p.Position).FirstOrDefaultAsync(m => m.ID == id); _context.Attach(player).State = EntityState.Modified; try { if (NewImage != null && NewImage.Length > 0) { using (var ms = new MemoryStream()) { NewImage.CopyTo(ms); var fileBytes = ms.ToArray(); var resizedImage = ImageUtils.ResizeImage(fileBytes, 140, 190); player.Image = resizedImage; } } player.FirstName = PlayerModel.FirstName; player.LastName = PlayerModel.LastName; player.DOB = PlayerModel.DOB; player.Email = PlayerModel.Email; player.PositionId = PlayerModel.PositionId; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlayerExists(id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
private static async Task <BankAccount> GetOrCreateNewAccount(ClubTreasurerContext context, GeorgeTransaction transaction) { BankAccount account; if (transaction.PartnerAccount?.Iban == null) { //cash payment account = await GetOwnBankAccount(context, "AT722050303300000928"); if (account != null) { return(account); } } account = await context.BankAccounts.FirstOrDefaultAsync(a => a.ID == transaction.PartnerAccount.Iban); if (account != null) { return(account); } else { account = new BankAccount { ID = transaction.PartnerAccount.Iban, Name = transaction.PartnerName }; context.BankAccounts.Add(account); try { await context.SaveChangesAsync(); } catch (Exception ex) { var test = ex; } //try to assign it to a person var person = context.Persons.Where(p => p.FullName == transaction.PartnerName || p.FullNameReverse == transaction.PartnerName).FirstOrDefault(); if (person != null) { context.Attach(person).State = EntityState.Modified; if (person.BankAccounts == null) { person.BankAccounts = new List <BankAccount> { account }; await context.SaveChangesAsync(); } else { person.BankAccounts.Add(account); } } return(account); } }