Beispiel #1
0
        public IActionResult Upload([FromBody] ReqFile reqFile)
        {
            try
            {
                string userId = User.FindFirst(ClaimTypes.PrimarySid).Value;

                var bytes = Convert.FromBase64String(reqFile.Base64);
                bytes = _fileService.AsJpeg(bytes);
                bytes = _fileService.Resize(bytes, 500);
                bytes = _fileService.Compress(bytes);

                var fileGuid = _fileService.Upload(userId, bytes, reqFile.Type);
                return(Ok(fileGuid.ToString()));
            }
            catch
            {
                return(BadRequest());
            }
        }
        public RegisteredAnimal Add(string userId, RegisteredAnimal animal)
        {
            animal.UploadDate = DateTimeOffset.Now;
            var databaseLayerAnimal = RegisteredAnimalMapper.StoD(animal);
            var addedAnimal         = _registeredAnimalProvider.Add(databaseLayerAnimal);

            QRCodeData qrCodeData  = _qrGenerator.CreateQrCode(addedAnimal.Id.ToString(), QRCodeGenerator.ECCLevel.Q);
            QRCode     qrCode      = new QRCode(qrCodeData);
            Bitmap     qrCodeImage = qrCode.GetGraphic(20);

            var qrId = _fileService.Upload(userId, _fileService.AsJpeg(qrCodeImage), "image/jpeg");

            addedAnimal.QR     = qrId.ToString();
            addedAnimal.UserId = userId;
            _registeredAnimalProvider.Update(addedAnimal);

            _unitOfWork.Commit();

            return(RegisteredAnimalMapper.DtoS(addedAnimal));
        }