Exemple #1
0
        public async Task <Response <HttpResponseMessage> > Handle(CreatePrintWorkCommand request, CancellationToken cancellationToken)
        {
            var uploadPrintWorkCommand = new UploadPrintWorkCommand();

            uploadPrintWorkCommand.File = request.File;
            var fileUploadResult = await _uploadPrintWorkCommand.Handle(uploadPrintWorkCommand, cancellationToken);

            if (fileUploadResult.Succeeded)
            {
                var printWork = _mapper.Map <PrintWork>(request);
                await _printWorkRepository.AddAsync(printWork);

                return(new Response <HttpResponseMessage>(new HttpResponseMessage(HttpStatusCode.Created), "PrintWorkId: " + printWork.Id));
            }
            else
            {
                return(new Response <HttpResponseMessage>(new HttpResponseMessage(HttpStatusCode.BadRequest), string.Join(',', fileUploadResult.Errors)));
            }
        }
Exemple #2
0
        public async Task <Response <byte[]> > Handle(UploadPrintWorkCommand request, CancellationToken cancellationToken)
        {
            var file = request.File;

            if (file.Length > _configuration.GetValue <long>("MaxFileSize"))
            {
                return(new Response <byte[]>("File size too big."));
            }

            if (file.Length == 0)
            {
                return(new Response <byte[]>("File size is zero"));
            }

            byte[] fileBytes;
            using (var ms = new MemoryStream())
            {
                file.CopyTo(ms);
                fileBytes = ms.ToArray();
            }
            return(new Response <byte[]>(fileBytes));
        }