public ActionResult AddTransactionPurpose(TransactionPurpose transactionPurpose) { if (ModelState.IsValid) { if (transactionPurpose.Id == 0) { Repository.Instance.Insert(transactionPurpose, true); } else { Repository.Instance.Update(transactionPurpose); Repository.Instance.Commit(); } return(RedirectToAction("TransactionPurposes")); } return(View()); }
protected override async Task OnRecordTransactionStartAsync(Common.Tracking.TrackingContext context) { Ef.Entities.Transaction tx = await _dbContext.Transactions.FirstOrDefaultAsync(t => t.TransactionId == context.Request.TransactionId); if (null == tx) { string key = string.Empty, uri = string.Empty; FormattedProcessRequest.SecretEvent evnt = FormattedProcessRequest.SecretEvent.Unknown; FormattedProcessRequest.RequestedAction action = FormattedProcessRequest.RequestedAction.Unknown; TransactionPurpose purpose = TransactionPurpose.Unknown; FormattedProcessRequest fpr = context.Request as FormattedProcessRequest; if (null == fpr) { fpr = (context.Request as RawProcessRequest)?.FormatRequest(); } if (null != fpr) { uri = fpr.ObjectUri; evnt = fpr.Event; action = fpr.Action; purpose = TransactionPurpose.ExecuteRotationProcess; } if (context.Request is RawProcessRequest) { action = FormattedProcessRequest.RequestedAction.Unknown; purpose = TransactionPurpose.ProcessKVEvent; } if (!string.IsNullOrWhiteSpace(uri)) { var s = SecretManagement.Contracts.Data.SecretBase.FromKeyvaultUri(uri); if (null != s) { key = s.Key; } } tx = new Ef.Entities.Transaction() { TransactionId = context.Request.TransactionId, SecretKey = key, SecretUri = uri, Action = action, Event = evnt, Purpose = purpose }; if (context.Request.ParentTransactionId != Guid.Empty) { tx.ParentTransaction = await _dbContext.Transactions.FirstOrDefaultAsync(t => t.TransactionId == context.Request.ParentTransactionId); } _dbContext.Transactions.Add(tx); } Ef.Entities.Attempt attempt = new Ef.Entities.Attempt() { StartingStatus = context.Result.Status, StartTimeUtc = context.StartTime, Transaction = tx }; List <Ef.Entities.Attempt> attempts = tx.Attempts?.ToList(); if (null == attempts) { attempts = new List <Ef.Entities.Attempt>(); } attempts.Add(attempt); tx.Attempts = attempts; _dbContext.Attempts.Add(attempt); await _dbContext.SaveChangesAsync(); context.TrackingState.Add(this, attempt.AttemptId); }