Example #1
0
        public async Task <IActionResult> GraduateUsers(int id)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var allUsers = _repo.GetAllUsers();

            foreach (var user in allUsers)
            {
                switch (user.StudentLevel)
                {
                case "sophomore":
                    user.StudentLevel = "junior";
                    break;

                case "junior":
                    user.StudentLevel = "senior";
                    break;

                case "senior":
                    user.StudentLevel = null;
                    break;
                }
            }

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception("Graduating Students Failed");
        }