Example #1
0
        public async Task <IActionResult> Delete(long id)
        {
            User user = await _userService.GetByIdAsync(id);

            if (user == null)
            {
                return(NotFound());
            }
            if (user.IsSuperAdmin)
            {
                return(BadRequest("Super admin darf nicht gelöscht werden!"));
            }
            await modService.RemoveUserForeignKeys(user);

            await _userService.DeleteUserAsync(user);

            return(Ok());
        }
Example #2
0
        /// <summary>
        /// Prüfroutine um zu checken ob der letzte Login-Zeitpunkt eines Users länger als ein konfigurierbarer Zeitraum in der Vergangenheit liegt
        /// </summary>
        /// <returns></returns>
        public async Task CheckAllUsersAsync()
        {
            TimeSpan inactiveSince = TimeSpan.FromDays(1095);

            TimeSpan.TryParse(configuration["DeleteInactiveUsers:InactiveSince"], out inactiveSince);

            List <User> allUsers = await userService.GetAllUsersAsync();

            foreach (User user in allUsers)
            {
                if (user.Id != 1 && !user.IsDeleted && user.LastLoginDate.AddDays(inactiveSince.TotalDays) < DateTime.Now)
                {
                    await modificationEntryService.RemoveUserForeignKeys(user);

                    await userService.DeleteUserAsync(user);
                }
            }
        }