public async Task <MonitoringSession> GetNewSession(
            int profileId
            )
        {
            bool hasMonitorTagFilter = await _context.ProfilesTagSelection
                                       .AnyAsync(pts => pts.BindedProfileID == profileId &&
                                                 ProfileSelectedTagFlags.Monitor ==
                                                 (pts.Flags & ProfileSelectedTagFlags.Monitor));

            int monitoredNodesNum = hasMonitorTagFilter
                ? await _context.ProfilesTagSelection.AsNoTracking()
                                    .Where(pts => pts.BindedProfileID == profileId &&
                                           ProfileSelectedTagFlags.Monitor ==
                                           (pts.Flags & ProfileSelectedTagFlags.Monitor))
                                    .Include(pts => pts.Tag)
                                    .ThenInclude(t => t.Attachments)
                                    .ThenInclude(ta => ta.Node)
                                    .SelectMany(pts => pts.Tag.Attachments.Select(ta => ta.Node))
                                    .Where(n => n.OpenPing)
                                    .Select(n => n.ID)
                                    .Distinct()
                                    .CountAsync()
                : await _context.Nodes.CountAsync(n => n.OpenPing);

            MonitoringSession newSession = new MonitoringSession
            {
                ID = 0,
                CreatedByProfileID    = profileId,
                ParticipatingNodesNum = monitoredNodesNum,
                CreationTime          = JsDateTimeNow(),
                LastPulseTime         = 0,
            };

            _context.MonitoringSessions.Add(newSession);
            await _context.SaveChangesAsync();

            _context.Entry(newSession).State = EntityState.Detached;
            return(newSession);
        }