예제 #1
0
        private async Task <List <Attachment> > Attachments(string objectReference, EnumList.Notifications notification)
        {
            var attachments = new List <Attachment>();

            switch (notification)
            {
            case EnumList.Notifications.InvoiceReminder:
            case EnumList.Notifications.InvoiceReceipt:

                var invoice = await _context.Invoices.FindAsync(int.Parse(objectReference));

                var courseName      = _context.Courses.Find(invoice.CourseId)?.Subject;
                var invoiceFile     = _pdf.GetInvoicePdfAttachment(invoice.Number);
                var invoiceFileName = invoice.Paid
                        ? $"Kvittering - {invoice.Number} - {courseName}.pdf"
                        : $"{invoice.InvoiceType.ToString()} - {invoice.Number} - {courseName}.pdf";

                attachments.Add(new Attachment()
                {
                    Data = invoiceFile, ContentType = "application/pdf", Filename = invoiceFileName
                });


                break;

            case EnumList.Notifications.PlusApplicationInvoices:
                var applicationInvoices = _context.Invoices.Where(x => x.ApplicationId == objectReference).ToList();

                foreach (var appInvoice in applicationInvoices)
                {
                    var appInvoiceFile     = _pdf.GetInvoicePdfAttachment(appInvoice.Number);
                    var appInvoiceFileName = $"Faktura - {appInvoice.Number}.pdf";

                    attachments.Add(new Attachment()
                    {
                        Data = appInvoiceFile, ContentType = "application/pdf", Filename = appInvoiceFileName
                    });
                }


                break;


            case EnumList.Notifications.Admin:
                //ToDo :: Check if there is an temp attachment in folder, attach it then find way to delete it
                break;

            case EnumList.Notifications.CourseRegisterConfirmation:
                var registerKeys = objectReference.Split(",").ToList();
                if (registerKeys.Count < 2)
                {
                    return(new List <Attachment>());
                }

                var registration = _context.Registrations.Where(x => x.StudentId == registerKeys[1])
                                   .SingleOrDefault(x => x.CourseId == registerKeys[0]);

                if (registration == null || !string.IsNullOrEmpty(registration.ApplicationId))
                {
                    return(new List <Attachment>());
                }


                var registerConfirmationFile = _pdf.RegistrationsConfirmationPdfAttachment(new List <string> {
                    registration.CourseId
                }, registration.StudentId);
                attachments.Add(new Attachment()
                {
                    Data = registerConfirmationFile, ContentType = "application/pdf", Filename = "Påmeldingsbekreftelse.pdf"
                });

                break;

            case EnumList.Notifications.PlusApplicationReceivedUser:
                var applicationUser   = _context.PlusApplications.Find(objectReference);
                var admissionFileUser = _pdf.GetMatterixApplicationAttachment(applicationUser.Id,
                                                                              EnumList.MatterixPlusRegDocument.Approval);
                attachments.Add(new Attachment()
                {
                    Data = admissionFileUser, ContentType = "application/pdf", Filename = "Godkjenningsdokument.pdf"
                });
                break;

            case EnumList.Notifications.PlusApplicationReceivedOrg:
                var application = _context.PlusApplications.Find(objectReference);

                var aboutSchoolFile = _pdf.GetMatterixApplicationAttachment(application.Id,
                                                                            EnumList.MatterixPlusRegDocument.AboutSchool);
                attachments.Add(new Attachment()
                {
                    Data = aboutSchoolFile, ContentType = "application/pdf", Filename = "Litt om Matterix skole.pdf"
                });

                var courseDescriptionFile = _pdf.GetMatterixApplicationAttachment(application.Id,
                                                                                  EnumList.MatterixPlusRegDocument.CoursesDescription);
                attachments.Add(new Attachment()
                {
                    Data = courseDescriptionFile, ContentType = "application/pdf", Filename = "Kursbeskrivelse.pdf"
                });

                var admissionFile = _pdf.GetMatterixApplicationAttachment(application.Id,
                                                                          EnumList.MatterixPlusRegDocument.Approval);
                attachments.Add(new Attachment()
                {
                    Data = admissionFile, ContentType = "application/pdf", Filename = "Godkjenningsdokument.pdf"
                });

                break;

            case EnumList.Notifications.PlusApplicationAccepted:

                var registrationApplication = _context.PlusApplications.Find(objectReference);

                var courseIds = registrationApplication.CoursesIds.Split(",").ToList();


                var registrationFile = _pdf.RegistrationsConfirmationPdfAttachment(courseIds, registrationApplication.StudentId);
                attachments.Add(new Attachment()
                {
                    Data = registrationFile, ContentType = "application/pdf", Filename = "Påmeldingsbekreftelse.pdf"
                });


                break;

            case EnumList.Notifications.ImportantUpdate:
            case EnumList.Notifications.OfferAndOther:
            case EnumList.Notifications.LectureStart:
            case EnumList.Notifications.CourseUpdate:
            default:
                return(new List <Attachment>());
            }



            return(attachments);
        }