/// <summary> /// 根據新增學習圈建立驗證碼 /// </summary> /// <param name="circleKey"></param> /// <returns></returns> public bool CreateFromCreateLearningCircle(string circleKey) { var learningCircleService = new LearningCircleService(); var learningCircleInfo = learningCircleService.GetDetailByOuterKey(circleKey.ToLower()); if (learningCircleInfo == null) { return(false); } var codeService = new CaptchaHelper(); var code = codeService.GenerateRandomText(10); var checkHadCode = _uow.MemberInviteRepo.GetFirst(t => t.CircleKey.ToLower() == circleKey.ToLower() && t.Enable == true && t.IsCourseCode == true); if (checkHadCode == null) { var entity = new MemberInvite() { CircleKey = circleKey.ToLower(), Code = code.ToLower(), CreateDate = DateTime.UtcNow, Enable = true, InviteEmail = null, InviteUrl = null, IsCourseCode = true, Type = 0 }; _uow.DbContext.MemberInvite.Add(entity); _uow.SaveChanges(); } return(true); }
/// <summary> /// 更新資料 /// </summary> /// <param name="requestData"></param> /// <returns></returns> public IEnumerable <MemberInvite> Update(MemberInvitePutRequest requestData) { var circleKey = requestData.CircleKey; var isUpdateCourseCode = requestData.CircleKey != null; //更新課程邀請碼 if (isUpdateCourseCode) { var courseCode = GetDetailByCircleKey(requestData.CircleKey); if (courseCode != null) { courseCode.Enable = false; } var captchaHelp = new Utility.CaptchaHelper(); var inviteCode = captchaHelp.GenerateRandomText(10).ToLower(); var entity = new MemberInvite() { CircleKey = requestData.CircleKey.ToLower(), Code = inviteCode, CreateDate = DateTime.UtcNow, Enable = true, IsCourseCode = true, Type = 0 }; _uow.DbContext.MemberInvite.Add(entity); } else {//更新特定邀請碼 var inviteInfo = GetDetail(requestData.InviteCode.ToLower()); if (inviteInfo == null) { return(null); } circleKey = inviteInfo.CircleKey; inviteInfo.Enable = requestData.Enable; } _uow.SaveChanges(); var responseData = GetList(circleKey, 0, null); return(responseData); }
/// <summary> /// 建立邀請碼資料 /// </summary> /// <param name="requestData"></param> /// <returns></returns> public bool Create(MemberInvitePostRequest requestData) { var inviteEmails = requestData.InviteEmail.ToList(); if (inviteEmails.FirstOrDefault() == null) { return(false); } var db = _uow.DbContext; var captchaHelp = new Utility.CaptchaHelper(); var mails = new List <MemberInvite>(); var learningCircleService = new LearningCircleService(); var learningCircleInfo = learningCircleService.GetDetailByOuterKey(requestData.CircleKey); if (learningCircleInfo == null) { return(false); } var organizationInfo = db.Organizations.FirstOrDefault(t => t.Id == learningCircleInfo.OrgId); var flipusOrgName = ConfigurationManager.AppSettings["FlipusOrgName"].ToString(); var inviteDomain = ConfigurationManager.AppSettings["loginServer"].ToString(); foreach (var inviteEmail in inviteEmails) { #region 將舊的code 設定失效 var setOldInviteCode = db.MemberInvite.Where(t => t.InviteEmail == inviteEmail && t.CircleKey == requestData.CircleKey && t.Enable == true); if (setOldInviteCode != null && setOldInviteCode.Count() > 0) { foreach (var oldInvite in setOldInviteCode) { oldInvite.Enable = false; } } #endregion var inviteCode = captchaHelp.GenerateRandomText(10).ToLower(); var inviteUrl = HttpUtility.UrlEncode(string.Format("{3}/FlipusWeb/invite?r=3&o={0}&c={1}&t={2}&on={3}", organizationInfo.OrgCode, inviteCode, requestData.InviteType, inviteDomain, HttpUtility.UrlEncode(organizationInfo.Name))); var entity = new MemberInvite() { CircleKey = requestData.CircleKey.ToLower(), Code = inviteCode, CreateDate = DateTime.UtcNow, Enable = true, InviteEmail = inviteEmail, IsCourseCode = false, Type = requestData.InviteType, InviteUrl = inviteUrl }; db.MemberInvite.Add(entity); mails.Add(entity); } //結束新增 try { //開始跑db db.SaveChanges(); var emailDomain = ConfigurationManager.AppSettings["MailDomain"].ToString(); var emailSMTPPort = Convert.ToInt32(ConfigurationManager.AppSettings["MailSMTPPort"].ToString()); var emailAdminAddress = ConfigurationManager.AppSettings["MailAdminAddress"].ToString(); var mailService = new MailService(); var tokenService = new TokenService(); var tokenInfo = tokenService.GetTokenInfo(requestData.Token).Result; var teacherInfo = db.Members.Find(tokenInfo.MemberId); var memberService = new MemberService(); var teachers = memberService.GetTeacherList(learningCircleInfo.LearningOuterKey); var teachersName = string.Empty; foreach (var teacher in teachers) { teachersName = string.Format("{0}、{1}", teachersName, teacher.Name); } teachersName = teachersName.Substring(1, teachersName.Length - 1); var weekTableService = new WeekTableService(); var weekTableDatas = weekTableService.GetByCirclekey(learningCircleInfo.LearningOuterKey); var weekTableTimes = string.Empty; foreach (var weekTableData in weekTableDatas.WeekTable) { weekTableTimes = string.Format("{0}、({1}){2:HH:mm} ~ {3:HH:mm}", weekTableTimes, weekTableData.Week, weekTableData.StartTime, weekTableData.EndTime); } weekTableTimes = weekTableTimes.Substring(1, weekTableTimes.Length - 1); //送邀請函信 foreach (var code in mails) { var mailContent = flipusOrgName == organizationInfo.OrgCode.ToString() ? //跑Flipus 非組織信字串 string.Format("<tbody><tr><td align = \"left\" style = \"padding-top: 15px;\"></td></tr>" + "<img src=\"http://scedev.eastus.cloudapp.azure.com/iThink/images/inviteimg/logo.png\" alt = \"logo\" width = \"108\" height = \"48\" />" + "<tr><td align=\"left\" style=\"padding - top: 15px; \"><h2>您好!</h2>" + "{0} 老師 邀請您一起加入,Flipus 翻轉校園學習圈的「{1}」,現在就與我們一同體驗最有溫度的學習互動!<br><br><br>" + "請點擊以下連結,來完成加入課程的動作:<br>" + "<a href=\"#\" style=\"color: #5bc289;\">{2}</a><br><br><br>" + "課程名稱:{1}<br>" + "適用對象:一般學員<br>" + "授課老師:{7}<br>" + "開課日期:{3:yyyy/MM/dd}~{4:yyyy/MM/dd}<br>" + "上課時段:{5}<br>" + "課程簡介:{6}" + "</td></tr>" + "<tr><td align = \"left\" style = \"padding-top: 30px; font-size: 13px; color: #868b8f;\" >" + "<hr style = \"margin-bottom: 25px; border: 0; background-color: #ccc; height: 1px;\">" + "※ 課程日期或上課時段等相關內容若有異動,請以實際課程資訊為主。<br>" + "※ 此信件是由 Flipus 系統自動產生與寄出,請勿直接回覆。<br>" + "若需要我們協助的問題,請透過此 <a href = \"mailto:[email protected]\" style = \"color: #5bc289;\" > [email protected]</a> 與我們聯繫,謝謝您!<br>" + "<a href = \"http://scedev.eastus.cloudapp.azure.com/iThink/images/inviteimg/footer_banner.png\" title = \"flipus翻轉校園學習圈\" ><img src = \"http://scedev.eastus.cloudapp.azure.com/iThink/images/inviteimg/footer_banner.png\" alt = \"flipus翻轉校園學習圈\" width = \"600\" height = \"100\" style = \"margin-top: 15px;\"></a>" + "<hr style = \"margin-top: 25px; border: 0; background-color: #ccc; height: 1px;\" ></td></tr><tr> " + "<td align = \"left\" style = \"padding-top: 15px; font-size: 13px;\" >© 中國文化大學推廣教育部 All Rights Reserved.</td>" + "</tr></tbody>", teacherInfo.Name, learningCircleInfo.Name, code.InviteUrl, learningCircleInfo.StartDate.Value.ToLocalTime(), learningCircleInfo.EndDate.Value.ToLocalTime(), weekTableTimes, learningCircleInfo.Description, teachersName) : //跑組織信字串 string.Format("<tbody><tr><td align = \"left\" style = \"padding-top: 15px;\"></td></tr>" + "<img src=\"http://scedev.eastus.cloudapp.azure.com/iThink/images/inviteimg/logo.png\" alt = \"logo\" width = \"108\" height = \"48\" />" + "<tr><td align=\"left\" style=\"padding - top: 15px; \"><h2>您好!</h2>" + "{0} 老師 邀請您一起加入,{8}組織專屬課程 -「{1}」,現在就與我們一同體驗最有溫度的學習互動!<br><br><br>" + "請點擊以下連結,來完成加入課程的動作:<br>" + "<a href=\"#\" style=\"color: #5bc289;\">{2}</a><br><br><br>" + "課程名稱:{1}<br>" + "適用對象:{8}組織學員<br>" + "授課老師:{7}<br>" + "開課日期:{3:yyyy/MM/dd}~{4:yyyy/MM/dd}<br>" + "上課時段:{5}<br>" + "課程簡介:{6}" + "</td></tr>" + "<tr><td align = \"left\" style = \"padding-top: 30px; font-size: 13px; color: #868b8f;\" >" + "<hr style = \"margin-bottom: 25px; border: 0; background-color: #ccc; height: 1px;\">" + "※ 課程日期或上課時段等相關內容若有異動,請以實際課程資訊為主。<br>" + "※ 此信件是由 Flipus 系統自動產生與寄出,請勿直接回覆。<br>" + "若需要我們協助的問題,請透過此 <a href = \"mailto:[email protected]\" style = \"color: #5bc289;\" > [email protected]</a> 與我們聯繫,謝謝您!<br>" + "<a href = \"http://scedev.eastus.cloudapp.azure.com/iThink/images/inviteimg/footer_banner.png\" title = \"flipus翻轉校園學習圈\" ><img src = \"http://scedev.eastus.cloudapp.azure.com/iThink/images/inviteimg/footer_banner.png\" alt = \"flipus翻轉校園學習圈\" width = \"600\" height = \"100\" style = \"margin-top: 15px;\"></a>" + "<hr style = \"margin-top: 25px; border: 0; background-color: #ccc; height: 1px;\" ></td></tr><tr> " + "<td align = \"left\" style = \"padding-top: 15px; font-size: 13px;\" >© 中國文化大學推廣教育部 All Rights Reserved.</td>" + "</tr></tbody>", teacherInfo.Name, learningCircleInfo.Name, code.InviteUrl, learningCircleInfo.StartDate.Value.ToLocalTime(), learningCircleInfo.EndDate.Value.ToLocalTime(), weekTableTimes, learningCircleInfo.Description, teachersName, organizationInfo.Name); mailService.SendMail(emailDomain, emailSMTPPort, emailAdminAddress, new List <string>() { code.InviteEmail }, mailContent, string.Format("Flipus 邀請您加入「{0}」", learningCircleInfo.Name), null); } if (requestData.CC) { mailService.SendMail(emailDomain, emailSMTPPort, emailAdminAddress, new List <string>() { teacherInfo.Email }, "已發送邀請碼完成", string.Format("[{0}] 課程邀請碼", learningCircleInfo.Name), null); } return(true); } catch (Exception ex) { return(false); throw ex; } }