private async Task <List <ImportMovement> > CaptureAddedImportMovements(CancelImportMovements message)
        {
            var result = new List <ImportMovement>();

            foreach (var addedMovement in message.AddedMovements)
            {
                var movement = await importMovementFactory.Create(message.NotificationId, addedMovement.Number,
                                                                  addedMovement.ShipmentDate, null);

                movementRepository.Add(movement);

                await context.SaveChangesAsync();

                result.Add(movement);
            }

            foreach (var movement in result)
            {
                await movementAuditRepository.Add(new ImportMovementAudit(movement.NotificationId, movement.Number,
                                                                          userContext.UserId.ToString(), (int)MovementAuditType.NoPrenotificationReceived, SystemTime.Now));
            }

            await context.SaveChangesAsync();

            return(result);
        }
        public async Task <bool> HandleAsync(CancelImportMovements message)
        {
            var movementIds = message.CancelledMovements.Select(m => m.Id).ToList();

            movementIds.AddRange((await CaptureAddedImportMovements(message)).Select(m => m.Id));

            var movements =
                (await movementRepository.GetImportMovementsByIds(message.NotificationId, movementIds)).ToList();

            foreach (var movement in movements)
            {
                await cancelMovement.Cancel(movement.Id);
            }

            await context.SaveChangesAsync();

            foreach (var movement in movements)
            {
                await
                repository.Add(new ImportMovementAudit(message.NotificationId, movement.Number,
                                                       userContext.UserId.ToString().ToUpper(), (int)MovementAuditType.Cancelled,
                                                       SystemTime.Now.AddSeconds(AuditTimeOffSet)));
            }

            await context.SaveChangesAsync();

            return(true);
        }
Example #3
0
        public async Task <bool> HandleAsync(AuditImportMovement message)
        {
            await repository.Add(mapper.Map <ImportMovementAudit>(message));

            await context.SaveChangesAsync();

            return(true);
        }