Exemplo n.º 1
0
        public async Task <IActionResult> PutCliente(int id, Cliente cliente)
        {
            if (id != cliente.Id)
            {
                return(BadRequest());
            }

            _context.Entry(cliente).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClienteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutAdministrador(int id, Administrador administrador)
        {
            if (id != administrador.Id)
            {
                return(BadRequest());
            }

            _context.Entry(administrador).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdministradorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Putinterest(int id, interest interest)
        {
            if (id != interest.ID)
            {
                return(BadRequest());
            }

            _context.Entry(interest).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!interestExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 4
0
        public async Task<IActionResult> Putuser(int id, user user)
        {
            if (id != user.ID)
            {
                return BadRequest();
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!userExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }
 public async Task<IActionResult> Create([Bind("Id,Marca,Modelo,AnoLancamento,AnoMontagem,Chassis")] Carro carro)
 {
     if (ModelState.IsValid)
     {
         _context.Add(carro);
         await _context.SaveChangesAsync();
         return RedirectToAction(nameof(Index));
     }
     return View(carro);
 }
        public async Task <IActionResult> Create([Bind("Id,Nome,Valor,Estoque")] Produto produto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(produto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(produto));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Email,Telefone")] Contato contato)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contato);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contato));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Nascimento,CPF,RG,Celular,Email")] Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cliente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Nascimento,Email")] Pessoa pessoa)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pessoa);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pessoa));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("Id,Descricao,Vencimento,Valor")] Conta conta)
        {
            if (ModelState.IsValid)
            {
                _context.Add(conta);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(conta));
        }
        public async Task <ActionResult <Mesaj> > GetMesaj(int id)
        {
            var mesaj = await _context.Mesajs.FindAsync(id);

            //Console.WriteLine(mesajs);
            if (mesaj.isRead == 1)
            {
                mesaj.isRead = 0;
                _context.Entry(mesaj).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }

            return(mesaj);
        }
Exemplo n.º 12
0
        public async Task <ActionResult <User> > Postuser(User user)
        {
            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUsers", new { id = user.ID }, user));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.Username, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim("game-record-keeper-identity", "player"));

                    Player player = new Player
                    {
                        PreferredName = user.UserName,
                        Account       = user
                    };

                    _context.Players.Add(player);
                    await _context.SaveChangesAsync();

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.Username, Email = Input.Email
                };

                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        if (info.Principal.HasClaim(c => c.Type == "game-record-keeper-identity"))
                        {
                            var grkClaims = info.Principal.Claims
                                            .Where(c => c.Type == "game-record-keeper-identity" && c.Issuer == info.LoginProvider);
                            await _userManager.AddClaimsAsync(user, grkClaims);
                        }

                        if (!info.Principal.HasClaim(c => c.Type == "game-record-keeper-identity" && c.Value == "admin") &&
                            !info.Principal.HasClaim(c => c.Type == "game-record-keeper-identity" && c.Value == "player"))
                        {
                            await _userManager.AddClaimAsync(user, new Claim("game-record-keeper-identity", "player"));
                        }

                        if (!info.Principal.HasClaim(c => c.Type == "game-record-keeper-identity" && c.Value == "admin") ||
                            info.Principal.HasClaim(c => c.Type == "game-record-keeper-identity" && c.Value == "player"))
                        {
                            Player player = new Player
                            {
                                PreferredName = user.UserName,
                                Account       = user
                            };

                            _context.Players.Add(player);
                            await _context.SaveChangesAsync();
                        }

                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);

                        var userId = await _userManager.GetUserIdAsync(user);

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                        var callbackUrl = Url.Page(
                            "/Account/ConfirmEmail",
                            pageHandler: null,
                            values: new { area = "Identity", userId = userId, code = code },
                            protocol: Request.Scheme);

                        await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                          $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                        // If account confirmation is required, we need to show the link if we don't have a real email sender
                        if (_userManager.Options.SignIn.RequireConfirmedAccount)
                        {
                            return(RedirectToPage("./RegisterConfirmation", new { Email = Input.Email }));
                        }

                        await _signInManager.SignInAsync(user, isPersistent : false, info.LoginProvider);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            ProviderDisplayName = info.ProviderDisplayName;
            ReturnUrl           = returnUrl;
            return(Page());
        }