using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Net.Mail; using System.Text.RegularExpressions; using System.Web; using System.Web.Mvc; using System.Xml; using CPE.App.Web.Code; using CPE.App.Web.Connect; using CPE.App.Web.Helpers; using CPE.App.Web.Models; namespace CPE.App.Web.Controllers { public class IndexController : BaseController { public enum MeetingType { Adobe, Elucidat } private bool IsLocal() { var address = Request.UserHostAddress; if (address.StartsWith("192.") || address.StartsWith("10.211") || address == "::1") return true; return false; } // GET: Index [HttpGet] public ActionResult Index(int? year) { if(Request.Cookies["allowed"] == null && !IsLocal()) return Redirect("http://www.cpeonline.com/webcasts"); string systemPassword = ConfigurationManager.AppSettings["password"]; if(Request.Cookies["allowed"] != null && (Request.Cookies["allowed"].Value != systemPassword)) return Redirect("http://www.cpeonline.com/webcasts"); DateTime now = DateTime.UtcNow; if(!year.HasValue) { year = DateTime.Now.Year; } List meetingSessions = Database.MeetingSessionsData() .Where(msd => msd.EndDate.HasValue && msd.EndDate <= now && (msd.StartDate >= new DateTime(year.Value, 1, 1) && msd.StartDate < new DateTime(year.Value + 1, 1, 1))) .OrderByDescending(msd => msd.StartDate) .ToList(); return View(meetingSessions); } [HttpGet] public ActionResult SessionDetails(int meetingSessionKey) { Extensions.LogServiceCall("[IndexController][SessionDetails]", string.Format("Beginning: meetingSessionKey = {0}", meetingSessionKey)); var meetingSession = Database.MeetingSessions.Single(ms => ms.MeetingSessionKey == meetingSessionKey); var result = new AdobeSessionViewModel { MeetingSession = meetingSession, ParticipantSessionsDataResult = Database.ParticipantSessionsData(meetingSessionKey) .ToList(), GetSessionReportResult = Database.GetSessionReport(meetingSessionKey) .ToList(), WebcastPurchaseDataResult = Database.WebcastPurchaseData(meetingSession.SCO_ID, meetingSessionKey) //.Where(w => w.Sco == meetingSession.SCO_ID && w.mDate.DayOfYear >= meetingSession.StartDate.DayOfYear) .ToList() }; //if (result.ParticipantSessionsDataResult.Count == 0) { adobe.GetAdobeTransactions(meetingSession, Database); Database.SubmitChanges(); result = new AdobeSessionViewModel { MeetingSession = meetingSession, ParticipantSessionsDataResult = Database.ParticipantSessionsData(meetingSessionKey) .ToList(), GetSessionReportResult = Database.GetSessionReport(meetingSessionKey) .ToList(), WebcastPurchaseDataResult = Database.WebcastPurchaseData(meetingSession.SCO_ID, meetingSessionKey) .ToList() }; //} return View(result); } [HttpGet] public ActionResult RetrieveSession(int meetingSessionKey) { Extensions.LogServiceCall("[IndexController][RetrieveSession]", string.Format("Beginning: meetingSessionKey = {0}", meetingSessionKey)); var meetingSession = Database.MeetingSessions.Single(ms => ms.MeetingSessionKey == meetingSessionKey); if(Database.ParticipantSessionsData(meetingSessionKey) .ToList() .Count == 0) { adobe.GetAdobeTransactions(meetingSession, Database); Database.SubmitChanges(); } return RedirectToAction("SessionDetails", new {meetingSessionKey}); } [HttpGet] public ActionResult TestElucidat() { var baseUrl = "https://api-launchpad.elucidat.com/"; var urlFull = "health/ping"; Extensions.LogServiceCall("[IndexController][TestElucidat]", $"Beginning: {baseUrl}{urlFull}"); ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3; ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls; ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls11; // Add TLS 1.2 ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; var client = new WebClient { BaseAddress = baseUrl }; client.Headers.Clear(); client.Headers["Accept"] = "application/json"; var response = client.DownloadString(urlFull); Extensions.LogServiceCall("[IndexController][TestElucidat]", $"Response: {response}"); return Content(response); } [HttpGet] public ActionResult Login(string meetingUrl, string d = null, string c = null) { meetingUrl = meetingUrl?.Trim(); d = d?.Trim(); c = c?.Trim(); Extensions.LogServiceCall("[IndexController][Login|Get]", string.Format("meetingUrl = {0} d (PurchaseDate) = {1} c (TicketFromUrl) = {2}", meetingUrl, d, c)); //Webcast and Rebroadcast access test course if(meetingUrl.ToLower() == "test_room") { var baseUrl = ConfigurationManager.AppSettings["Connect.Url"]; var testUrl = ConfigurationManager.AppSettings["Connect.AccessTestMeetingUrl"]; var accessTestUrl = baseUrl + '/' + testUrl; return Redirect(accessTestUrl); } var meetingType = meetingUrl.Contains('-') ? MeetingType.Elucidat : MeetingType.Adobe; if(meetingType == MeetingType.Elucidat) { var releaseCode = meetingUrl.Substring(meetingUrl.IndexOf('-') + 1); Extensions.LogServiceCall("[IndexController][Login|Get]", string.Format("meetingUrl = {0} releaseCode = {1}", meetingUrl, releaseCode)); ReleaseModel release = ElucidatMeetingConnection.GetReleaseDetails(releaseCode); string projectName = null; if(release != null && release.Project != null) { projectName = release.Project.Name; } return View("elucidatlogin", new ElucidatCourseView {Name = projectName, Url = meetingUrl, PurchaseDate = d, TicketFromUrl = c, Message = null}); } //if (ConfigurationManager.AppSettings["CPE.AdobeTicketingOn"].ToLower() == "true") //{ // //The flag is unnecessary now since we're keeping magic passcode access available. Non-ticketed link is now magicTicket // } XmlDocument meeting = AdobeMeetingConnection.getAdobeMeeting(meetingUrl); if(meeting != null) { if(meeting.SelectSingleNode("//sco") .Attributes["icon"].Value != "archive") { return View("login", new AdobeMeetingView { Name = meeting.SelectSingleNode("//sco/name") .InnerText, HasPassCode = meeting.SelectSingleNode("//meeting-passcode") != null, PurchaseDate = d, TicketFromUrl = c }); } } return null; } [HttpPost] public ActionResult Login(string meetingUrl, string firstname, string lastname, string email, string passcode, string courseName, string ticket = null, string ticketFromUrl = null, string purchaseDate = null, string message = null) { meetingUrl = meetingUrl?.Trim(); firstname = firstname?.Trim(); lastname = lastname?.Trim(); email = email?.Trim(); passcode = passcode?.Trim(); courseName = courseName?.Trim(); ticket = ticket?.Trim(); ticketFromUrl = ticketFromUrl?.Trim(); purchaseDate = purchaseDate?.Trim(); message = message?.Trim(); Extensions.LogServiceCall("[IndexController][Login|Post]", string.Format("email = {0} meetingUrl = {1} ticket = {2} ticketFromUrl = {3} purchaseDate = {4} firstname = {5} lastname = {6} passcode = {7} courseName = {8}", email, meetingUrl, ticket, ticketFromUrl, purchaseDate, firstname, lastname, passcode, courseName)); var magicTicketLogin = string.IsNullOrEmpty(ticketFromUrl); var meetingType = meetingUrl.Contains('-') ? MeetingType.Elucidat : MeetingType.Adobe; if(meetingType.Equals(MeetingType.Elucidat)) { var releaseCode = meetingUrl.Substring(meetingUrl.IndexOf('-') + 1); if(!ticket.Equals(ticketFromUrl) || !VerifyAccess.VerifyTicket(ticket, meetingUrl, firstname, lastname, email, purchaseDate)) { return View("elucidatlogin", new ElucidatCourseView { Url = meetingUrl, Name = courseName, PurchaseDate = purchaseDate, TicketFromUrl = ticketFromUrl, Message = "Invalid Login. Please re-enter your information. This information MUST match the information in the email you received with your passcode. If you continue to have trouble, please contact Customer Service at 1-800-544-1114 or email us at sswebcast@cpeincmail.com" } ); } PurchasedCourse course = Database.PurchasedCourses.SingleOrDefault(pc => pc.Ticket == ticket && pc.ContentUrl == meetingUrl); if(course == null) { //no purchase record yet, look for release details in database CourseDetail release = Database.CourseDetails.SingleOrDefault(r => r.ReleaseCode == releaseCode); if(release == null) { //course isn't in db yet, get details form api ReleaseModel releaseCourse = ElucidatMeetingConnection.GetReleaseDetails(releaseCode); var done = ReleaseHelper.GetReleaseDescriptionDetails(releaseCourse); if(done) { release = Database.CourseDetails.SingleOrDefault(cd => cd.ReleaseCode == releaseCode); } } string formattedPdate = purchaseDate.Substring(0, 4) + '-' + purchaseDate.Substring(4, 2) + '-' + purchaseDate.Substring(6, 2); DateTime pDate = Convert.ToDateTime(formattedPdate); course = new PurchasedCourse { ContentUrl = meetingUrl, CourseName = release.Name, FirstName = firstname, LastName = lastname, Email = email, Ticket = ticket, PurchaseDate = pDate, Presenter = release.Presenter, Fos = release.Fos, Credits = release.Credits, CertificateDate = null, FailedAttempts = 0, isManualCertificate = false }; Database.PurchasedCourses.InsertOnSubmit(course); } Database.SubmitChanges(); //verify access (PurchaseDate<1yrold) and access not revoked if(!VerifyAccess.AccessBlocked(course) && VerifyAccess.IsValid(course)) { string courseUrl = ElucidatMeetingConnection.GetLaunchLink(releaseCode, firstname, lastname, email); Regex linkParser = new Regex(@"\b(?:https?://)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); string rawString = courseUrl; string goodUrl = linkParser.Match(rawString) .Value; return Redirect(goodUrl); } //Access is expired or Revoked return View("elucidatlogin", new ElucidatCourseView { Url = meetingUrl, Name = courseName, PurchaseDate = purchaseDate, TicketFromUrl = ticketFromUrl, Message = "Access to this course is no longer available. Please contact Customer Service at 1-800-544-1114 or email us at sswebcast@cpeincmail.com" } ); } if((ConfigurationManager.AppSettings["CPE.AdobeTicketingOn"].ToLower() == "true") & !magicTicketLogin) { if(passcode == null) { passcode = (DateTime.UtcNow.ToString("MMM") + DateTime.UtcNow.Day.ToString("00")).ToLower(); } if(!ticketFromUrl.Equals(ticket)) { return RedirectToAction("Login"); } if(!VerifyAccess.VerifyTicket(ticket, meetingUrl, firstname, lastname, email, purchaseDate)) { return RedirectToAction("Login"); } //if valid continue on to existing way of doing things } string connectUrl = ConfigurationManager.AppSettings["Connect.Url"]; int accountId = int.Parse(ConfigurationManager.AppSettings["Connect.AccountId"]); string password = Guid.NewGuid() .ToString() .Replace("{", "") .Replace("}", "") .Substring(0, 8); Session admin = AdobeMeetingConnection.GetAdobeAdminSession(); var request = new Request(admin, "principal-list"); request.Parameters.Add("filter-type", "guest"); request.Parameters.Add("filter-type", "user"); request.Parameters.Add("filter-login", email); if(request.Execute() && request.Status == Status.OK) { Extensions.LogServiceCall("[IndexController][Login|Post]", string.Format("email = [{0}] request.XmlResults.InnerXml = {1}", email, request.XmlResults.InnerXml)); int principalId; if(request.XmlResults.SelectSingleNode("//principal") == null) { principalId = Connect.Login.CreateGuest(admin, email, password, email, firstname, lastname); } else { principalId = int.Parse(request.XmlResults.SelectSingleNode("//principal") .Attributes["principal-id"].Value); email = request.XmlResults.SelectSingleNode("//principal/login") .InnerText; if(request.XmlResults.SelectSingleNode("//principal") .Attributes["type"].Value == "user") return RedirectToAction("Login"); } if(principalId < 1) return RedirectToAction("Login"); Connect.Login.ResetPassword(admin, principalId, password); Session session = Connect.Login.UserLogin(email, password, connectUrl, accountId); var meetingView = new AdobeMeetingView { Name = AdobeMeetingConnection.getAdobeMeetingName(meetingUrl), PrincipalId = principalId, Url = string.Format("{0}/{1}?session={2}&launcher=false", connectUrl, meetingUrl, session.SessionKey) + (passcode == null ? "" : "&meeting-passcode=" + passcode) }; Participant participant = Database.Participants.SingleOrDefault(p => p.Principal_ID == principalId); if(participant == null) { participant = new Participant { Principal_ID = principalId, FirstName = firstname, LastName = lastname, Email = email }; Database.Participants.InsertOnSubmit(participant); } Database.SubmitChanges(); var certificateId = 0; int scoId = AdobeMeetingConnection.getAdobeMeetingSco(meetingUrl); if(!magicTicketLogin) { string formattedPdate = purchaseDate.Substring(0, 4) + '-' + purchaseDate.Substring(4, 2) + '-' + purchaseDate.Substring(6, 2); DateTime pDate = Convert.ToDateTime(formattedPdate); ParticipantPurchase purchase = Database.ParticipantPurchases.SingleOrDefault( p => p.PrincipalID == principalId & p.Ticket == ticketFromUrl & p.MeetingSco == scoId); if(purchase == null) { purchase = new ParticipantPurchase { FirstName = firstname, LastName = lastname, Email = email, PrincipalID = principalId, MeetingName = meetingView.Name, MeetingDate = DateTime.UtcNow, MeetingSco = scoId, Ticket = ticketFromUrl, PurchaseDate = pDate, EarnedCertificate = false, Credits = 0 }; Database.ParticipantPurchases.InsertOnSubmit(purchase); Extensions.LogServiceCall("[IndexController][Login|Post]", string.Format("email = {0} scoId = {1} principalId = {2} MeetingDate = {3}", email, scoId, principalId, purchase.MeetingDate)); } Database.SubmitChanges(); certificateId = purchase.Purchase_ID; } meetingView.CertificateId = certificateId; meetingView.ScoId = scoId; Extensions.LogServiceCall("[IndexController][Login|Post]", string.Format("email = {0} scoId = {1} certificateId = {2} principalId = {3}", email, scoId, certificateId, principalId)); var idCookie = new HttpCookie("id") { Value = principalId.ToString(), Expires = DateTime.UtcNow.AddDays(1) }; Response.Cookies.Add(idCookie); request = new Request(admin, "principal-update"); request.Parameters.Add("first-name", firstname); request.Parameters.Add("last-name", lastname); request.Parameters.Add("principal-id", principalId.ToString()); request.Execute(); return View("meeting", meetingView); } return RedirectToAction("Login"); } [HttpGet] public ActionResult Admin() { return View(); } public ActionResult Email() { var email = new MailMessage { To = { "sophia@sophicsystems.com" }, Subject = "[CPE] Email Test", Body = "Email test has been received.", From = new MailAddress("support@intesolv.com") }; var server = new SmtpClient("localhost"); server.Send(email); return Redirect("/"); } public ActionResult SendCerificateEmail(string email, string url, string key) { if (key != "q1w2e3") return Content("Bad key"); var course = Database.PurchasedCourses .Where(c => c.Email == email && c.ContentUrl == url) .OrderByDescending(c => c.CertificateDate).FirstOrDefault(); var done = SendEmailHelperWeb.SendCertificateEmail(course); var s = url.Split('-'); var courseName = Database.CourseDetails .FirstOrDefault(c => c.ReleaseCode == s[1])?.Name; Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} cert sent email={1} courseName={2}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName); return Content("Certificate send successfully"); } [HttpPost] public ActionResult Admin(string login, string passcode) { login = login?.Trim(); passcode = passcode?.Trim(); string systemPassword = ConfigurationManager.AppSettings["password"]; if(login == ConfigurationManager.AppSettings["login"] & passcode == systemPassword) { var reportingCookie = new HttpCookie("allowed") { Value = systemPassword, Expires = DateTime.UtcNow.AddDays(1) }; Response.Cookies.Add(reportingCookie); } return Redirect("/"); } [HttpGet] public ActionResult CourseDetails(string releaseCode) { releaseCode = releaseCode?.Trim(); var course = Database.CourseDetails.Single(cd => cd.ReleaseCode == releaseCode); var result = new ElucidatCourseViewModel { CourseDetail = course, PurchasedCoursesDataResult = Database.PurchasedCoursesData(releaseCode) .OrderByDescending(pc => pc.PurchaseDate) .ToList() }; return View(result); } [HttpGet] public ActionResult Elucidat() { if(Request.Cookies["allowed"] == null && !IsLocal()) return Redirect("http://www.cpeonline.com/webcasts"); string systemPassword = ConfigurationManager.AppSettings["password"]; if(Request.Cookies["allowed"] != null && (Request.Cookies["allowed"].Value != systemPassword)) return Redirect("http://www.cpeonline.com/webcasts"); DateTime now = DateTime.UtcNow; List courseListings = Database.CourseListingsData() .Where(cl => cl.CreatedDate != null) .OrderBy(cl => cl.Name) .ToList(); return View(courseListings); } [HttpGet] public ActionResult Wufoo(int id) { //https://cpeonline.wufoo.com/forms/cpe-webcast-evaluation/def/Field1=Jason&Field2=Wigginton&Field3-1=7&Field3-2=2&Field3=2012&Field4=1234&Field5=J.%20McIntosh&Field6=ConnectPro&Field7=Test101&Field8=Test%20topic ParticipantTracking pt = Database.ParticipantTrackings.OrderByDescending(p => p.StartDate) .FirstOrDefault(p => p.Principal_ID == id); string url = ConfigurationManager.AppSettings["Wufoo.Survey1.1"]; if(pt == null) { Extensions.LogServiceCall("[IndexController][Wufoo]", string.Format("id = {0} url = {1}", id, url)); return Redirect(url); } MeetingDetail d = pt.MeetingParticipantSession.MeetingSession.Meeting.MeetingDetail; DateTime date = Extensions.GetLocalDateTime(DateTime.UtcNow); url += string.Format(ConfigurationManager.AppSettings["Wufoo.Survey1.2"], pt.Participant.FirstName, pt.Participant.LastName, date.Month.ToString("00"), date.Day.ToString("00"), date.Year, d.TopicID, d.TopicName, d.Instructor, d.Location, d.CourseCode); Extensions.LogServiceCall("[IndexController][Wufoo]", string.Format("id = {0} url = {1}", id, url)); return Redirect(url); } public ActionResult Survey() { int id = 0; string url = ConfigurationManager.AppSettings["Wufoo.Survey1.1"]; string cookie = Request.Cookies["id"] == null ? "0" : Request.Cookies["id"].Value; int.TryParse(cookie, out id); if(id == 0) { return Redirect(url); } Extensions.LogServiceCall("[IndexController][Survey]", string.Format("id = {0}", id)); ParticipantTracking pt = Database.ParticipantTrackings.OrderByDescending(p => p.StartDate) .FirstOrDefault(p => p.Principal_ID == id); if(pt == null) return Redirect(url); MeetingDetail d = pt.MeetingParticipantSession.MeetingSession.Meeting.MeetingDetail; DateTime date = Extensions.GetLocalDateTime(DateTime.UtcNow); url += string.Format(ConfigurationManager.AppSettings["Wufoo.Survey1.2"], pt.Participant.FirstName, pt.Participant.LastName, date.Month.ToString("00"), date.Day.ToString("00"), date.Year, d.TopicID, d.TopicName, d.Instructor, d.Location, d.CourseCode); return Redirect(url); } [HttpGet] public ActionResult AllowReporting(Guid? id) { //if (id.HasValue && id == Guid.Parse("")) { // var reportingCookie = new HttpCookie("reporting") {Value = "1", Expires = DateTime.MaxValue}; // Response.Cookies.Add(reportingCookie); // return Redirect("/"); //} //return Redirect("http://www.cpeonline.com/webcasts"); return RedirectToAction("Admin"); } [HttpGet] public ActionResult GetTicket(string courseUrl) { courseUrl = courseUrl?.Trim(); TicketModel ticketInfo = new TicketModel { CourseUrl = courseUrl }; //return the view as a partial view that opens in a pretty jquery ui form (dialog) within the page, not a new page return PartialView(ticketInfo); } [HttpPost] public string GetTicket(string firstname, string lastname, string email, string contenturl) { //NOT IMPLEMENTED. possible solution to "magic ticket" request for ondemand course, since a global entry would not make sense //generate hashed ticket link for a specific user for an ondemand course. This will bypass cpe's commerce site and allow cpe customer service to generate an access link firstname = firstname?.Trim(); lastname = lastname?.Trim(); email = email?.Trim(); contenturl = contenturl?.Trim(); string purchasedate = DateTime.Now.ToString("yyyyMMdd"); var ticket = VerifyAccess.generateTicket(contenturl, firstname, lastname, email, purchasedate); var link = "http://cpeonlineselfstudywebcasts.com/" + contenturl + "?d=" + purchasedate + "&c=" + ticket; return link; } // GET: CertificateReport [HttpGet] public ActionResult CertificateReport() { List earnedCertificates = Database.CertficateData() .OrderBy(ec => ec.Course) .ToList(); return View(earnedCertificates); } public ActionResult WebcastCertificateReport() { List earnedCertificates = Database.WebcastCertficateData() .OrderBy(ec => ec.MeetingName) .ToList(); return View(earnedCertificates); } //public string SendCert(int meeting_sco, int certificate_id, int principal_id) //{ // //TODO (webcast) make outcome dictionary to return pass, fail, ineligible, or wonky:contact cust serv // string _fail = "fail"; // if (certificate_id > 0) // { // ParticipantPurchase purchase = // Database.ParticipantPurchases.FirstOrDefault(p => p.Purchase_ID == certificate_id && p.PrincipalID == principal_id); // if (purchase == null) // { // //if the certificate_id is >0 then purchase would only be null because of record being deleted while user was in the meeting, or the principalID got mis-matched // return _fail; // TODO probably return wonky, contact cust service message // } // if (!purchase.EarnedCertificate) // { // var meeting = Database.MeetingSessions.FirstOrDefault( // m => // m.Recording == false && m.SCO_ID == meeting_sco && // m.StartDate.DayOfYear == DateTime.UtcNow.DayOfYear); // if (meeting == null) // { // return _fail;//TODO return wonky // } // int meetingSessionKey = meeting.MeetingSessionKey; // MeetingParticipantSession meetingParticipantSession = // Database.MeetingParticipantSessions.FirstOrDefault( // m => m.MeetingSessionKey == meetingSessionKey && m.ParticipantKey == principal_id); // if (meetingParticipantSession == null) // { // return _fail;//TODO return wonky // } // List participantSessionsDataResult = // Database.ParticipantSessionsData(meetingSessionKey) // .ToList(); // var participantSessionsData = // participantSessionsDataResult.OrderBy(p => p.MeetingParticipantSessionKey) // .FirstOrDefault( // p => // p.MeetingParticipantSessionKey == // meetingParticipantSession.MeetingParticipantSessionKey); // if (participantSessionsData == null) // { // return _fail;//TODO is this a return wonky? it means they weren't tracked // } // MeetingSessionsDataResult meetingSession = Database.MeetingSessionsData().FirstOrDefault(m => m.MeetingSessionKey == meetingSessionKey); // if (meetingSession == null) // { // return _fail;//TODO return wonky // } // var courseLength = meetingSession.ActualSessionTime.GetValueOrDefault(); //in minutes // double courseCredits = courseLength / 50.0; //1 credit per 50 minutes // List maxCourseCredits = ConfigurationManager.AppSettings["MaxCourseCreditList"].Split(';').Select(s => double.Parse(s)).ToList(); //max credits cut list // int mx = maxCourseCredits.BinarySearch(courseCredits); //find appropriate max for this course // double maxCredits = maxCourseCredits[mx >= 0 ? mx : ~mx - 1];//...by rounding down // double realCredits = participantSessionsData.SessionCredit == null ? 0 : (double)participantSessionsData.SessionCredit.Value; //users credits per adobe // purchase.Credits = Math.Min(maxCredits, realCredits); //user awarded no more than max possible credits for the course // MeetingDetail meetingDetail = // Database.MeetingDetails.FirstOrDefault(m => m.MeetingKey == purchase.MeetingSco); // purchase.Presenter = meetingDetail == null ? "" : meetingDetail.Instructor; // double percentComplete = (participantSessionsData.SessionEngagementCount.GetValueOrDefault() == 0 ? // 1 : (participantSessionsData.SessionHeartbeatCount.GetValueOrDefault() / participantSessionsData.SessionEngagementCount.Value)); // if (percentComplete >= .75) //threshold for earning a certificate is 75% response rate // { // purchase.EarnedCertificate = true; // } // Database.SubmitChanges(); // if (purchase.EarnedCertificate) // { // //TODO with return Pass dictionary value as string.format with replace of certUrl // //string certUrl = AdobeCertificateHelper.SendWebcastCert(purchase); // //format the outcome.pass.value message with certUrl replace // //return outcome.pass with its value // return AdobeCertificateHelper.SendWebcastCert(purchase); // } // //TODO return outcome.fail // return AdobeCertificateHelper.SendFailNotice(purchase); // } // } // return _fail;// TODO return ineligible.need to make AdobeCertificateHelper.SendIneligibleNotice(principalId) //} //public participantResult ProcessParticipantResult(participantResult result, ParticipantPurchase purchase) //{ // if (purchase == null) // { // result = participantResult.Ineligible; // } // switch (result) // { // case participantResult.Ineligible: // //Ineligible for auto-cert; not sending notice. // break; // case participantResult.Fail: // AdobeCertificateHelper.SendFailNotice(purchase); // break; // case participantResult.Pass: // AdobeCertificateHelper.SendWebcastCert(purchase); // //Send Cert email; // break; // case participantResult.Wonky: // //something went wrong: send email to contact cust service? send email to cpe? do nothing? // break; // } // return result; //} //public ActionResult BatchProcessParticipantResults(int msk) //{ // List psdr = BaseController.Database.ParticipantSessionsData(msk).ToList(); // var meeting = BaseController.Database.MeetingSessions.FirstOrDefault(m => m.MeetingSessionKey == msk); // if (meeting == null) // { // return Content("Error retrieving meeting session details."); // } // var scoId = meeting.SCO_ID; // foreach (var p in psdr) // { // ParticipantPurchase purchase = null; // participantResult result = participantResult.Wonky; // var mpsk = p.MeetingParticipantSessionKey; // var meetingParticipantSession = // BaseController.Database.MeetingParticipantSessions.FirstOrDefault( // mps => mps.MeetingParticipantSessionKey == mpsk && mps.MeetingSessionKey == msk); // if (meetingParticipantSession != null) // { // var principalId = meetingParticipantSession.ParticipantKey; // purchase = BaseController.Database.ParticipantPurchases.FirstOrDefault(pp => pp.PrincipalID == principalId && pp.MeetingSco == scoId); // if (purchase == null) // { // result = participantResult.Ineligible; // } // else // { // MeetingSessionsDataResult meetingSession = Database.MeetingSessionsData().FirstOrDefault(m => m.MeetingSessionKey == msk); // if (meetingSession != null) // { // var courseLength = meetingSession.ActualSessionTime.GetValueOrDefault(); //in minutes // double courseCredits = courseLength/50.0; //1 credit per 50 minutes // List maxCourseCredits = // ConfigurationManager.AppSettings["MaxCourseCreditList"].Split(';') // .Select(s => double.Parse(s)) // .ToList(); //max credits cut list // int mx = maxCourseCredits.BinarySearch(courseCredits); // //find appropriate max for this course // double maxCredits = maxCourseCredits[mx >= 0 ? mx : ~mx - 1]; //...by rounding down // double realCredits = p.SessionCredit == null // ? 0 // : (double) p.SessionCredit.Value; //users credits // purchase.Credits = Math.Min(maxCredits, realCredits); // //user awarded no more than max possible credits for the course // MeetingDetail meetingDetail = // Database.MeetingDetails.FirstOrDefault(m => m.MeetingKey == purchase.MeetingSco); // purchase.Presenter = meetingDetail == null ? "" : meetingDetail.Instructor; // double percentComplete = // (p.SessionEngagementCount.GetValueOrDefault() == 0 // ? 1 // : (p.SessionHeartbeatCount.GetValueOrDefault()/ // p.SessionEngagementCount.Value)); // if (percentComplete >= .75) //threshold for earning a certificate is 75% response rate // { // purchase.EarnedCertificate = true; // result = participantResult.Pass; // } // else // { // result = participantResult.Fail; // } // Database.SubmitChanges(); // } // } // } // ProcessParticipantResult(result, purchase); // } // return Content("done"); //} public ActionResult Result(int principalid, int scoid) { var resultView = new SessionResultViewModel(); participantResult result = participantResult.Wonky; Extensions.LogServiceCall("[IndexController][Result]", string.Format("Beginning: principalid = {0} scoid = {1}", principalid, scoid)); Extensions.LogServiceCall("[IndexController][Result]", string.Format( "principalid = {0} scoid = {1} DateTime.UtcNow.DayOfYear = {2} DateTime.Now.DayOfYear = {3}", principalid, scoid, DateTime.UtcNow.DayOfYear, DateTime.Now.DayOfYear)); var meeting = Database.MeetingSessions.FirstOrDefault( m => m.SCO_ID == scoid && m.StartDate.DayOfYear == DateTime.UtcNow.DayOfYear); if(meeting != null) { int msk = meeting.MeetingSessionKey; MeetingParticipantSession meetingParticipantSession = Database.MeetingParticipantSessions.FirstOrDefault( m => m.MeetingSessionKey == msk && m.ParticipantKey == principalid); if(meetingParticipantSession != null) { adobe.GetAdobeTransactions(meetingParticipantSession.MeetingSession, Database); Database.SubmitChanges(); result = SessionEnd.ProcessEndOfMeetingSessionHeartbeatResultsForParticipant(Database, meetingParticipantSession); switch (result) { case participantResult.Ineligible: resultView.Message = Utilities.Result.RenderIneligibleResult(principalid); break; case participantResult.Fail: resultView.Message = Utilities.Result.RenderFailResult(principalid); break; case participantResult.Pass: resultView.Message = Utilities.Result.RenderPassResult(principalid); break; case participantResult.Wonky: resultView.Message = Utilities.Result.RenderWonkyResult(); break; } } else { Extensions.LogServiceCall("[IndexController][Result]", string.Format( "meetingParticipantSession is null: principalid = {0} scoid= {1} msk = {2}", principalid, scoid, msk)); } } else { Extensions.LogServiceCall("[IndexController][Result]", string.Format( "meeting is null: principalid = {0} scoid= {1} DateTime.UtcNow.DayOfYear = {2} DateTime.Now.DayOfYear = {3}", principalid, scoid, DateTime.UtcNow.DayOfYear, DateTime.Now.DayOfYear)); } resultView.Result = (int) result; return View("result", resultView); } } }