public AuthStatusModel GetAuthStatus() { AuthStatusModel status = new AuthStatusModel { IsAuthenticated = false }; try { status.IsAuthenticated = User.Identity.IsAuthenticated; return(status); } catch (Exception ex) { _logger.LogError(ex, $"{nameof(GetAuthStatus)} => FAIL"); } return(status); }
public async Task <IActionResult> CreateAuthorizerStatus([FromBody] AuthStatusModel model, string authorizerCode) { var userId = GetUserId(); var endPointId = await GetEndPointId(); if (!ModelState.IsValid) { return(BadRequest("Invalid Parameters...")); } else { var emailAddress = await _emailAddressRepository.SendEmailAddress(model.BatchId); // if authorizerstatus was not selected if (model.Status == 0) { return(BadRequest(new { message = "Status was not selected" })); } var tblStaff = await _staffRepository.FirstOrDefaultAsync(x => x.AspnetUserId == userId); // if authorizer Rejects if (model.Status == 3) { var audit = new TblAuthList { Title = model.Title, Url = model.Url, CreatedDate = DateTime.Now, Status = model.Status, StaffId = tblStaff.StaffId, BatchId = model.BatchId }; var newAuthApprover = new TblAuthApprover { AuthId = audit.AuthId, CreatedDate = DateTime.Now, Status = model.Status, Reason = model.Reason, StaffId = tblStaff.StaffId, }; await _authApproverRepository.CreateAsync(newAuthApprover); } // if authorizer approves if (model.Status == 2) { var codes = _codeGeneratorRepository.FindAsync(x => x.GeneratedCode == authorizerCode).Result.FirstOrDefault(); if (codes == null) { return(BadRequest(new { message = "Code is invalid" })); } if (codes != null) { codes.Status = 1; _codeGeneratorRepository.Update(codes); var audit = new TblAuthList { Title = model.Title, Url = model.Url, CreatedDate = DateTime.Now, Status = model.Status, StaffId = tblStaff.StaffId, BatchId = model.BatchId }; var newAuthApprover = new TblAuthApprover { AuthId = audit.AuthId, CreatedDate = DateTime.Now, Status = model.Status, Reason = model.Reason, StaffId = tblStaff.StaffId, }; await _authApproverRepository.CreateAsync(newAuthApprover); } } // if authorizer reviews if (model.Status == 1) { var audit = new TblAuthList { Title = model.Title, Url = model.Url, CreatedDate = DateTime.Now, Status = model.Status, StaffId = tblStaff.StaffId, BatchId = model.BatchId }; var newAuthApprover = new TblAuthApprover { AuthId = audit.AuthId, CreatedDate = DateTime.Now, Status = model.Status, Reason = model.Reason, StaffId = tblStaff.StaffId, }; await _authApproverRepository.CreateAsync(newAuthApprover); } await _authApproverRepository.SaveChangesAsync(); return(Ok(new { message = "Authorizer status registered...", EmailAddress = emailAddress, StatusReason = model.Reason })); } }
public async Task <IActionResult> CreateCheckerStatus([FromBody] AuthStatusModel model) { var userId = GetUserId(); var endPointId = await GetEndPointId(); if (!ModelState.IsValid) { return(BadRequest("Invalid Parameters...")); } else { // email address to initiator var emailAddress = await _emailAddressRepository.SendEmailAddress(model.BatchId); // if checker status was not selected if (model.Status == 0) { return(BadRequest(new { message = "Status was not selected" })); } var tblStaff = await _staffRepository.FirstOrDefaultAsync(x => x.AspnetUserId == userId); // if checker rejects if (model.Status == 3) { var audit = new TblAuthList { Title = model.Title, Url = model.Url, CreatedDate = DateTime.Now, Status = model.Status, StaffId = tblStaff.StaffId, BatchId = model.BatchId }; await _auditRepository.CreateAsync(audit); var newAuthChecker = new TblAuthChecker { AuthId = audit.AuthId, CreatedDate = DateTime.Now, Status = model.Status, Reason = model.Reason, StaffId = tblStaff.StaffId, }; await _authCheckerRepository.CreateAsync(newAuthChecker); } // if checker approves if (model.Status == 2) { var audit = new TblAuthList { Title = model.Title, Url = model.Url, CreatedDate = DateTime.Now, Status = model.Status, StaffId = tblStaff.StaffId, BatchId = model.BatchId }; await _auditRepository.CreateAsync(audit); var newAuthChecker = new TblAuthChecker { AuthId = audit.AuthId, CreatedDate = DateTime.Now, Status = model.Status, Reason = model.Reason, StaffId = tblStaff.StaffId, }; await _authCheckerRepository.CreateAsync(newAuthChecker); emailAddress = await _emailAddressRepository.SendEmailAddress(endPointId, 2); } // if checker reviews if (model.Status == 1) { var audit = new TblAuthList { Title = model.Title, Url = model.Url, CreatedDate = DateTime.Now, Status = model.Status, StaffId = tblStaff.StaffId, BatchId = model.BatchId }; await _auditRepository.CreateAsync(audit); var newAuthChecker = new TblAuthChecker { AuthId = audit.AuthId, CreatedDate = DateTime.Now, Status = model.Status, Reason = model.Reason, StaffId = tblStaff.StaffId, }; await _authCheckerRepository.CreateAsync(newAuthChecker); _auditRepository.Update(audit); } await _auditRepository.SaveChangesAsync(); return(Ok(new { message = "Checker status registered...", EmailAddress = emailAddress, StatusReason = model.Reason })); } }