コード例 #1
0
        public async Task CreateAttachedObjectUnit(CreateAttachedObjectInputUnit input)
        {
            var storedFile = new BinaryObject(AbpSession.TenantId, input.Bytes);

            var binaryObjectId = await _binaryObjectRepository.InsertAndGetIdAsync(storedFile);

            input.UserAttachmentFilesId = binaryObjectId;

            await _attachedObjectUnitManager.CreateAsync(input.MapTo <AttachedObjectUnit>());

            await _iUnitOfWork.SaveChangesAsync();
        }
コード例 #2
0
        /// <summary>
        /// Action for saving the uploaded attachment
        /// </summary>
        /// <param name="fileData"></param>
        /// <returns></returns>
        public async Task <JsonResult> UploadAttachment(UploadFileDataInput fileData)
        {
            try
            {
                int iFileCount = Request.Files.Count;
                var file       = Request.Files[0];

                //Check input
                if (iFileCount <= 0 || Request.Files[0] == null)
                {
                    throw new UserFriendlyException(L("NoFilesAttached_Message"));
                }

                var createAttachedObjectInputUnit = new CreateAttachedObjectInputUnit()
                {
                    FileName               = fileData.FileName,
                    Description            = fileData.Description,
                    TypeOfAttachedObjectId = fileData.TypeOfAttachedObjectId,
                    FileExtension          = fileData.FileExtension,
                    FileSize               = Convert.ToInt32(fileData.FileSize),
                    TypeOfObjectId         = fileData.TypeOfObjectId,
                    ObjectId               = fileData.ObjectId
                };

                using (var binaryReader = new BinaryReader(file.InputStream))
                {
                    createAttachedObjectInputUnit.Bytes = binaryReader.ReadBytes(file.ContentLength);
                }

                await _attachedObjectUnitAppService.CreateAttachedObjectUnit(createAttachedObjectInputUnit);

                return(Json(new { success = true }));
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }