Esempio n. 1
0
        public async Task <IActionResult> PutCategorieClient(int id, CategorieClient categorieClient)
        {
            if (id != categorieClient.Id)
            {
                return(BadRequest());
            }

            _context.Entry(categorieClient).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategorieClientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
 private async Task UpdateDbWorkflow(UserWorkflow userWorkflow)
 {
     foreach (var step in userWorkflow.Steps)
     {
         if (step.TrackingState == TrackingState.Updated)
         {
             _db.Entry(step).State = EntityState.Modified;
         }
     }
     _db.Entry(userWorkflow).State = EntityState.Modified;
     await _db.SaveChangesAsync();
 }
        private async Task <bool> WriteAttempt(TekReleaseWorkflowStateEntity workflowStateEntity)
        {
            if (++_attemptCount > AttemptCountMax)
            {
                throw new InvalidOperationException("Maximum attempts reached.");
            }

            if (_attemptCount > 1)
            {
                _logger.WriteDuplicatePollTokenFound(_attemptCount);
            }

            try
            {
                await _workflowDb.SaveChangesAsync();

                _logger.WritePollTokenCommit();
                return(true);
            }
            catch (DbUpdateException ex)
            {
                if (CanRetry(ex))
                {
                    return(false);
                }

                throw;
            }
        }
Esempio n. 4
0
 private async Task WriteBucket(byte[] bucketId)
 {
     _DbContext.KeyReleaseWorkflowStates.Add(new TekReleaseWorkflowStateEntity
     {
         BucketId        = bucketId,
         ValidUntil      = DateTime.UtcNow.AddHours(1),
         Created         = DateTime.UtcNow,
         ConfirmationKey = new byte[32],
     });
     await _DbContext.SaveChangesAsync();
 }
Esempio n. 5
0
        public async Task <TEntity> DeleteAsync(Guid id, CancellationToken cancellationToken = default)
        {
            var item = await GetByIdAsync(id, cancellationToken);

            item.Deleted = true;
            await UpdateAsync(item, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(item);
        }
Esempio n. 6
0
        public async Task Execute(KeysFirstAuthorisationArgs args)
        {
            var workflow = _DbContextProvider.Set <KeyReleaseWorkflowState>()
                           .Where(x => x.LabConfirmationId == args.Token)
                           .Take(1)
                           .ToArray()
                           .SingleOrDefault();

            if (workflow == null)
            {
                //TODO log a miss.
                return;
            }

            workflow.Authorised = true;
            _DbContextProvider.Update(workflow);
            await _DbContextProvider.SaveChangesAsync();
        }
Esempio n. 7
0
        public async Task InitializeAsync()
        {
            _Connection = new SqliteConnection("Data Source=:memory:");
            _DbContext  = new WorkflowDbContext(new DbContextOptionsBuilder().UseSqlite(_Connection).Options);

            _Factory = WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddScoped(sp =>
                    {
                        var context =
                            new WorkflowDbContext(new DbContextOptionsBuilder().UseSqlite(_Connection).Options);
                        context.BeginTransaction();
                        return(context);
                    });
                });
                builder.ConfigureAppConfiguration((ctx, config) =>
                {
                    config.AddInMemoryCollection(new Dictionary <string, string>
                    {
                        ["Validation:TemporaryExposureKey:RollingPeriod:Min"] = "1",
                        ["Validation:TemporaryExposureKey:RollingPeriod:Max"] = "256"
                    });
                });
            });
            await _Connection.OpenAsync();

            await _DbContext.Database.EnsureCreatedAsync();

            // ReSharper disable once MethodHasAsyncOverload
            //TODO mapper...
            _DbContext.KeyReleaseWorkflowStates.Add(new TekReleaseWorkflowStateEntity
            {
                BucketId        = _BucketId,
                ValidUntil      = DateTime.UtcNow.AddHours(1),
                Created         = DateTime.UtcNow,
                ConfirmationKey = _Key,
            });
            await _DbContext.SaveChangesAsync();
        }
        private async Task WriteBucket(string pollToken)
        {
            var now = _FakeTimeProvider.Snapshot;

            var e = new TekReleaseWorkflowStateEntity
            {
                BucketId              = new byte[32],
                ValidUntil            = now.AddHours(1),
                Created               = now,
                ConfirmationKey       = new byte[32],
                AuthorisedByCaregiver = now,
                DateOfSymptomsOnset   = now.AddDays(-2),
                TeksTouched           = false,
                PollToken             = pollToken
            };

            _DbContext.KeyReleaseWorkflowStates.Add(e);
            await _DbContext.SaveChangesAsync();

            _BucketPk = e.Id;
        }
Esempio n. 9
0
        private static async Task TestWorkflow()
        {
            Person person = await context.People
                            .AsNoTracking()
                            .FirstOrDefaultAsync(x => x.Account == "001");

            string  title   = "送審主題" + Guid.NewGuid().ToString();
            Request request = new Request()
            {
                Title               = title,
                Description         = "申請說明",
                CurrentSigningLevel = 1,
                Note     = "",
                PersonId = person.Id,
                Status   = SigningStatus.Sending,
                Person   = null,
            };

            context.Entry(request).State = EntityState.Added;
            await context.SaveChangesAsync();

            #region 第1階主管審核
            foreach (var fooxx in context.Set <Request>().Local)
            {
                context.Entry(fooxx).State = EntityState.Detached;
            }
            Person person2 = await context.People
                             .AsNoTracking()
                             .FirstOrDefaultAsync(x => x.Account == "002");

            Request currentRequest = await context.Requests
                                     .AsNoTracking()
                                     .FirstOrDefaultAsync(x => x.Title == title);

            currentRequest.FinalSigningPersonId = person2.Id;
            currentRequest.CurrentSigningLevel++;
            currentRequest.Status = SigningStatus.Approve;
            context.Entry(currentRequest).State = EntityState.Modified;
            await context.SaveChangesAsync();

            #endregion

            #region 第2階主管審核
            foreach (var fooxx in context.Set <Request>().Local)
            {
                context.Entry(fooxx).State = EntityState.Detached;
            }
            Person person3 = await context.People
                             .AsNoTracking()
                             .FirstOrDefaultAsync(x => x.Account == "003");

            Request currentRequest2 = await context.Requests
                                      .AsNoTracking()
                                      .FirstOrDefaultAsync(x => x.Title == title);

            currentRequest2.FinalSigningPersonId = person3.Id;
            currentRequest2.CurrentSigningLevel++;
            currentRequest2.Status = SigningStatus.Approve;
            context.Entry(currentRequest2).State = EntityState.Modified;
            await context.SaveChangesAsync();

            #endregion

            #region 第3階主管審核
            foreach (var fooxx in context.Set <Request>().Local)
            {
                context.Entry(fooxx).State = EntityState.Detached;
            }
            Person person4 = await context.People
                             .AsNoTracking()
                             .FirstOrDefaultAsync(x => x.Account == "003");

            Request currentRequest3 = await context.Requests
                                      .AsNoTracking()
                                      .FirstOrDefaultAsync(x => x.Title == title);

            currentRequest3.FinalSigningPersonId = person4.Id;
            currentRequest3.CurrentSigningLevel++;
            currentRequest3.Status = SigningStatus.Approve;
            context.Entry(currentRequest3).State = EntityState.Modified;
            await context.SaveChangesAsync();

            #endregion
        }