public async Task <IActionResult> ChangeRole([FromBody] Roles roles) { string role = await _appDbContext.GetRoleByToken(Request.Headers["Authorization"]); if (role.ToLower() == "admin") { _log.LogInfo("Get new role."); if (!ModelState.IsValid) { _log.LogError("Incorrect input."); return(BadRequest(ModelState)); } if (await _appDbContext.ChangeRole(roles) == null) { _log.LogError("Incorrect role."); return(BadRequest(Errors.AddErrorToModelState("rolesFailure", "Invalid role.", ModelState))); } _log.LogInfo("Changing role."); await _appDbContext.ChangeRole(roles); string roleChangeText; using (StreamReader streamreader = new StreamReader(@"..\EHospital.Authorization.WebAPI\Letters\roleChange.txt")) { roleChangeText = streamreader.ReadToEnd(); } string email = await _appDbContext.GetEmail(roles); await emailSender.SendEmail(email, "Free access", roleChangeText); return(Ok()); } return(BadRequest(role)); }