Пример #1
0
        /// <summary>
        /// 雲端版APP專用
        /// </summary>
        /// <param name="circleKey"></param>
        /// <param name="token"></param>
        /// <param name="files"></param>
        /// <returns></returns>
        public Infrastructure.BusinessObject.MaterialEvent AddFile(string circleKey, string token, HttpFileCollection files)
        {
            var tokenService          = new TokenService();
            var checkToken            = tokenService.GetTokenInfo(token).Result;
            var learningcircleService = new LearningCircleService();
            var learningcircleinfo    = learningcircleService.GetDetailByOuterKey(circleKey);

            var createDateTime = DateTime.UtcNow;

            if (checkToken == null)
            {
                return(null);
            }
            var fileService = new FileService();
            var newFiles    = fileService.UploadFile(checkToken.MemberId, files);
            var file        = newFiles.FirstOrDefault();

            if (file == null)
            {
                return(null);
            }
            try
            {
                var db             = _uow.DbContext;
                var materialEntity = new Infrastructure.Entity.ActMaterial()
                {
                    LearningId        = learningcircleinfo.Id,
                    Name              = file.Name,
                    EventId           = file.FileGuid,
                    CreateUser        = checkToken.MemberId,
                    Created           = Infrastructure.Property.TimeData.Create(createDateTime),
                    Updated           = Infrastructure.Property.TimeData.Create(null),
                    Deleted           = Infrastructure.Property.TimeData.Create(null),
                    GoogleDriveFileId = file.FileGuid.ToString("N"),
                    FileImgUrl        = string.Format("{0}api/imgFile/{1}/{2}/{3}", loginServer, file.FileGuid.ToString("N"), maxImgWidth, maxImgHeight),
                    FileLength        = file.FileSize,
                    FileType          = file.FileContentType,
                    Visibility        = true
                };
                var activityEntity = new Activitys()
                {
                    CardisShow  = true,
                    CreateUser  = checkToken.MemberId,
                    Created     = Infrastructure.Property.TimeData.Create(createDateTime),
                    Updated     = Infrastructure.Property.TimeData.Create(null),
                    Deleted     = Infrastructure.Property.TimeData.Create(null),
                    OuterKey    = file.FileGuid,
                    Publish_Utc = createDateTime,
                    ToRoomId    = circleKey,
                    ModuleKey   = Utility.ParaCondition.ModuleType.Material,
                    StartDate   = createDateTime,
                    IsActivity  = true
                };
                db.ActMaterial.Add(materialEntity);
                db.Activitys.Add(activityEntity);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(null);

                throw ex;
            }
            var memberService = new MemberService();
            var memberInfo    = memberService.UserIdToAccount(checkToken.MemberId);

            var response = new Infrastructure.BusinessObject.MaterialEvent()
            {
                ClassId       = circleKey,
                CreateAccount = memberInfo.Account,
                Creator       = memberInfo.Id.ToString(),
                OuterKey      = file.FileGuid,
                CreateDate    = createDateTime
            };

            return(response);
        }
Пример #2
0
        /// <summary>
        /// 新增一筆上傳檔案活動
        /// </summary>
        /// <param name="circleKey"></param>
        /// <param name="memberId"></param>
        /// <param name="name"></param>
        /// <param name="googleDriveFileId"></param>
        /// <param name="folderId"></param>
        /// <param name="fileType"></param>
        /// <param name="fileSize"></param>
        /// <param name="fileShortImg"></param>
        /// <returns></returns>
        public Infrastructure.BusinessObject.MaterialEvent Add(string circleKey, int memberId, string name, string googleDriveFileId, string folderId, string fileType, int fileSize, string fileShortImg)
        {
            Guid     eveId = Guid.NewGuid();
            DateTime?dt    = DateTime.UtcNow;
            int      id    = cacheService.GetCircle(circleKey).Id;

            using (var db = _uow.DbContext)
            {
                using (var dbTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        #region // 1. 建立上傳檔案活動物件
                        var objMaterial = new ActMaterial()
                        {
                            LearningId        = id,
                            Name              = name,
                            EventId           = eveId,
                            CreateUser        = memberId,
                            Created           = Infrastructure.Property.TimeData.Create(dt),
                            Updated           = Infrastructure.Property.TimeData.Create(null),
                            Deleted           = Infrastructure.Property.TimeData.Create(null),
                            GoogleDriveFileId = googleDriveFileId,
                            FileImgUrl        = string.Format("https://drive.google.com/a/g.scenet.pccu.edu.tw/uc?id={0}&export=download", googleDriveFileId),
                            FileLength        = fileSize,
                            FileType          = fileType,
                            GoogleDriveFolder = folderId
                        };
                        #endregion

                        #region // 2. 替上傳檔案活動建立一筆訊息物件

                        Activitys objAct = new Activitys()
                        {
                            Duration    = 0,
                            ModuleKey   = Utility.ParaCondition.ModuleType.Material,
                            ToRoomId    = circleKey,
                            CreateUser  = memberId,
                            Created     = Infrastructure.Property.TimeData.Create(dt),
                            Updated     = Infrastructure.Property.TimeData.Create(null),
                            Deleted     = Infrastructure.Property.TimeData.Create(null),
                            OuterKey    = eveId,
                            StartDate   = dt,
                            IsActivity  = true,
                            CardisShow  = true,
                            Publish_Utc = dt
                        };
                        #endregion

                        #region // 3. 建立一筆Google檔案

                        var objGoogle = new GoogleFile()
                        {
                            DownLoadUrl  = string.Format("https://drive.google.com/a/g.scenet.pccu.edu.tw/uc?id={0}&export=download", googleDriveFileId),
                            FileId       = googleDriveFileId,
                            FileType     = fileType,
                            ImgUrl       = string.Format("https://drive.google.com/a/g.scenet.pccu.edu.tw/uc?id={0}&export=download", fileShortImg),
                            WebViewUrl   = string.Format("https://drive.google.com/a/g.scenet.pccu.edu.tw/file/d/{0}/view?usp=drivesdk", googleDriveFileId),
                            Name         = name,
                            ParentFileId = folderId,
                            Size         = fileSize,
                            Create_User  = memberId,
                            Create_Utc   = Convert.ToDateTime(dt)
                        };
                        #endregion

                        // 3. 寫入DB
                        db.ActMaterial.Add(objMaterial);
                        db.Activitys.Add(objAct);
                        db.GoogleFile.Add(objGoogle);
                        db.SaveChanges();
                        dbTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Rollback();
                        throw ex;
                    }
                }
            }
            #region // 回傳給APP的物件
            var data = new Infrastructure.BusinessObject.MaterialEvent()
            {
                ClassId    = circleKey,
                OuterKey   = eveId,
                Creator    = memberId.ToString(),
                CreateDate = Convert.ToDateTime(dt)
            };
            #endregion
            return(data);
        }