// POST: AppUserPrizes/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. //[HttpPost] //[ValidateAntiForgeryToken] public async Task <IActionResult> CreatePrizeUser(int prize, string user) { Prize newPrize = _appUserPrizes.SearchForPrize(prize); AppUser newUser = await _userManager.FindByIdAsync(user); if (newUser.Points >= newPrize.Price) { newUser.Points -= newPrize.Price; await _userManager.UpdateAsync(newUser); AppUserPrize appUserPrize = new AppUserPrize() { Prize = newPrize, User = newUser }; if (ModelState.IsValid) { await _registry.CreateRegistryAsync("Buy", newPrize.Price, newUser); await _appUserPrizes.CreateAppUserPrizeAsync(appUserPrize); return(RedirectToAction(nameof(Index))); } return(View(appUserPrize)); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id, [Bind("Id")] AppUserPrize appUserPrize) { if (id != appUserPrize.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _appUserPrizes.UpdateAppUserPrizeAsync(appUserPrize); } catch (DbUpdateConcurrencyException) { if (!_appUserPrizes.AppUserPrizeExists(appUserPrize.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(appUserPrize)); }
public async Task UpdateAppUserPrizeAsync(AppUserPrize userPrize) { _context.Update(userPrize); await _context.SaveChangesAsync(); }
public async Task DeleteAppUserPrizeAsync(AppUserPrize userPrize) { _context.AppUserPrize.Remove(userPrize); await _context.SaveChangesAsync(); }
public async Task CreateAppUserPrizeAsync(AppUserPrize userPrize) { await _context.AddAsync(userPrize); await _context.SaveChangesAsync(); }