Beispiel #1
0
        public async Task <IActionResult> PutEmployee(int id, Employee emp)
        {
            if (emp == null)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #2
0
        public async Task <ActionResult <UserWithToken> > Login([FromBody] User user)
        {
            user = await _context.Users.Where(u => u.EmailAddress == user.EmailAddress &&
                                              u.Password == user.Password).FirstOrDefaultAsync();

            UserWithToken userWithToken = null;

            if (user != null)
            {
                RefreshToken refreshToken = GenerateRefreshToken();
                user.RefreshTokens.Add(refreshToken);
                await _context.SaveChangesAsync();

                userWithToken = new UserWithToken(user);
                userWithToken.RefreshToken = refreshToken.Token;
            }

            if (userWithToken == null)
            {
                return(NotFound());
            }

            userWithToken.AccessToken = GenerateAccessToken(user.UserId);
            return(userWithToken);
        }