예제 #1
0
        public void PostTest()
        {
            postTestValue = new CourseManagerPostRequest()
            {
                Account   = "yushuchen",
                ICanToken = "4a01b7ed-27d7-4312-9a63-71c53a70dc81",
                Token     = "4a01b7ed-27d7-4312-9a63-71c53a70dc81",
                Accounts  = new string[1] {
                    "yushuchen"
                },
                InviteCode = "9875641258",
                ResType    = 1,
                OrgCode    = "Sce"
            };


            // target = new CircleAdminController(mock.Object);
            var courseManagerService = new CourseManagerService("FlipusDB");
            //    var targetResponse = target.Post(postTestValue);
            var targetResponse = courseManagerService.CreateMutiple(postTestValue);
            //Assert.IsInstanceOfType(targetResponse, getResponse);
            var targetResData = targetResponse as InviteResponseData;

            Assert.IsNotNull(targetResData);
            //  Assert.IsTrue(targetResData.Content.Success);
            //     throw new NotImplementedException();
        }
예제 #2
0
        public IHttpActionResult Post(CourseManagerPostRequest requestData)
        {
            var requestService = new Service.Utility.RequestDataHelper <CourseManagerPostRequest>();
            var checkColumnKey = new string[4] {
                "token", "invitecode", "restype", "accounts"
            };
            var checkEmpty = requestService.CheckColumnEmpty(requestData, checkColumnKey);
            var response   = new Infrastructure.ViewModel.Base.BaseResponse <InviteResponseData>();

            response.Success = false;

            if (checkEmpty == false)
            {
                response.Message = "遺漏參數";
                return(Content(HttpStatusCode.BadRequest, response));
            }
            var organizationService = new OrganizationService();
            var checkCanRegister    = organizationService.CheckCanRegister(requestData.OrgCode);

            if (checkCanRegister == false)
            {
                response.Message = "不允許加入課程";
                response.State   = Infrastructure.ViewModel.Base.LogState.Error;
                response.Data    = new InviteResponseData()
                {
                    InviteStatus = InviteStatusEnum.EndInvite, IsOrgRegister = false, CircleKey = requestData.CircleKey
                };
                return(Ok(response));
            }
            var responseData = courseManagerService.CreateMutiple(requestData);

            response.Success = true;
            response.Message = responseData.InviteStatus.ToString();

            response.Data = responseData;
            return(Ok(response));
        }
예제 #3
0
        /// <summary>
        /// 根據邀請碼加入課程管理者列表
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public InviteResponseData CreateMutiple(CourseManagerPostRequest requestData)
        {
            var inviteData   = _uow.DbContext.MemberInvite.FirstOrDefault(t => t.Code.ToLower() == requestData.InviteCode.ToLower());
            var responseData = new InviteResponseData()
            {
                InviteStatus = InviteStatusEnum.inviteError
            };

            if (inviteData == null)
            {
                return(responseData);
            }

            var learningService    = new LearningCircleService();
            var learningCircleInfo = learningService.GetDetailByOuterKey(inviteData.CircleKey.ToLower());

            //課程停止邀請
            if (learningCircleInfo == null || learningCircleInfo.AdminInviteEnable == false || learningCircleInfo.Enable == false)
            {
                responseData.InviteStatus = InviteStatusEnum.EndInvite;
                return(responseData);
            }

            //邀請碼失效
            if (inviteData.Enable == false)
            {
                responseData.InviteStatus = InviteStatusEnum.inviteError;
                return(responseData);
            }


            responseData.CircleName = learningCircleInfo.Name;

            var memberService = new MemberService();
            var memberInfo    = memberService.TokenToMember(requestData.Token).Result;

            if (memberInfo == null || memberInfo.OrgId != learningCircleInfo.OrgId.Value)
            {
                responseData.InviteStatus = InviteStatusEnum.AccountNotAllow;
                return(responseData);
            }
            var organizationInfo = _uow.DbContext.Organizations.FirstOrDefault(t => t.Id == memberInfo.OrgId);

            if (organizationInfo == null)
            {
                responseData.InviteStatus = InviteStatusEnum.AccountNotAllow;
                return(responseData);
            }
            responseData.OrgName = organizationInfo.Name;


            //判斷要加的管理者是否跟Token帳號一致
            var checkAddAccountIsSuccess = requestData.Accounts.FirstOrDefault(t => t.ToString() == memberInfo.Account);

            if (checkAddAccountIsSuccess == null)
            {
                responseData.InviteStatus = InviteStatusEnum.inviteError;
                return(responseData);
            }
            //將驗證碼失效
            var getOldInviteData = _uow.DbContext.MemberInvite.FirstOrDefault
                                       (t => t.CircleKey.ToLower() == inviteData.CircleKey.ToLower() &&
                                       t.Enable == true && t.Type == 1 && t.Code.ToLower() == requestData.InviteCode.ToLower());

            if (getOldInviteData != null)
            {
                getOldInviteData.Enable = false;
            }
            else
            {
                responseData.InviteStatus = InviteStatusEnum.inviteError;
                return(responseData);
            }

            var checkJoined = GetDetail(memberInfo.Id, learningCircleInfo.Id, null);

            //判斷是否加入過
            if (checkJoined != null)
            {
                UpdateFromCreate(checkJoined.Id);
                {
                    responseData.InviteStatus = InviteStatusEnum.success;
                    return(responseData);
                }
            }
            var entity = new LearningCircleManager()
            {
                CreateUtcDate    = DateTime.UtcNow,
                Creator          = memberInfo.Id,
                Enable           = true,
                LearningCircleId = learningCircleInfo.Id,
                MemberId         = memberInfo.Id,
                ResType          = requestData.ResType
            };

            _uow.DbContext.LearningCircleManager.Add(entity);
            _uow.SaveChanges();
            responseData.InviteStatus = InviteStatusEnum.success;
            return(responseData);
        }