Esempio n. 1
0
        public async Task <Unit> Handle(DeleteAppealFileCommand request, CancellationToken cancellationToken)
        {
            var upload = await _appealFileRepository.Get(request.ApplicationId, request.FileName);

            if (upload is null)
            {
                throw new InvalidOperationException($"Appeal file {request.FileName} does not belong to Application {request.ApplicationId}");
            }

            _auditService.StartTracking(UserAction.RemoveAppealFile, request.UserId, request.UserName);

            _auditService.AuditDelete(upload);
            _appealFileRepository.Remove(upload.Id);

            _auditService.Save();

            return(Unit.Value);
        }
        public async Task <Unit> Handle(UploadAppealFileCommand request, CancellationToken cancellationToken)
        {
            _auditService.StartTracking(UserAction.UploadAppealFile, request.UserId, request.UserName);

            var appealFile = await _appealFileRepository.Get(request.ApplicationId, request.AppealFile.FileName);

            if (appealFile is null)
            {
                appealFile = new AppealFile
                {
                    ApplicationId = request.ApplicationId,
                    ContentType   = request.AppealFile.ContentType,
                    FileName      = request.AppealFile.FileName,
                    Size          = request.AppealFile.Data.Length,
                    UserId        = request.UserId,
                    UserName      = request.UserName
                };

                _auditService.AuditInsert(appealFile);
                _appealFileRepository.Add(appealFile);
            }
            else
            {
                _auditService.AuditUpdate(appealFile);

                appealFile.ContentType = request.AppealFile.ContentType;
                appealFile.Size        = request.AppealFile.Data.Length;
                appealFile.UserId      = request.UserId;
                appealFile.UserName    = request.UserName;
                appealFile.CreatedOn   = DateTime.UtcNow;

                _appealFileRepository.Update(appealFile);
            }

            _auditService.Save();

            return(await Task.FromResult(Unit.Value));
        }