Exemplo n.º 1
0
        public async Task <Guid> UpdateAuditLog(Guid auditLogId, OpenLockResult result)
        {
            try
            {
                var UpdateAuditLogServiceUri = new Uri($"/api/v1/AuditLogs/{auditLogId}/{result}", UriKind.Relative);
                //var auditLog = new AuditLog(auditLogId, result.ToString());

                var response = await HttpClient.PutAsync(UpdateAuditLogServiceUri, null);

                response.EnsureSuccessStatusCode();

                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsAsync <Guid>());
                }
                else
                {
                    return(Guid.Empty);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error in  UpdateAuditLog", ex.Message);
            }
            return(Guid.Empty);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Lock([FromBody] OpenLockInfo openLockInfo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var            result        = new LockingResult();
            OpenLockResult lockingResult = new OpenLockResult();

            try
            {
                _logger.LogInformation($"User {openLockInfo.UserId} request {"Open"} Lock with Id= {openLockInfo.LockId}");

                Guid auditLogId = await _auditLogService.LogLockRequest(openLockInfo.LockId,
                                                                        openLockInfo.UserId, Model.LockCommand.Open);

                if (_userAccessService.HasAccess(openLockInfo.UserId, openLockInfo.LockId).Result)
                {
                    lockingResult = await _lockingService.OpenLock(openLockInfo.LockId);

                    var auditsult = await _auditLogService.LogLockResult(auditLogId, lockingResult);

                    if (lockingResult == OpenLockResult.Opened)
                    {
                        _logger.LogInformation($"Request {"Open"} for Lock with Id={openLockInfo.LockId} has been successful.");
                        return(Ok(new LockOpenSuccessful()));
                    }
                    else
                    {
                        _logger.LogWarning($"Request {"Open"} for Lock with Id={openLockInfo.LockId} has been faild.");
                        return(Ok(new LockOpenFailed()));
                    }
                }
                else
                {
                    var auditsult = await _auditLogService.LogLockResult(auditLogId, OpenLockResult.UserAccessDenied);

                    return(Ok(new UserAccessDenied()));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error in Lock Service API");
                return(Ok(new LockingResult(-1, "Internal Error")));
            }
        }
Exemplo n.º 3
0
 public async Task <Guid> LogLockResult(Guid auditLogId, OpenLockResult result)
 {
     return(await _auditLogHttpClient.UpdateAuditLog(auditLogId, result));
 }