示例#1
0
        /// <summary>
        /// 修改資料
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public bool UpdateMutiple(LearningRolePostResquest requestData)
        {
            if (requestData.Roles.FirstOrDefault() == null)
            {
                return(false);
            }

            var tokenService = new TokenService();
            var tokenInfo    = tokenService.GetTokenInfo(requestData.Token).Result;

            if (tokenInfo == null)
            {
                return(false);
            }

            var db = _uow.DbContext;

            foreach (var learningRole in requestData.Roles)
            {
                var oldLeanirngRole = db.LearningRole.Find(learningRole.RoleId);
                //查不到或無法修改就跳過
                if (oldLeanirngRole == null || oldLeanirngRole.IsFixed == false)
                {
                    continue;
                }
                oldLeanirngRole.Name       = learningRole.Name;
                oldLeanirngRole.Level      = learningRole.Level;
                oldLeanirngRole.Updated    = TimeData.Create(DateTime.UtcNow);
                oldLeanirngRole.UpdateUser = tokenInfo.MemberId;
            }
            db.SaveChanges();
            return(true);
        }
示例#2
0
        /// <summary>
        /// 只更新Email
        /// </summary>
        /// <param name="token"></param>
        /// <param name="account"></param>
        /// <param name="email"></param>
        /// <param name="isShowMail"></param>
        /// <returns></returns>
        public bool UpdateMemberEmailInfo(string token, string account, string email, bool?isShowMail = false)
        {
            try
            {
                var db           = _uow.DbContext;
                var tokenService = new TokenService();
                //取得目前DB登入
                var checkUserToken = tokenService.GetTokenInfo(token).Result;
                //db.UserToken.FirstOrDefault(t => t.Token == token);
                if (checkUserToken == null)
                {
                    return(false);
                }

                var memberInfo = db.Members.FirstOrDefault(t => t.Id == checkUserToken.MemberId);

                if (memberInfo == null)
                {
                    return(false);
                }

                memberInfo.Email       = email;
                memberInfo.Updated     = TimeData.Create(DateTime.UtcNow);
                memberInfo.UpdateUser  = memberInfo.Id;
                memberInfo.IsShowEmail = isShowMail.Value;
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#3
0
        public bool LogOut(string token)
        {
            var tokenService = new TokenService();
            var tokenInfo    = tokenService.GetTokenInfo(token).Result;
            var deleteToken  = tokenService.DeleteUserToken(tokenInfo.MemberId, tokenInfo.RequestSystem);

            return(deleteToken);
        }
        /// <summary>
        /// 建立學習圈 - [後臺管理API用]
        /// </summary>
        /// <returns></returns>
        public LearningCircle CreateLearningCircle(string name, string circleKey, string description, string token, DateTime startDate, DateTime endDate, int?orgId, string objective = null, int?section = null)
        {
            var db = _uow.DbContext;

            var checkDBEmpty = db.LearningCircle.FirstOrDefault(t => t.LearningOuterKey == circleKey && t.Name == name);

            if (checkDBEmpty != null)
            {
                return(checkDBEmpty);
            }
            var now          = DateTime.UtcNow;
            var tokenService = new TokenService();
            var creator      = tokenService.GetTokenInfo(token).Result;
            var entity       = new LearningCircle()
            {
                Created     = TimeData.Create(now),
                Deleted     = TimeData.Create(null),
                Updated     = TimeData.Create(null),
                CreateUser  = creator.MemberId,
                Description = description,
                Name        = name,
                Enable      = true,
                Visibility  = true,
                StartDate   = startDate.ToUniversalTime(),
                EndDate     = endDate.ToUniversalTime(),
                LCType      = 10,
                Objective   = objective
            };

            if (section.HasValue)
            {
                entity.Section = section.Value.ToString();
            }
            if (orgId.HasValue)
            {
                entity.OrgId = orgId.Value;
            }

            if (circleKey == null || circleKey == string.Empty)
            {
                circleKey = string.Format("{0}{1}", now.Ticks.ToString(), "course");
            }

            entity.LearningOuterKey = circleKey.ToLower();

            db.LearningCircle.Add(entity);
            db.SaveChanges();
            var memberInviteService = new MemberInviteService();
            var memerInviteInfo     = memberInviteService.CreateFromCreateLearningCircle(circleKey.ToLower());

            return(entity);
        }
示例#5
0
        /// <summary>
        /// 刪除角色
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public bool DeleteMutiple(LearningRoleDeleteResquest requestData)
        {
            var tokenService = new TokenService();
            var tokenInfo    = tokenService.GetTokenInfo(requestData.Token).Result;

            if (tokenInfo == null)
            {
                return(false);
            }

            var db = _uow.DbContext;
            var learningCircleService = new LearningCircleService();
            var learningCircleInfo    = learningCircleService.GetDetailByOuterKey(requestData.CircleKey.ToLower());

            if (learningCircleInfo == null)
            {
                return(false);
            }
            var circleMemberService = new Service.Backend.CircleMemberService();
            //查出該課程的學生角色
            var studentRoleInfo = db.LearningRole.FirstOrDefault(t => t.Level == 3 && t.LearningId == learningCircleInfo.Id && t.IsFixed == false);

            if (studentRoleInfo == null)
            {
                return(false);
            }
            foreach (var learningRoleId in requestData.Ids)
            {
                var oldLeanirngRole = db.LearningRole.Find(learningRoleId);
                //查不到或無法修改就跳過
                if (oldLeanirngRole == null || oldLeanirngRole.IsFixed == false)
                {
                    continue;
                }
                //將該角色的所有成員全部移至學生Level3 isFixed=false的角色中
                var circleMemberDatas = db.CircleMemberRoleplay.Where(t => t.RoleId == learningRoleId && t.CircleId == oldLeanirngRole.LearningId);
                foreach (var circleMemberData in circleMemberDatas)
                {
                    circleMemberData.RoleId = studentRoleInfo.Id;
                }
                oldLeanirngRole.Enable     = false;
                oldLeanirngRole.Deleted    = TimeData.Create(DateTime.UtcNow);
                oldLeanirngRole.DeleteUser = tokenInfo.MemberId;
            }
            db.SaveChanges();
            return(true);
        }
示例#6
0
        /// <summary>
        /// 更新成員資訊 - 管理者修改
        /// </summary>
        /// <param name="token">登入者代碼</param>
        /// <param name="name">欲修改姓名</param>
        /// <param name="email">欲修改信箱</param>
        /// <param name="roleName">欲修改角色</param>
        /// <param name="file">欲修改大頭照</param>
        /// <returns></returns>
        public Member UpdateMemberInfo(MemberManagePutRequest requestData)
        {
            try
            {
                var db           = _uow.DbContext;
                var tokenService = new TokenService();
                //取得目前DB登入
                var checkUserToken = tokenService.GetTokenInfo(requestData.Token).Result;

                if (checkUserToken == null)
                {
                    return(null);
                }

                var updaterInfo = db.Members.FirstOrDefault(t => t.Id == checkUserToken.MemberId);
                var memberInfo  = db.Members.FirstOrDefault(t => t.OrgId == requestData.OrgId && t.Account.ToLower() == requestData.Account.ToLower());
                if (memberInfo == null)
                {
                    return(null);
                }

                memberInfo.Email = requestData.Email;

                if (requestData.Name != null && requestData.Name != string.Empty)
                {
                    memberInfo.Name = requestData.Name;
                }

                if (requestData.RoleId.HasValue)
                {
                    memberInfo.RoleName = requestData.RoleId.ToString();
                }
                memberInfo.Updated    = TimeData.Create(DateTime.UtcNow);
                memberInfo.UpdateUser = updaterInfo.Id;
                //if (requestData.Photo != string.Empty && requestData.Photo != null)
                //    memberInfo.Photo = requestData.Photo;
                memberInfo.IsShowEmail = requestData.IsShowEmail;
                db.SaveChanges();
                return(memberInfo);
            }
            catch (Exception ex)
            {
                return(null);

                throw ex;
            }
        }
示例#7
0
        /// <summary>
        /// 建立多筆
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public IEnumerable <LearningRole> CreateMutiple(LearningRolePostResquest requestData)
        {
            var db           = _uow.DbContext;
            var tokenService = new TokenService();
            var tokenInfo    = tokenService.GetTokenInfo(requestData.Token).Result;

            if (tokenInfo == null)
            {
                return(null);
            }
            var learningCircleService = new LearningCircleService();
            var learningCircleInfo    = learningCircleService.GetDetailByOuterKey(requestData.CircleKey.ToLower());

            if (learningCircleInfo == null)
            {
                return(null);
            }

            var responseData = new List <LearningRole>();

            foreach (var data in requestData.Roles)
            {
                var checkEmpty = db.LearningRole.FirstOrDefault(t => t.Name == data.Name && t.Level == data.Level && t.LearningId == learningCircleInfo.Id);
                if (checkEmpty != null)
                {
                    continue;
                }
                var entity = new LearningRole()
                {
                    Created     = TimeData.Create(DateTime.UtcNow),
                    Deleted     = TimeData.Create(null),
                    Updated     = TimeData.Create(null),
                    IsAdminRole = data.Level <= 2 ? true : false,
                    Name        = data.Name,
                    Level       = data.Level,
                    Enable      = true,
                    IsFixed     = true,
                    LearningId  = learningCircleInfo.Id,
                    CreateUser  = tokenInfo.MemberId
                };
                db.LearningRole.Add(entity);
                responseData.Add(entity);
            }
            db.SaveChanges();
            return(responseData);
        }
示例#8
0
        /// <summary>
        /// Token轉MemberAccount
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <Member> TokenToMember(Guid token)
        {
            var tokenService = new TokenService();
            var userToken    = await tokenService.GetTokenInfo(token.ToString());

            if (userToken != null)
            {
                //取得memberAccount
                int myId = userToken.MemberId;
                var me   = _uow.EntityRepository <Member>().GetFirst(x => x.Id == myId);
                return(me);
            }
            else
            {
                return(null);
            }
        }
示例#9
0
        public bool UpdateMemberBySelf(PersonPutRequest requestData)
        {
            try
            {
                var db             = _uow.DbContext;
                var tokenService   = new TokenService();
                var checkUserToken = tokenService.GetTokenInfo(requestData.Token).Result;
                if (checkUserToken == null)
                {
                    return(false);
                }
                var memberInfo = db.Members.FirstOrDefault(t => t.Id == checkUserToken.MemberId);
                if (memberInfo == null)
                {
                    return(false);
                }

                memberInfo.Email = requestData.Email;

                if (requestData.Name != null && requestData.Name != string.Empty)
                {
                    memberInfo.Name = requestData.Name;
                }

                if (requestData.RoleId.HasValue)
                {
                    memberInfo.RoleName = requestData.RoleId.ToString();
                }
                memberInfo.Updated    = TimeData.Create(DateTime.UtcNow);
                memberInfo.UpdateUser = memberInfo.Id;
                if (requestData.Photo != string.Empty && requestData.Photo != null)
                {
                    memberInfo.Photo = requestData.Photo;
                }
                memberInfo.IsShowEmail = requestData.IsShowEmail;


                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#10
0
        /// <summary>
        /// 取得自己在學習圈內的角色
        /// </summary>
        /// <param name="token"></param>
        /// <param name="circleKey"></param>
        /// <returns></returns>
        public LearningRole GetMyRole(string token, string circleKey)
        {
            var db           = _uow.DbContext;
            var tokenService = new TokenService();
            var tokenInfo    = tokenService.GetTokenInfo(token).Result;

            if (tokenInfo == null)
            {
                return(null);
            }
            var responseData = (from cmr in db.CircleMemberRoleplay
                                join lc in db.LearningCircle on cmr.CircleId equals lc.Id
                                join lr in db.LearningRole on cmr.RoleId equals lr.Id
                                where lc.LearningOuterKey.ToLower() == circleKey.ToLower() && cmr.MemberId == tokenInfo.MemberId
                                select lr).FirstOrDefault();

            return(responseData);
        }
示例#11
0
        /// <summary>
        /// 編輯學習圈 - [後臺管理API用]
        /// </summary>
        /// <param name="name"></param>
        /// <param name="circleKey"></param>
        /// <param name="description"></param>
        /// <param name="token"></param>
        /// <param name="enable"></param>
        /// <param name="objective"></param>
        /// <returns></returns>
        public LearningCircle UpdateLearningCircle(string name, string circleKey, string description, string token, bool enable, string objective, string remark)
        {
            var db           = _uow.DbContext;
            var checkDBEmpty = db.LearningCircle.FirstOrDefault(t => t.LearningOuterKey == circleKey);

            if (checkDBEmpty == null)
            {
                return(null);
            }

            var tokenService = new TokenService();
            var updater      = tokenService.GetTokenInfo(token).Result;

            checkDBEmpty.Updated     = TimeData.Create(DateTime.UtcNow);
            checkDBEmpty.UpdateUser  = updater.MemberId;
            checkDBEmpty.Description = description;
            checkDBEmpty.Name        = name;
            checkDBEmpty.Enable      = enable;
            checkDBEmpty.Objective   = objective;
            checkDBEmpty.ReMark      = remark;
            // var timeTableService = new Backend.TimeTableService();
            //如果有修改開始日期與修改結束日期

            /*  if (startDate.HasValue && endDate.HasValue)
             * {
             *    //需要修改 weekTable資料
             *    if (weeks !=null && weeks.Count > 0)
             *    {
             *        var weekTableService = new WeekTableService();
             *        var updateWeekDatas = weekTableService.UpdateWeekDatas(token, circleKey, place, startDate.Value, endDate.Value,0,weeks);
             *    }
             *    checkDBEmpty.StartDate = startDate.Value.ToUniversalTime();
             *    checkDBEmpty.EndDate = endDate.Value.ToUniversalTime();
             *    var updateResponse = timeTableService.UpdateByCircleKey(startDate.Value.ToUniversalTime(), endDate.Value.ToUniversalTime(), circleKey);
             * }
             * //如果只有修改結束日期
             * else if (endDate.HasValue)
             * {
             *    //需要修改 weekTable資料
             *    if (weeks != null && weeks.Count > 0)
             *    {
             *        var weekTableService = new WeekTableService();
             *        var updateWeekDatas = weekTableService.UpdateWeekDatas(token, circleKey, place, checkDBEmpty.StartDate.Value, endDate.Value, 0, weeks);
             *    }
             *    checkDBEmpty.EndDate = endDate.Value.ToUniversalTime();
             *
             *    var updateResponse = timeTableService.UpdateByCircleKey(checkDBEmpty.StartDate.Value, endDate.Value.ToUniversalTime(), circleKey);
             * }
             * //如果只有修改開始日期
             * else if (startDate.HasValue)
             * {
             *    //需要修改 weekTable資料
             *    if (weeks != null && weeks.Count > 0)
             *    {
             *        var weekTableService = new WeekTableService();
             *        var updateWeekDatas = weekTableService.UpdateWeekDatas(token, circleKey, place, checkDBEmpty.StartDate.Value, checkDBEmpty.EndDate.Value, 0, weeks);
             *    }
             *    checkDBEmpty.StartDate = startDate.Value.ToUniversalTime();
             *    var updateResponse = timeTableService.UpdateByCircleKey(startDate.Value.ToUniversalTime(), checkDBEmpty.EndDate.Value, circleKey);
             * }*/
            db.SaveChanges();

            return(checkDBEmpty);
        }
示例#12
0
        /// <summary>
        /// 取得APP的GetCourseDetail的資訊
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public Infrastructure.ViewModel.CourseManage.GetCourseDetailResponse APPGetCourseDetail(string token, string circleKey)
        {
            var response      = new Infrastructure.ViewModel.CourseManage.GetCourseDetailResponse();
            var memberService = new MemberService();
            var tokenService  = new TokenService();
            var checkToken    = tokenService.GetTokenInfo(token);

            if (checkToken == null)
            {
                return(response);
            }

            var members = memberService.GetLearningCircleMembers(circleKey);

            if (members == null)
            {
                return(response);
            }

            response.MemberCount    = members.Count();
            response.Edit           = false;
            response.EditImpression = false;
            response.CollInfo       = null;

            var learningCircleInfo = GetDetailByOuterKey(circleKey);

            if (learningCircleInfo == null)
            {
                return(response);
            }

            //處理老師名單
            var teachers = memberService.GetTeacherList(circleKey);

            if (teachers.FirstOrDefault() != null)
            {
                var teachersName = teachers.Select(t => t.Name).ToList();
                foreach (var teacher in teachersName)
                {
                    response.ClassTeachers += teacher + "、";
                }
                response.ClassTeachers = response.ClassTeachers.Substring(0, response.ClassTeachers.Length - 1);
            }
            if (learningCircleInfo.StartDate.HasValue && learningCircleInfo.EndDate.HasValue)
            {
                response.ClassPeriod = string.Format("{0} ~ {1}", learningCircleInfo.StartDate.Value.ToLocalTime().ToString("yyyy/MM/dd"), learningCircleInfo.EndDate.Value.ToLocalTime().ToString("yyyy/MM/dd"));
                response.StartDate   = learningCircleInfo.StartDate.Value.ToLocalTime();
                response.EndDate     = learningCircleInfo.EndDate.Value.ToLocalTime();
            }

            var weekTableService    = new WeekTableService();
            var ClassWeekTableDatas = weekTableService.GetByCirclekey(circleKey);

            response.WeekTable = new List <Infrastructure.ViewModel.CourseManage.GetAllMyCourseWeekTable>();
            if (ClassWeekTableDatas.WeekTable.FirstOrDefault() != null)
            {
                foreach (var weekTableData in ClassWeekTableDatas.WeekTable)
                {
                    var data = new Infrastructure.ViewModel.CourseManage.GetAllMyCourseWeekTable()
                    {
                        Week        = weekTableData.Week,
                        Place       = weekTableData.Place,
                        StartPeriod = weekTableData.StartPeriod.Value,
                        EndPeriod   = weekTableData.EndPeriod.Value,
                        StartTime   = string.Format("{0:HH}:{0:mm}", weekTableData.StartTime.ToLocalTime()),
                        EndTime     = string.Format("{0:HH}:{0:mm}", weekTableData.EndTime.ToLocalTime())
                    };
                    response.WeekTable.Add(data);
                }
            }

            response.ClassSubjectName = learningCircleInfo.Name;
            response.ClassId          = learningCircleInfo.LearningOuterKey;
            response.Introduction     = learningCircleInfo.Description;
            response.ClassName        = learningCircleInfo.Name;
            response.ClassDomainId    = null;
            response.ClassDomainName  = null;
            response.Note             = learningCircleInfo.ReMark;
            response.ClassTarget      = learningCircleInfo.Objective;
            return(response);
        }
示例#13
0
        /// <summary>
        /// 儲存個人照片檔案
        /// </summary>
        /// <param name="token"></param>
        /// <param name="account"></param>
        /// <param name="photo"></param>
        /// <returns></returns>
        public Infrastructure.ViewModel.MemberManage.MemberPhotoResponse SaveMemberPhotoFile(string token, string account, string photo)
        {
            var db            = _uow.DbContext;
            var memberService = new MemberService();
            var tokenService  = new TokenService();
            var checkToken    = tokenService.GetTokenInfo(token).Result;

            if (checkToken == null)
            {
                return(null);
            }

            var memberData = db.Members.Find(checkToken.MemberId);

            //    var memberInfo = memberService.UserIdToAccount(checkToken.MemberId);
            if (memberData == null)
            {
                return(null);
            }
            int?fileImageWidth  = null;
            int?fileImageHeight = null;
            var fileGuidName    = Guid.NewGuid();
            var resourcePath    = Path.Combine(drivePath, fileGuidName.ToString("N"));

            var photoData   = Convert.FromBase64String(photo);
            var photoStream = new System.IO.MemoryStream(photoData);
            var photoBitmap = new Bitmap(new MemoryStream(photoData));

            //原始圖片檔
            SetPhotoFileInfo(photoBitmap, resourcePath);

            var imgResizePath = Path.Combine(drivePath, string.Format("{0}_w{1}_h{2}", fileGuidName.ToString("N"), maxImgWidth, maxImgHeight));

            //縮圖檔
            SetPhotoFileResizeInfo(photoBitmap, resourcePath, maxImgWidth, maxImgHeight, imgResizePath);
            var image = System.Drawing.Image.FromStream(photoStream);

            //實體圖片寬高
            fileImageWidth  = image.Width;
            fileImageHeight = image.Width;
            var imgContentType = "image/png";
            var fileServer     = WebConfigurationManager.AppSettings["loginServer"];
            var fileEntity     = new Infrastructure.Entity.FileStorage()
            {
                Name            = memberData.Name + "照片",
                FileGuid        = fileGuidName,
                FileSize        = photoData.Length, //Byte
                FileContentType = imgContentType,
                Creator         = memberData.Id,
                CreateUtcDate   = DateTime.UtcNow,
                FileUrl         = string.Format("{0}api/file/{1}", fileServer, fileGuidName.ToString("N")),

                FileImageHeight = fileImageHeight,
                FileImageWidth  = fileImageWidth
            };

            // Db File
            var fileImgData = Create(fileEntity);

            memberData.Photo      = fileImgData.FileImageUrl;
            memberData.Updated    = TimeData.Create(DateTime.UtcNow);
            memberData.UpdateUser = memberData.Id;
            db.SaveChanges();

            var response = new Infrastructure.ViewModel.MemberManage.MemberPhotoResponse();

            response.AcpdId = account;
            response.Photo  = fileImgData.FileImageUrl;
            return(response);
        }