public override async Task DeleteAsync(object key) { var version = await _dbContext.ScriptVersion.FindAsync(key); version.IsDeleted = true; await _dbContext.SaveChangesAsync(); }
public override async Task <Db.Models.Script> PatchAsync(Delta <Db.Models.Script> obj, object key) { var entity = await _dbContext.Script.FindAsync(key); if (entity == null) { return(null); } obj.Patch(entity); entity.Modified = DateTime.UtcNow; entity.ModifiedByUserId = _ephItUser.Register().UserId; await _dbContext.SaveChangesAsync(); return(entity); }
public Task LogAsync(Guid jobUid, string message, JobLogLevelEnum level, string Exception = null) { var newJobLog = new JobLog(); newJobLog.JobLogId = Guid.NewGuid(); newJobLog.Exception = Exception; newJobLog.JobUid = jobUid; newJobLog.LevelId = (short)level; newJobLog.LogTime = DateTime.UtcNow; newJobLog.Message = message; _context.Add(newJobLog); return(_context.SaveChangesAsync()); }
public async Task <int> NewAsync(string name, string description) { var userId = _ephItUser.Register().UserId; // This will return the new scriptId and then the Blazor site will // Immediately redirect from the "new" page to the "Details" page of this // Script - so we want to ensure they have permission to it. var userRoleId = await _dbContext.RoleObjectAction .Where(p => p.RbacActionId.Equals((short)RBACActionEnum.Create) && p.RbacObjectId.Equals((short)RBACObjectsId.Scripts) && p.Role.RoleMembershipUser.Where(us => us.UserId.Equals(userId)).Any() ) .Select(p => p.RoleId) .FirstAsync(); var newScript = new EphIt.Db.Models.Script { Created = DateTime.UtcNow, CreatedByUserId = userId, Description = description, Name = name, Modified = DateTime.UtcNow, ModifiedByUserId = userId }; _dbContext.Add(newScript); await _dbContext.SaveChangesAsync(); var roleAsyncTask = AssociateWithRoleAsync(newScript.ScriptId, userRoleId); var auditTask = _auditLogger.AuditLog(AuditObject.Script, AuditAction.Create, AuditStatus.Success, newScript.ScriptId); await Task.WhenAll(roleAsyncTask, auditTask); return(newScript.ScriptId); }
public async Task <ActionResult <Guid> > NewOutputAsync([FromBody] JobOutputPostParameters jobOutputPostParameters) { JobOutput output = new JobOutput(); output.ByteArrayValue = jobOutputPostParameters.ByteArrayValue; output.JobUid = jobOutputPostParameters.JobUid; output.JsonValue = jobOutputPostParameters.JsonValue; output.OutputTime = DateTime.UtcNow; output.JobOutputId = Guid.NewGuid(); output.Type = jobOutputPostParameters.Type; await _dbContext.JobOutput.AddAsync(output); await _dbContext.SaveChangesAsync(); return(output.JobOutputId); }