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
using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Text.RegularExpressions;
using System.Reflection;
using CPE.App.Api.Models;
using CPE.App.Api.Helpers;
using CPE.App.Web.Code;
using CPE.App.Web.Controllers;
using CPE.App.Web.Models;
using Spire.Doc;
using Spire.Doc.Fields;
using Spire.Doc.Documents;
using LicenseProvider = Spire.License.LicenseProvider;

namespace CPE.App.Api.Controllers
{
    public class CertificateController : Controller
    {
        //
        // GET: /Certificate/
        public FileResult Index(string a, string b, string c)
        {
                //Utilities.LogWrapper.Info("[CertificateController][Index] a={0} b={1} c={2}", a, b, c);

                //LicenseProvider.SetLicenseFileName("license.elic.xml");
                //Spire.License.LicenseProvider.SetLicenseKey("X9zoH5wBACEkbxZBCckEWQN59jBmfbv1DANzUFP9L1QeYw1g3vaSx7rFIdgJgwYVNADZby8Wz5sqiRAqqlQ9JOoIp7VkMynAuujR6NjAR4jokDEQisMYeDIYKSAz0rC6d/tLi1u5ljU70MH+JNMWjUTkWrVU1rO4CBJ0NeF8HcUX13LcYI9Nh7nrdKa5nGjnowPhRKB0kk94B5iAFY3am8EdPiisLKYFSmYffAiLdy4cWfxXTnBushMV+1edF/NCDXzq+LQ4aeMytyPN4H9CsJJarQlcgje/yquDt6HMwA0zwUlsb2x4wKZzG00pjXB4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24Q5aZd8HSgSNv8NDoY83H4kw98yYTfUc09HJVlHDbcBqjBcHwvFnZ85HjKp4dp+ePY3LpCSo/Wm26kaXIhUZ2eR8uA72qO/j");
                //Spire.License.LicenseProvider.LoadLicense();  
                LicenseProvider.ClearLicense();

                var fileInfo = new FileInfo(Server.MapPath("~/static/doc/license.elic.xml"));
                LicenseProvider.SetLicenseFile(fileInfo);
                LicenseProvider.LoadLicense();

                var test = LicenseProvider.GetLicenseFileName();

                string formattedPdate = b.Substring(0, 4) + '-' + b.Substring(4, 2) + '-' + b.Substring(6, 2);
                DateTime cDate = Convert.ToDateTime(formattedPdate);
            Document cert = new Document();
            if (a.Contains('-'))
            {
                PurchasedCourse purchasedCourse =
                    BaseController.Database.PurchasedCourses.FirstOrDefault(
                        pc => pc.ContentUrl == a && pc.CertificateDate.Value.Date == cDate.Date && pc.Ticket == c);
                
                cert.LoadFromFile(Server.MapPath("~/static/doc/selfstudycert.docx"));

                foreach (var p in purchasedCourse.GetType().GetProperties())
                {
                    if (p.ToString().IndexOf("FailedAttempts") < 0)
                    {
                        var token = p.GetValue(purchasedCourse, null).ToString();
                        DateTime dateToken;
                        if ((DateTime.TryParse(token, out dateToken)) && (p.Name.IndexOf("Credits") < 0))
                        {
                            token = dateToken.ToShortDateString();
                        }

                        var value = p.Name;
                        //Utilities.LogWrapper.Info("[CertificateController][Index] PurchasedCourse.Properties cert.Replace value={0} token={1}", value, token);
                        cert.Replace(value, token, true, true);
                    }
                }
            }
            else
            {
                ParticipantPurchase purchase = BaseController.Database.ParticipantPurchases.FirstOrDefault(
                        pc => pc.MeetingSco.ToString() == a && pc.PurchaseDate == cDate.Date && pc.Ticket == c);

                MeetingDetail detail =
                    BaseController.Database.MeetingDetails.FirstOrDefault(md => md.MeetingKey.ToString() == a);
                cert.LoadFromFile(Server.MapPath("~/static/doc/webcastcert.docx"));

                foreach (var p in purchase.GetType().GetProperties())
                {

                    var token = p.GetValue(purchase, null)?.ToString() ?? "";
                    DateTime dateToken;
                    if ((DateTime.TryParse(token, out dateToken)) && (p.Name.IndexOf("Credits") < 0))
                    {
                        token = dateToken.ToShortDateString();
                    }
                   //Certificate Credits are only awarded in whole or half credits. Always rounded down.
                    if (p.ToString().IndexOf("Credits") > -1)
                    {
                        float fToken = float.Parse(token);
                        double roundedRating = (Math.Floor(2 * fToken)) / 2;
                        token = roundedRating.ToString(".0");
                    }

                    var value = p.Name;
                    //Utilities.LogWrapper.Info("[CertificateController][Index] ParticipantPurchase.Properties cert.Replace value={0} token={1}", value, token);
                    cert.Replace(value, token, true, true);

                }
                foreach (var d in detail.GetType().GetProperties())
                {
                    if (d.ToString().IndexOf("Location") < 0)
                    {
                        var token = d.GetValue(detail, null).ToString();
                        var value = d.Name;
                        //Utilities.LogWrapper.Info("[CertificateController][Index] MeetingDetail.Properties cert.Replace value={0} token={1}", value, token);
                        cert.Replace(value, token, true, true);
                    }
                    
                }
            }

            //Utilities.LogWrapper.Info("[CertificateController][Index] cert.Replace value=IssueDate token=DateTime.Now");
            cert.Replace("IssueDate", DateTime.Now.ToShortDateString(), false, false);

            MemoryStream stream = new MemoryStream();

                cert.SaveToStream(stream, FileFormat.PDF);

                cert.Close();

                stream.Flush();
                stream.Position = 0;
                Response.AppendHeader("Content-Disposition", "inline; filename=Certificate.pdf");
                return File(stream, "application/pdf");

        }

        //GET: /Certificate/Resend
        public ActionResult Resend(PurchasedCourse course)
        {
            //return a mailto dialog with the cert pdf attached
            return View();
        }
	}
}

Commits for CPE_learningsite/CPE/CPE.App/CPE.App.Api/Controllers/CertificateController.cs

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

initial commit