public virtual int CreateDynamicModuleBlob(
            int dynamicModuleId,
            DynamicModuleBlobEnum dynamicModuleBlobEnum,
            string fileExtension,
            Action <FileResourceEntity> persistStream
            )
        {
            var dynamicModule = GetById(dynamicModuleId);

            var fileResourceId = m_fileResourceRepository.CreateExternal(fileExtension);

            var fileResource = m_fileResourceRepository.GetFileResource(fileResourceId);

            var dynamicModuleBlobEntity = new DynamicModuleBlobEntity
            {
                DynamicModule = dynamicModule,
                Type          = dynamicModuleBlobEnum,
                File          = fileResource,
                LastChange    = DateTime.UtcNow,
            };

            var result = (int)m_dynamicModuleRepository.Create(dynamicModuleBlobEntity);

            persistStream(fileResource);

            return(result);
        }
        public DataResult <int> CreateDynamicModuleBlob(
            int dynamicModuleId,
            DynamicModuleBlobEnum dynamicModuleBlobEnum,
            Stream fileStream,
            string fileExtension
            )
        {
            try
            {
                var result = m_dynamicModuleUoW.CreateDynamicModuleBlob(
                    dynamicModuleId,
                    dynamicModuleBlobEnum,
                    fileExtension,
                    fileResourceEntity =>
                {
                    var model = m_mapper.Map <FileResourceModel>(fileResourceEntity);

                    using (var writeStream = m_fileResourceManager.GetWriteStream(model))
                    {
                        fileStream.CopyTo(writeStream);
                    }
                }
                    );

                return(Success(result));
            }
            catch (DatabaseException e)
            {
                m_logger.LogWarning(e);

                return(Error <int>(e.Message));
            }
        }
        public DynamicModuleBlobEntity GetByModuleIdAndType(int moduleId, DynamicModuleBlobEnum dynamicModuleBlobEnum)
        {
            var criterion = Restrictions.Where <DynamicModuleBlobEntity>(
                x => x.DynamicModule.Id == moduleId && x.Type == dynamicModuleBlobEnum
                );

            try
            {
                return(GetSingleValue <DynamicModuleBlobEntity>(FetchCollections, criterion));
            }
            catch (HibernateException ex)
            {
                throw new DatabaseException("Get DynamicModuleBlob by id failed", ex);
            }
        }
        public virtual DynamicModuleBlobEntity GetDynamicModuleBlob(int dynamicModuleId, DynamicModuleBlobEnum dynamicModuleBlobEnum)
        {
            var dynamicModuleBlob = m_dynamicModuleBlobRepository.GetByModuleIdAndType(dynamicModuleId, dynamicModuleBlobEnum);

            return(dynamicModuleBlob);
        }
        public DataResult <DynamicModuleBlobModel> GetDynamicModuleBlob(int dynamicModuleId, DynamicModuleBlobEnum dynamicModuleBlobEnum)
        {
            try
            {
                var dynamicModuleBlobEntity = m_dynamicModuleUoW.GetDynamicModuleBlob(dynamicModuleId, dynamicModuleBlobEnum);

                var model = m_mapper.Map <DynamicModuleBlobModel>(dynamicModuleBlobEntity);

                return(Success(model));
            }
            catch (NoResultException <DynamicModuleBlobModel> e)
            {
                m_logger.LogWarning(e);
                return(Error <DynamicModuleBlobModel>(
                           m_translator.Translate("invalid-dynamic-module-id"),
                           DataResultErrorCode.DynamicModuleNotExistId
                           ));
            }
            catch (DatabaseException e)
            {
                m_logger.LogWarning(e);
                return(Error <DynamicModuleBlobModel>(e.Message));
            }
        }