/// <summary> /// Add a new record. /// </summary> /// <param name="tclass">Model class.</param> public void Add(NotificationGroupModel tclass) { try { var watch = new Stopwatch(); watch.Start(); var userId = this.AuthenticationSession.GetUserId(); var entity = new NotificationGroup { UniqueId = tclass.UniqueId, Description = tclass.Description, TemplateId = tclass.TemplateId, StartDate = tclass.StartDate, Status = (int)NotificationGroupStatus.NotProcessed, CompletedDate = tclass.CompletedDate, IsDeleted = tclass.IsDeleted, CreatedBy = userId, Created = DateTime.Now, ChangedBy = userId, Changed = DateTime.Now }; this.Entities.AddToNotificationGroups(entity); watch.Stop(); Log.Debug(string.Format("A new notification group has been added. Took {0}", watch.Elapsed)); } catch (Exception ex) { Log.Exception(ex); } }
public async Task <Notification> CreateLinkedNotificationAsync(Notification notification, ClaimsPrincipal user) { var linkedNotification = await CreateNewNotificationForUserAsync(user); _context.Attach(linkedNotification); _context.SetValues(linkedNotification.PatientDetails, notification.PatientDetails); await _notificationRepository.SaveChangesAsync(); if (notification.GroupId != null) { linkedNotification.GroupId = notification.GroupId; await _notificationRepository.SaveChangesAsync(); } else { var group = new NotificationGroup(); _context.NotificationGroup.Add(group); await _notificationRepository.SaveChangesAsync(NotificationAuditType.Added); linkedNotification.GroupId = group.NotificationGroupId; await _notificationRepository.SaveChangesAsync(); notification.GroupId = group.NotificationGroupId; await _notificationRepository.SaveChangesAsync(); } return(linkedNotification); }
public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,GroupId")] NotificationGroup notificationGroup) { if (id != notificationGroup.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(notificationGroup); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NotificationGroupExists(notificationGroup.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["GroupId"] = new SelectList(_context.Set <Group>(), "Id", "Id", notificationGroup.GroupId); ViewData["UserId"] = new SelectList(_context.Set <ApplicationUser>(), "Id", "Id", notificationGroup.UserId); return(View(notificationGroup)); }
public async Task <IActionResult> AddEmailToGroup(int groupid, int emailId) { var grp = new NotificationGroup { GroupId = groupid, EmailNotificationId = emailId }; bionoContext.NotificationGroups.Add(grp); await bionoContext.SaveChangesAsync(); return(Ok()); }
public ActionResult ReadNotification(int notificationId) { TeemaDBEntities entities = new TeemaDBEntities(); NotificationGroup notification = entities.NotificationGroups.Find(notificationId); if (notification.User.Username == User.Identity.Name) { notification.Seen = true; entities.SaveChangesAsync(); } return(new EmptyResult()); }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsServiceXmlReader reader) { reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Notification); do { NotificationGroup notifications = new NotificationGroup(); notifications.SubscriptionId = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.SubscriptionId); notifications.Events = new Collection<NotificationEvent>(); lock (this) { this.events.Add(notifications); } do { reader.Read(); if (reader.IsStartElement()) { string eventElementName = reader.LocalName; EventType eventType; if (GetEventsResults.XmlElementNameToEventTypeMap.TryGetValue(eventElementName, out eventType)) { if (eventType == EventType.Status) { // We don't need to return status events reader.ReadEndElementIfNecessary(XmlNamespace.Types, eventElementName); } else { this.LoadNotificationEventFromXml( reader, eventElementName, eventType, notifications); } } else { reader.SkipCurrentElement(); } } } while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Notification)); reader.Read(); } while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Notifications)); }
public async Task <IActionResult> Create([Bind("Id,UserId,GroupId")] NotificationGroup notificationGroup) { if (ModelState.IsValid) { _context.Add(notificationGroup); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["GroupId"] = new SelectList(_context.Set <Group>(), "Id", "Id", notificationGroup.GroupId); ViewData["UserId"] = new SelectList(_context.Set <ApplicationUser>(), "Id", "Id", notificationGroup.UserId); return(View(notificationGroup)); }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsServiceXmlReader reader) { reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Notification); do { NotificationGroup notifications = new NotificationGroup(); notifications.SubscriptionId = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.SubscriptionId); notifications.Events = new Collection <NotificationEvent>(); lock (this) { this.events.Add(notifications); } do { reader.Read(); if (reader.IsStartElement()) { string eventElementName = reader.LocalName; EventType eventType; if (GetEventsResults.XmlElementNameToEventTypeMap.TryGetValue(eventElementName, out eventType)) { if (eventType == EventType.Status) { // We don't need to return status events reader.ReadEndElementIfNecessary(XmlNamespace.Types, eventElementName); } else { this.LoadNotificationEventFromXml( reader, eventElementName, eventType, notifications); } } else { reader.SkipCurrentElement(); } } }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Notification)); reader.Read(); }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Notifications)); }
public async Task <List <Notification> > AddLinkedNotificationsAsync(List <Notification> notifications) { if (notifications.Count > 1) { var group = new NotificationGroup(); _context.NotificationGroup.Add(group); notifications.ForEach(n => n.Group = group); } _context.Notification.AddRange(notifications); _context.AddAuditCustomField(CustomFields.AuditDetails, NotificationAuditType.Imported); await _context.SaveChangesAsync(); return(notifications); }
public async Task NotificationsWithDuplicateNamesAndDobs_CorrectlyIgnoresNonDuplicates( NotificationStatus status1, NotificationStatus status2, string groupName1, string groupName2, string givenName1, string givenName2, string familyName1, string familyName2, string dob1, string dob2) { // Arrange var group1 = new NotificationGroup(); var group2 = new NotificationGroup(); await _context.NotificationGroup.AddRangeAsync(group1, group2); var notification1 = new Notification { NotificationStatus = status1, NotificationDate = DateTime.Now, Group = groupName1 == "1" ? group1 : groupName1 == "2" ? group2 : null, PatientDetails = new PatientDetails { GivenName = givenName1, FamilyName = familyName1, Dob = dob1 == null ? null : (DateTime?)DateTime.Parse(dob1) } }; var notification2 = new Notification { NotificationStatus = status2, NotificationDate = DateTime.Now, Group = groupName2 == "1" ? group1 : groupName2 == "2" ? group2 : null, PatientDetails = new PatientDetails { GivenName = givenName2, FamilyName = familyName2, Dob = dob1 == null ? null : (DateTime?)DateTime.Parse(dob2) } }; await _context.AddRangeAsync(notification1, notification2); await _context.SaveChangesAsync(); var repo = new DataQualityRepository(_context); // Act var notificationIds = await repo.GetNotificationIdsEligibleForDqPotentialDuplicateAlertsAsync(); // Assert Assert.Empty(notificationIds); }
public static int Count(int UserId = 0, NotificationGroup GroupId = NotificationGroup.None) { using (var ctx = new AgrishareEntities()) { var query = ctx.Notifications.Include(o => o.Booking).Include(o => o.Booking.Service).Include(o => o.Booking.Service.Listing).Where(o => !o.Deleted && !o.Booking.Deleted && !o.Booking.Service.Deleted && !o.Booking.Service.Listing.Deleted); if (UserId > 0) { query = query.Where(o => o.UserId == UserId); } if (GroupId != NotificationGroup.None) { query = query.Where(o => o.GroupId == GroupId); } return(query.Count()); } }
public async Task NotificationsWithDuplicateNhsNumbers_CorrectlyFindsDuplicates( NotificationStatus status1, NotificationStatus status2, string groupName1, string groupName2, string nhsNumber1, string nhsNumber2) { // Arrange var group1 = new NotificationGroup(); var group2 = new NotificationGroup(); await _context.NotificationGroup.AddRangeAsync(group1, group2); var notification1 = new Notification { NotificationStatus = status1, NotificationDate = DateTime.Now, Group = groupName1 == "1" ? group1 : groupName1 == "2" ? group2 : null, PatientDetails = new PatientDetails { NhsNumber = nhsNumber1, } }; var notification2 = new Notification { NotificationStatus = status2, NotificationDate = DateTime.Now, Group = groupName2 == "1" ? group1 : groupName2 == "2" ? group2 : null, PatientDetails = new PatientDetails { NhsNumber = nhsNumber2, } }; await _context.AddRangeAsync(notification1, notification2); await _context.SaveChangesAsync(); var repo = new DataQualityRepository(_context); // Act var notificationIds = await repo.GetNotificationIdsEligibleForDqPotentialDuplicateAlertsAsync(); // Assert AssertDuplicatePairIsFound(notificationIds, notification1.NotificationId, notification2.NotificationId); }
/// <summary> /// Loads a notification event from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="eventElementName">Name of the event XML element.</param> /// <param name="eventType">Type of the event.</param> /// <param name="notifications">Collection of notifications</param> private void LoadNotificationEventFromXml( EwsServiceXmlReader reader, string eventElementName, EventType eventType, NotificationGroup notifications) { DateTime timestamp = reader.ReadElementValue <DateTime>(XmlNamespace.Types, XmlElementNames.TimeStamp); NotificationEvent notificationEvent; reader.Read(); if (reader.LocalName == XmlElementNames.FolderId) { notificationEvent = new FolderEvent(eventType, timestamp); } else { notificationEvent = new ItemEvent(eventType, timestamp); } notificationEvent.LoadFromXml(reader, eventElementName); notifications.Events.Add(notificationEvent); }
private async Task <Dictionary <string, string> > GenerateDuplicateNhsNumberNotificationUrlsAsync(string nhsNumber, NotificationGroup group) { // If NhsNumber is empty or does not pass validation - return null // Potential duplication of validation here so that both Server and Dynamic/JS routes to warnings // can use the same method. if (string.IsNullOrEmpty(nhsNumber) || !string.IsNullOrEmpty( ValidationService.GetPropertyValidationResult <PatientDetails>("NhsNumber", nhsNumber, false).Content)) { return(null); } var ntbsNhsNumberMatchesTask = NotificationRepository.GetNotificationIdsByNhsNumberAsync(nhsNumber); var legacyNhsNumberMatchesTask = _migrationRepository.GetLegacyNotificationNhsNumberMatches(nhsNumber); var ntbsNhsNumberMatches = await ntbsNhsNumberMatchesTask; var legacyNhsNumberMatches = await legacyNhsNumberMatchesTask; var idsInGroup = group?.Notifications?.Select(n => n.NotificationId) ?? new List <int>(); var filteredNtbsIdDictionary = ntbsNhsNumberMatches .Except(idsInGroup) .Where(n => n != NotificationId) .ToDictionary( id => id.ToString(), id => RouteHelper.GetNotificationPath(id, NotificationSubPaths.Overview)); var legacyIdDictionary = legacyNhsNumberMatches.ToDictionary( match => $"{match.Source}: {match.OldNotificationId}", match => RouteHelper.GetLegacyNotificationPath(match.OldNotificationId)); return(filteredNtbsIdDictionary.Concat(legacyIdDictionary).ToDictionary(x => x.Key, x => x.Value)); }
public static List <Notification> List(int PageIndex = 0, int PageSize = int.MaxValue, string Sort = "", int UserId = 0, NotificationGroup GroupId = NotificationGroup.None, int BookingId = 0, NotificationType Type = NotificationType.None) { using (var ctx = new AgrishareEntities()) { var query = ctx.Notifications.Include(o => o.Booking).Include(o => o.Booking.Service).Include(o => o.Booking.Service.Listing).Where(o => !o.Deleted && !o.Booking.Deleted && !o.Booking.Service.Deleted && !o.Booking.Service.Listing.Deleted); if (UserId > 0) { query = query.Where(o => o.UserId == UserId); } if (GroupId != NotificationGroup.None) { query = query.Where(o => o.GroupId == GroupId); } if (BookingId > 0 && Type != NotificationType.None) { query = query.Where(e => e.BookingId == BookingId && e.TypeId == Type); } query = query.OrderBy(Sort.Coalesce(DefaultSort)); return(query.Skip(PageIndex * PageSize).Take(PageSize).ToList()); } }
private async Task <Dictionary <string, string> > GenerateDuplicateNhsNumberNotificationUrlsAsync(string nhsNumber, NotificationGroup group) { // If NhsNumber is empty or does not pass validation - return null // Potential duplication of validation here so that both Server and Dynamic/JS routes to warnings // can use the same method. if (string.IsNullOrEmpty(nhsNumber) || !string.IsNullOrEmpty( ValidationService.GetPropertyValidationResult <PatientDetails>("NhsNumber", nhsNumber, false).Content)) { return(null); } var notificationIds = await NotificationRepository.GetNotificationIdsByNhsNumberAsync(nhsNumber); var idsInGroup = group?.Notifications?.Select(n => n.NotificationId) ?? new List <int>(); var filteredIds = notificationIds .Except(idsInGroup) .Where(n => n != NotificationId) .ToDictionary( id => id.ToString(), id => RouteHelper.GetNotificationPath(id, NotificationSubPaths.Overview)); return(filteredIds); }
/// <summary> /// Loads a notification event from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="eventElementName">Name of the event XML element.</param> /// <param name="eventType">Type of the event.</param> /// <param name="notifications">Collection of notifications</param> private void LoadNotificationEventFromXml( EwsServiceXmlReader reader, string eventElementName, EventType eventType, NotificationGroup notifications) { DateTime timestamp = reader.ReadElementValue<DateTime>(XmlNamespace.Types, XmlElementNames.TimeStamp); NotificationEvent notificationEvent; reader.Read(); if (reader.LocalName == XmlElementNames.FolderId) { notificationEvent = new FolderEvent(eventType, timestamp); } else { notificationEvent = new ItemEvent(eventType, timestamp); } notificationEvent.LoadFromXml(reader, eventElementName); notifications.Events.Add(notificationEvent); }