Ejemplo n.º 1
0
        public async Task <IActionResult> UploadAttachment(string id, [FromForm] FileCreateRequest req)
        {
            var ownerId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            //Check if bill exists for the owner
            var bill = await _billService.GetBill(ownerId, id);

            if (bill == null)
            {
                return(NotFound(new { message = "Bill not found." }));
            }

            //Upload the file
            GetObjectResponse fileInfo = await _fileService.UploadBillAttachment(id, req.file);

            if (fileInfo == null)
            {
                return(BadRequest(new { message = "Bill attachment could not be uploaded." }));
            }

            //File Uploaded Succesfully, Update the database
            var attachment = await _billService.StoreAttachment(id, fileInfo);

            if (attachment == null)
            {
                return(BadRequest(new { message = "Error saving attachment information." }));
            }

            return(Created(string.Empty, attachment));
        }
        public async Task <CampaignServiceErrorResponseModel> AddImage(FileCreateRequest model)
        {
            try
            {
                var file = _mapper.Map <FileModel>(model);

                await _burnRuleService.SaveBurnRuleContentImage(file);

                return(new CampaignServiceErrorResponseModel()
                {
                    ErrorCode = CampaignServiceErrorCodes.None
                });
            }
            catch (RuleConditionNotFileException ex)
            {
                _log.Info(string.Format(Phrases.InvalidContentType), context: model.RuleContentId);

                return(new CampaignServiceErrorResponseModel()
                {
                    ErrorCode = CampaignServiceErrorCodes.NotValidRuleContentType,
                    ErrorMessage = ex.Message
                });
            }
            catch (EntityNotFoundException e)
            {
                _log.Info(string.Format(Phrases.EntityWithIdNotFound, "Burn rule", model.RuleContentId), context: model.RuleContentId);

                return(new CampaignServiceErrorResponseModel()
                {
                    ErrorCode = CampaignServiceErrorCodes.EntityNotFound,
                    ErrorMessage = e.Message
                });
            }
            catch (NotValidFormatFile ex)
            {
                _log.Info(string.Format(Phrases.NotValidFormatFile), context: model.Type);

                return(new CampaignServiceErrorResponseModel()
                {
                    ErrorCode = CampaignServiceErrorCodes.NotValidFileFormat,
                    ErrorMessage = ex.Message
                });
            }
        }
        public void SetUp()
        {
            dbToDtoMapper     = new FileMapper();
            requestToDbMapper = new FileMapper();

            fileRequest = new FileCreateRequest
            {
                Content   = "RGlnaXRhbCBPZmA5Y2U=",
                Extension = ".txt",
                Name      = "DigitalOfficeTestFile"
            };

            dbFile = new DbFile
            {
                Id        = Guid.NewGuid(),
                Content   = Convert.FromBase64String("RGlnaXRhbCBPZmA5Y2U="),
                Extension = ".txt",
                IsActive  = true,
                Name      = "DigitalOfficeTestFile"
            };
        }
Ejemplo n.º 4
0
        public byte[] GetZippedContent(bool includeDockerFile = false)
        {
            using (var m = new MemoryStream())
            {
                using (var zip = new ZipArchive(m, ZipArchiveMode.Create))
                {
                    foreach (var request in ContentFiles)
                    {
                        AddToZip(zip, request);
                    }

                    if (includeDockerFile)
                    {
                        var request = new FileCreateRequest("Dockerfile", Code);
                        AddToZip(zip, request);
                    }
                }

                return(m.ToArray());
            }
        }
        public void ShouldThrowArgumentNullExceptionWhenRequestMappingObjectIsNull()
        {
            fileRequest = null;

            Assert.Throws <ArgumentNullException>(() => requestToDbMapper.Map(fileRequest));
        }