public async Task <IActionResult> Revoke(int id) { var request = await _context.Requests.SingleAsync(r => r.Id == id); request.Approved = false; request.ApprovedComment = null; request.Submitted = false; request.SubmittedBy = null; request.SubmittedOn = null; await _context.SaveChangesAsync(); return(Json(new { success = true })); }
public async Task <IActionResult> Edit(int id, ApprovalDecisionViewModel model) { var request = await _dbContext .Requests .Include(r => r.Course) .SingleAsync(x => x.Id == id); request.Approved = model.Approved; // build comment var comment = model.Comment; if (string.Equals(model.Comment, "other", StringComparison.OrdinalIgnoreCase)) { comment += $" - {model.CommentOther}"; } request.ApprovedComment = comment; CreateApprovalHistory(request); var notificationRequest = request.ShallowCopy(); // on denial, turn this back into non-exception if (request.Approved.HasValue && request.Approved.Value == false) { request.Exception = false; request.Approved = true; } await _dbContext.SaveChangesAsync(); // send emails try { await _emailService.SendApprovalNotification(notificationRequest); } catch (Exception ex) { Log.Error(ex, "Exception throw while sending notification email."); } return(RedirectToAction("Index")); }
public async Task <IActionResult> AddUserToDepartmentRole(string userId, int departmentId) { // check for existing user first var user = await _userManager.FindByIdAsync(userId); // check email too if (user == null) { user = await _userManager.FindByEmailAsync(userId); } // check for user on directory if (user == null) { var person = await _directorySearchService.GetByKerberos(userId); if (person == null) { person = await _directorySearchService.GetByEmail(userId); } if (person == null) { ErrorMessage = "User not found."; return(RedirectToAction(nameof(DepartmentUsers))); } // create user and login var principal = new ClaimsPrincipal(); var login = new ExternalLoginInfo( principal, AspNetCore.Security.CAS.CasDefaults.AuthenticationScheme, person.Kerberos, AspNetCore.Security.CAS.CasDefaults.DisplayName); user = new User { Id = person.Kerberos, Email = person.Mail, UserName = person.Kerberos, FirstName = person.GivenName, LastName = person.Surname, Name = person.FullName, }; await _userManager.CreateAsync(user); await _userManager.AddLoginAsync(user, login); } var department = await _dbContext.Departments .Include(d => d.MemberRoles) .FirstOrDefaultAsync(d => d.Id == departmentId); _dbContext.DepartmentRoles.Add(new DepartmentRole() { User = user, Department = department, Role = "Member", }); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(DepartmentUsers))); }