Git Repository Public Repository

CPE_learningsite

URLs

Copy to Clipboard

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CPE.App.Web.Models;
using CPE.App.Web.Code;

namespace CPE.App.Web.Controllers
{
    public class AccessController : Controller
    {

        [HttpPost]
        public ActionResult Revoke(BlockedPurchase blockedCourse)
        {
            BaseController.Database.BlockedPurchases.InsertOnSubmit(blockedCourse);
            try
            {
                BaseController.Database.SubmitChanges();
            }
            catch
            {
                return null;
            }

            return null;
        }

        [HttpPost]
        public ActionResult Restore(BlockedPurchase blockedCourse)
        {
            BlockedPurchase course =
                BaseController.Database.BlockedPurchases.SingleOrDefault(
                    bc =>
                        bc.Ticket == blockedCourse.Ticket && bc.ContentUrl == blockedCourse.ContentUrl &&
                        bc.Email == blockedCourse.Email);
            if (course != null)
            {
                BaseController.Database.BlockedPurchases.DeleteOnSubmit(course);
                try
                {
                    BaseController.Database.SubmitChanges();
                }
                catch
                {
                    return null;
                }
            }
            return null;
        }

        [HttpPost]
        public ActionResult OverrideCert(PurchasedCourse purchasedCourse)
        {
            PurchasedCourse pCourse =
                BaseController.Database.PurchasedCourses.FirstOrDefault(
                    pc =>
                        pc.Ticket == purchasedCourse.Ticket && pc.ContentUrl == purchasedCourse.ContentUrl &&
                        pc.Email == purchasedCourse.Email && pc.CertificateDate == null);
            if (pCourse != null)
            {
                pCourse.CertificateDate = DateTime.Now;

                pCourse.isManualCertificate = true;
            }
            try
            {
                BaseController.Database.SubmitChanges();
            }
            catch
            {
                return null;
            }

            return null;
        }

        [HttpPost]
        public ActionResult OverridePoll(int mpsk, int msk, double creds)
        {
            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;

            
            List<ParticipantEngagement> missedEngagements =
                BaseController.Database.ParticipantEngagements.Where(
                    pe => pe.MeetingParticipantSessionKey == mpsk && pe.ResponseTime == null)
                    .ToList();

            var principalId = 0;
            foreach (var missed in missedEngagements)
            {
                if (principalId == 0) //updating principalid on the first loop, it will be the same for each item
                {
                    principalId = missed.Principal_ID;
                }
                missed.ResponseTime = DateTime.UtcNow;
            }
            try
            {
                BaseController.Database.SubmitChanges();
            }
            catch
            {
                return null;
            }

            var purchase =
                BaseController.Database.ParticipantPurchases.FirstOrDefault(
                    p => p.PrincipalID == principalId && p.MeetingSco == scoId && p.EarnedCertificate == false);
            if (purchase == null)
            {
                return
                    Content(
                        "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.");
            }

            var meetingSession = BaseController.Database.MeetingSessionsData().FirstOrDefault(m => m.MeetingSessionKey == msk);

            var courseLength = meetingSession.ActualSessionTime.GetValueOrDefault(); //in minutes
            double courseCredits = courseLength / 50.0; //1 credit per 50 minutes
            List<double> 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 = creds;
            purchase.Credits = Math.Min(maxCredits, realCredits); //user awarded no more than max possible credits for the course

            purchase.EarnedCertificate = true;
            purchase.IsForced = true;
  

            try
            {
                BaseController.Database.SubmitChanges();
            }
            catch
            {
                return null;
            }
            return Content("Poll responses successfully updated. User should now be eligible for a certificate.");

        }
    }
}

Commits for CPE_learningsite/CPE/CPE.App/CPE.App.Web/Controllers/AccessController.cs

Diff revisions: vs.
Revision Author Commited Message
4cd176 ... v.shishlov Fri 27 Aug, 2021 14:33:17 +0000

initial commit