Esempio n. 1
0
        public async Task <IActionResult> DeleteUser(string username)
        {
            try
            {
                //manager status
                var loggedInUser = await _userRepository.GetUser(_userAccessor.GetCurrentUsername());

                if (loggedInUser.Manager == false)
                {
                    return(Unauthorized(new RestError(HttpStatusCode.Unauthorized, new { Unauthorized = "Unauthorized to perform action" })));
                }

                //find user
                var user = await _userRepository.GetUser(username);

                if (user == null)
                {
                    return(NotFound($"Username {username} not found."));
                }

                //delete user
                await _timestampRepository.DeleteAllUserTimestamps(user);

                await _userRepository.DeleteUser(user);

                return(Ok($"{username} deleted."));
            } catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Server Error: Failed to communicate with database"));
            }
        }