2 using System.Collections.Generic;
3 using System.Configuration;
4 using System.Data.Entity;
8 using CPE.App.Web.Models;
9 using CPE.App.Web.Code;
11 namespace CPE.App.Web.Controllers
13 public class AccessController : Controller
17 public ActionResult Revoke(BlockedPurchase blockedCourse)
19 BaseController.Database.BlockedPurchases.InsertOnSubmit(blockedCourse);
22 BaseController.Database.SubmitChanges();
33 public ActionResult Restore(BlockedPurchase blockedCourse)
35 BlockedPurchase course =
36 BaseController.Database.BlockedPurchases.SingleOrDefault(
38 bc.Ticket == blockedCourse.Ticket && bc.ContentUrl == blockedCourse.ContentUrl &&
39 bc.Email == blockedCourse.Email);
42 BaseController.Database.BlockedPurchases.DeleteOnSubmit(course);
45 BaseController.Database.SubmitChanges();
56 public ActionResult OverrideCert(PurchasedCourse purchasedCourse)
58 PurchasedCourse pCourse =
59 BaseController.Database.PurchasedCourses.FirstOrDefault(
61 pc.Ticket == purchasedCourse.Ticket && pc.ContentUrl == purchasedCourse.ContentUrl &&
62 pc.Email == purchasedCourse.Email && pc.CertificateDate == null);
65 pCourse.CertificateDate = DateTime.Now;
67 pCourse.isManualCertificate = true;
71 BaseController.Database.SubmitChanges();
82 public ActionResult OverridePoll(int mpsk, int msk, double creds)
84 var meeting = BaseController.Database.MeetingSessions.FirstOrDefault(m => m.MeetingSessionKey == msk);
87 return Content("Error retrieving meeting session details.");
89 var scoId = meeting.SCO_ID;
92 List<ParticipantEngagement> missedEngagements =
93 BaseController.Database.ParticipantEngagements.Where(
94 pe => pe.MeetingParticipantSessionKey == mpsk && pe.ResponseTime == null)
98 foreach (var missed in missedEngagements)
100 if (principalId == 0) //updating principalid on the first loop, it will be the same for each item
102 principalId = missed.Principal_ID;
104 missed.ResponseTime = DateTime.UtcNow;
108 BaseController.Database.SubmitChanges();
116 BaseController.Database.ParticipantPurchases.FirstOrDefault(
117 p => p.PrincipalID == principalId && p.MeetingSco == scoId && p.EarnedCertificate == false);
118 if (purchase == null)
122 "This participant is not eligible for an Autmomated Certificate, because they logged in using a magic ticket instead of a unique hashed-ticket, but their Poll Responses have been updated.");
125 var meetingSession = BaseController.Database.MeetingSessionsData().FirstOrDefault(m => m.MeetingSessionKey == msk);
127 var courseLength = meetingSession.ActualSessionTime.GetValueOrDefault(); //in minutes
128 double courseCredits = courseLength / 50.0; //1 credit per 50 minutes
129 List<double> maxCourseCredits = ConfigurationManager.AppSettings["MaxCourseCreditList"].Split(';').Select(s => double.Parse(s)).ToList(); //max credits cut list
130 int mx = maxCourseCredits.BinarySearch(courseCredits); //find appropriate max for this course
131 double maxCredits = maxCourseCredits[mx >= 0 ? mx : ~mx - 1];//...by rounding down
132 double realCredits = creds;
133 purchase.Credits = Math.Min(maxCredits, realCredits); //user awarded no more than max possible credits for the course
135 purchase.EarnedCertificate = true;
136 purchase.IsForced = true;
141 BaseController.Database.SubmitChanges();
147 return Content("Poll responses successfully updated. User should now be eligible for a certificate.");