Exemplo n.º 1
0
        // 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)));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
 public async Task UpdateAppUserPrizeAsync(AppUserPrize userPrize)
 {
     _context.Update(userPrize);
     await _context.SaveChangesAsync();
 }
Exemplo n.º 4
0
 public async Task DeleteAppUserPrizeAsync(AppUserPrize userPrize)
 {
     _context.AppUserPrize.Remove(userPrize);
     await _context.SaveChangesAsync();
 }
Exemplo n.º 5
0
        public async Task CreateAppUserPrizeAsync(AppUserPrize userPrize)
        {
            await _context.AddAsync(userPrize);

            await _context.SaveChangesAsync();
        }