예제 #1
0
        public long Add(ArquivoAddCommand arquivo)
        {
            var _produto    = Mapper.Map <ArquivoAddCommand, Arquivo>(arquivo);
            var novoProduto = _ArquivoRepository.Add(_produto);

            return(novoProduto.Id);
        }
예제 #2
0
        public OperationResultVo <Guid> Add(ArquivoViewModel viewModel)
        {
            OperationResultVo <Guid> result;

            try
            {
                Arquivo model;

                // TODO validate before

                Arquivo existing = _repository.GetById(viewModel.Id);
                if (viewModel.Id != Guid.Empty && existing != null)
                {
                    return(new OperationResultVo <Guid>("Erro ao adicionar Arquivo"));
                }

                model = _mapper.Map <Arquivo>(viewModel);

                _repository.Add(model);
                viewModel.Id = model.Id;

                _unitOfWork.Commit();

                result = new OperationResultVo <Guid>(model.Id);
            }
            catch (Exception ex)
            {
                result = new OperationResultVo <Guid>(ex.Message);
            }

            return(result);
        }
        public async Task <int> UploadAsync(IFormFile file, int IDInstituicaoProjeto, int iTipo)
        {
            if (file == null)
            {
                throw new Exception("File is null");
            }
            if (file.Length == 0)
            {
                throw new Exception("File is empty");
            }

            try
            {
                using (Stream stream = file.OpenReadStream())
                {
                    using (var binaryReader = new BinaryReader(stream))
                    {
                        var      fileContent = binaryReader.ReadBytes((int)file.Length);
                        string   sTipo;
                        string[] aFoto = file.FileName.Split('.');

                        Arquivo _arquivoProjeto = new Arquivo
                        {
                            sNome                = aFoto[0],
                            sNomebase            = IDInstituicaoProjeto + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + aFoto[aFoto.Count() - 1],
                            IDInstituicaoProjeto = IDInstituicaoProjeto,
                            iTipo                = iTipo
                        };

                        _arquivoRepository.Add(_arquivoProjeto);

                        if (iTipo == 1)
                        {
                            sTipo = "INSTITUICAO";
                        }
                        else
                        {
                            sTipo = "PROJETO";
                        }

                        await Diversos.SaveImage(file, sTipo, _arquivoProjeto.sNomebase);
                    }
                }

                return(1);
            }
            catch (Exception)
            {
                return(0);
            }
        }
예제 #4
0
        public async Task <IActionResult> Post()
        {
            using (var ms = new MemoryStream())
            {
                IFormFile file = Request.Form.Files[0];
                file.CopyTo(ms);
                var fileBytes = ms.ToArray();

                var arquivo = new Arquivo
                {
                    Id          = Guid.NewGuid(),
                    FileName    = file.FileName,
                    ContentType = file.ContentType,
                    Bytes       = fileBytes
                };


                var result = await _arquivoRepository.Add(arquivo);

                return(Ok($"v1/arquivo/{arquivo.Id}"));
            }
        }