public IActionResult Notifications(EnumList.Notifications type, EnumList.NotifyMethod method, bool receive = false) { //ToDo :: Implement Method here var userId = _access.GetUserId(User); if (string.IsNullOrEmpty(userId)) { return(BadRequest()); } var user = _context.Users.Find(userId); if (user == null) { return(BadRequest()); } var userNotifications = _context.NoNotifications.Where(x => x.UserId == userId).Where(x => x.Method == method).ToList(); if (receive) { if (!userNotifications.Any()) { return(BadRequest()); } var notification = userNotifications.SingleOrDefault(x => x.NotificationType == type); if (notification == null) { return(BadRequest()); } _context.Remove(notification); _context.SaveChanges(); return(Ok()); } if (userNotifications.Any(x => x.NotificationType == type)) { return(BadRequest()); } var newNotNotify = new NoNotification { User = user, NotificationType = type, Method = method }; _context.Add(newNotNotify); _context.SaveChanges(); return(Ok()); }
private async Task SaveNotification(ApplicationUser user, string body, EnumList.Notifications type, string reference) { //ToDo :: Check if the phone is confirmed before you send this sms var notification = new Notification() { User = user, Body = body, PhoneNumber = $"{user.PhoneCode}{user.PhoneNumber}", Method = EnumList.NotifyMethod.SMS, Type = type, Reference = reference }; await _context.AddAsync(notification); await _context.SaveChangesAsync(); }
private bool AcceptNotification(string userId, EnumList.Notifications type) { if (type == EnumList.Notifications.Admin) { return(true); } //ToDO :: Possible database failure here, there must be .ToList() after the Where(). return(!_context.NoNotifications.Where(x => x.UserId == userId) .Where(x => x.Method == EnumList.NotifyMethod.SMS) .Any(x => x.NotificationType == type)); }
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); }