protected void hlSendPush_Click(object sender, EventArgs e)
 {
     try
     {
         Button btn                = (Button)(sender);
         var    arguments          = btn.CommandArgument;
         var    notificationToSend = NotificationFilter.FetchByID(int.Parse(arguments));
         var    users              = NotificationGroups.GetUsersOfFilter(notificationToSend);
         try
         {
             Task.Run(() => Snoopi.core.FcmService.SendTemplateToMany(notificationToSend.Name, notificationToSend.MessageTemplate, users)).Wait();
         }
         catch (Exception ex)
         {
             using (System.IO.StreamWriter sw = System.IO.File.AppendText(AppDomain.CurrentDomain.BaseDirectory + @"\Output\push-log.txt"))
             {
                 sw.WriteLine(@" ------------" + DateTime.Now + "--------------------" + '\n' + "Exception  " + ex.Message + " CallStack : " + ex.StackTrace);
             }
         }
         Master.MessageCenter.DisplaySuccessMessage(NotificationStrings.GetText(@"NotificationSent"));
     }
     catch (Exception ex)
     {
         Master.MessageCenter.DisplayErrorMessage(NotificationStrings.GetText(@"DeleteErrorMessage") + " \n" + ex.Message + '\n' + ex.StackTrace);
     }
 }
Exemple #2
0
        public async Task <int> Count(NotificationFilter filter)
        {
            IQueryable <NotificationDAO> Notifications = DataContext.Notification.AsNoTracking();

            Notifications = DynamicFilter(Notifications, filter);
            return(await Notifications.CountAsync());
        }
        protected IQuery <NotificationDTO> CreateQuery(NotificationFilter filter = null)
        {
            var query = NotificationListQuery;

            query.Filter = filter;
            return(query);
        }
 public List <NotificationDTO> GetNotifications(NotificationFilter filter)
 {
     using (var unitOfWork = UnitOfWorkProvider.Create())
     {
         return(CreateQuery(filter).Execute().ToList());
     }
 }
 public ChannelSpecificDefaults(NotificationFilter filter, bool push, M2EmailNotificationType email, bool?threadsSubscribed = null)
 {
     Filter = filter;
     IsPush = push;
     Email  = email;
     IsThreadsSubscribed = threadsSubscribed;
 }
        public async Task <ActionResult <bool> > BulkDelete([FromBody] List <long> Ids)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            NotificationFilter NotificationFilter = new NotificationFilter();

            NotificationFilter    = NotificationService.ToFilter(NotificationFilter);
            NotificationFilter.Id = new IdFilter {
                In = Ids
            };
            NotificationFilter.Selects = NotificationSelect.Id;
            NotificationFilter.Skip    = 0;
            NotificationFilter.Take    = int.MaxValue;

            List <Notification> Notifications = await NotificationService.List(NotificationFilter);

            Notifications = await NotificationService.BulkDelete(Notifications);

            if (Notifications.Any(x => !x.IsValidated))
            {
                return(BadRequest(Notifications.Where(x => !x.IsValidated)));
            }
            return(true);
        }
Exemple #7
0
        public async Task <IActionResult> Get([FromBody] NotificationFilter filter)
        {
            var userId = Request.GetUserId();
            await _notificationsService.GetAsync(userId, filter);

            return(Ok());
        }
Exemple #8
0
    private NotificationFilter GetCurrentFilter()
    {
        var filter = new NotificationFilter();

        if (!IsNewMode)
        {
            filter = NotificationFilter.FetchByID(FilterId);
        }
        bool     isAuto = cbIsAuto.Checked;
        DateTime fromDate;

        DateTime.TryParse(txtFromDate.Text, out fromDate);
        DateTime toDate;

        DateTime.TryParse(txtToDate.Text, out toDate);
        int animalType, area, priority, maxFrequency, minFrequency, groupId, runEvery;

        filter.AnimalTypeId    = int.TryParse(ddlAnimalType.SelectedValue, out animalType) ? animalType : 0;
        filter.AreaId          = int.TryParse(ddlArea.SelectedValue, out area) ? area : 0;
        filter.Priority        = int.TryParse(txtPriority.Text, out priority) ? priority : 0;
        filter.FromDate        = fromDate;
        filter.ToDate          = toDate;
        filter.MaxFrequency    = int.TryParse(txtMaxFrequency.Text, out maxFrequency) ? maxFrequency : int.MaxValue;
        filter.MinFrequency    = int.TryParse(txtMinFrequency.Text, out minFrequency) ? minFrequency : 0;
        filter.Group           = (NotificationGroupsEnum)(int.TryParse(ddlFilteringGroup.SelectedValue, out groupId) ? groupId : 0);
        filter.MessageTemplate = txtMessage.Text;
        filter.Name            = txtName.Text;
        filter.IsAuto          = isAuto;
        filter.RunEvery        = int.TryParse(txtRunEvery.Text, out runEvery) ? runEvery : 25;
        return(filter);
    }
        public async Task <ActionResult <List <NotificationDTO> > > GetNotifications([FromQuery] NotificationFilter notificationFilter)
        {
            var notifications = await notificationRepository.GetNotifications(notificationFilter,
                                                                              IncludeType : true);

            return(mapper.Map <List <NotificationDTO> >(notifications));
        }
 public async Task <Notification[]> GetAsync(string userId, NotificationFilter filter = null)
 {
     filter = filter ?? new NotificationFilter
     {
         MaxCount = 50,
     };
     return(await _repository.GetAllByUserAsync(userId, filter));
 }
Exemple #11
0
    protected void LoadView()
    {
        string[] itemNames  = Enum.GetNames(typeof(NotificationGroupsEnum));
        Array    itemValues = Enum.GetValues(typeof(NotificationGroupsEnum)).Cast <int>().ToArray();

        for (int i = 0; i <= itemValues.Length - 1; i++)
        {
            string   localizationValue = NotificationStrings.GetText(itemNames[i]);
            ListItem item = new ListItem(localizationValue, itemValues.GetValue(i).ToString());
            ddlFilteringGroup.Items.Add(item);
        }
        ddlFilteringGroup.DataBind();
        var animals = AnimalCollection.FetchAll();

        animals.Add(new Animal {
            AnimalId = 0, AnimalName = "All"
        });
        ddlAnimalType.DataSource     = animals.OrderBy(x => x.AnimalId);
        ddlAnimalType.DataValueField = "AnimalId";
        ddlAnimalType.DataTextField  = "AnimalName";
        ddlAnimalType.DataBind();

        var areas = AreaCollection.FetchAll();

        areas.Add(new Area {
            AreaId = 0, AreaName = "All"
        });
        ddlArea.DataSource     = areas.OrderBy(x => x.AreaId);
        ddlArea.DataValueField = "AreaId";
        ddlArea.DataTextField  = "AreaName";
        ddlArea.DataBind();

        if (FilterId > 0)
        {
            var notificationFilter = NotificationFilter.FetchByID(FilterId);

            ddlArea.SelectedValue           = notificationFilter.AreaId.ToString();
            txtFromDate.Text                = notificationFilter.FromDate.ToString();
            txtToDate.Text                  = notificationFilter.ToDate.ToString();
            txtMaxFrequency.Text            = notificationFilter.MaxFrequency.ToString();
            txtMinFrequency.Text            = notificationFilter.MinFrequency.ToString();
            txtName.Text                    = notificationFilter.Name;
            txtPriority.Text                = notificationFilter.Priority.ToString();
            ddlAnimalType.SelectedValue     = notificationFilter.AnimalTypeId.ToString();
            ddlFilteringGroup.SelectedValue = ((int)notificationFilter.Group).ToString();
            txtMessage.Text                 = notificationFilter.MessageTemplate;
            txtRunEvery.Text                = notificationFilter.RunEvery.ToString();
            cbIsAuto.Checked                = notificationFilter.IsAuto;

            if (!string.IsNullOrEmpty(notificationFilter.AdImageUrl))
            {
                HomeImage.ImageUrl = MediaUtility.GetImagePath("Banners", notificationFilter.AdImageUrl, 0, 64, 64);
                HomeImage.ImageUrl = HomeImage.ImageUrl.Contains(".") ? HomeImage.ImageUrl : "";
                ImageFileHandler(fuImage, HomeImage, btnDeleteImage, HomeImage.ImageUrl);
            }
        }
    }
        /// <summary>
        /// Asynchronously Retrieve Notifications, with support for cancellation.
        /// </summary>
        /// <remarks>
        /// Retrieves a list of all notifications associated with your company,
        /// with optional filters to narrow down the results.
        /// </remarks>
        /// <param name="filter">
        /// An instance of the <see cref="NotificationFilter"/> class, for narrowing down the results.
        /// </param>
        /// <param name="options">
        /// An instance of the <see cref="RequestOptions"/> class, for customizing method processing.
        /// </param>
        /// <param name="cancellationToken">
        /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>
        /// An enumerable set of <see cref="Notification"/> objects, along with an output
        /// instance of the <see cref="ResultsMeta"/> class containing additional data.
        /// </returns>
        public async Task <(IList <Notification>, ResultsMeta)> GetNotificationsAsync(
            NotificationFilter filter,
            RequestOptions options,
            CancellationToken cancellationToken)
        {
            var context = new GetContext <Notification>(EndpointName.Notifications, filter, options);

            await ExecuteOperationAsync(context, cancellationToken).ConfigureAwait(false);

            return(context.Results.Items, context.ResultsMeta);
        }
Exemple #13
0
        public async Task <IEnumerable <Notification> > SearchAsync(NotificationFilter filter)
        {
            var query = entities.AsQueryable();

            if (filter.UserId > 0)
            {
                query = query.Where(i => i.UserId == filter.UserId);
            }

            query = base.SearchAsync(query, filter);

            return(await query.ToListAsync());
        }
Exemple #14
0
        public async Task <List <Notification> > List(NotificationFilter filter)
        {
            if (filter == null)
            {
                return(new List <Notification>());
            }
            IQueryable <NotificationDAO> NotificationDAOs = DataContext.Notification.AsNoTracking();

            NotificationDAOs = DynamicFilter(NotificationDAOs, filter);
            NotificationDAOs = DynamicOrder(NotificationDAOs, filter);
            List <Notification> Notifications = await DynamicSelect(NotificationDAOs, filter);

            return(Notifications);
        }
 protected void hlChechNumOfUsers(object sender, EventArgs e)
 {
     try
     {
         Button btn                = (Button)(sender);
         var    arguments          = btn.CommandArgument;
         var    notificationToSend = NotificationFilter.FetchByID(int.Parse(arguments));
         var    users              = NotificationGroups.GetUsersOfFilter(notificationToSend);
         Master.MessageCenter.DisplaySuccessMessage(NotificationStrings.GetText(@"NotificationSent"));
     }
     catch (Exception ex)
     {
         Master.MessageCenter.DisplayErrorMessage(NotificationStrings.GetText(@"DeleteErrorMessage") + " \n" + ex.Message + '\n' + ex.StackTrace);
     }
 }
Exemple #16
0
        async void LoadNotifications()
        {
            await StopNotificationsSubscription();

            bool loaded = false;
            NotificationFilter filter = new NotificationFilter()
            {
                End       = filterNotificationsEnd,
                Start     = filterNotificationsStart,
                SortOrder = SortOrder.DESC
            };
            var list = new IncrementalLoadingCollection <Notification>(async(take, skip) =>
            {
                filter.Skip = (int)skip;
                filter.Take = (int)take;
                try
                {
                    Debug.WriteLine("NTF LOAD START");
                    var notifications = await ClientService.Current.GetNotificationsAsync(deviceId, filter);
                    Debug.WriteLine("NTF LOAD END");
                    return(notifications);
                }
                catch (Exception ex)
                {
                    Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        new MessageDialog(ex.Message, "Error").ShowAsync();
                    });
                    throw ex;
                }
            }, 20);

            list.IsLoadingChanged += (s, isLoading) =>
            {
                LoadingItems += isLoading ? 1 : -1;
                if (!isLoading && !loaded)
                {
                    StartNotificationsSubscription();
                    if (s.Count > 0)
                    {
                        // makes server response faster
                        filter.End = s.First().Timestamp;
                    }
                    loaded = true;
                }
            };
            NotificationsObservable = list;
        }
 protected void hlDelete_Click(object sender, EventArgs e)
 {
     try
     {
         Button btn                  = (Button)(sender);
         var    arguments            = btn.CommandArgument;
         var    notificationToDelete = NotificationFilter.FetchByID(int.Parse(arguments));
         notificationToDelete.Deleted = DateTime.Now;
         notificationToDelete.Save();
         Master.MessageCenter.DisplaySuccessMessage(NotificationStrings.GetText(@"DeleteMessage"));
         LoadItems();
     }
     catch (Exception ex)
     {
         Master.MessageCenter.DisplayErrorMessage(NotificationStrings.GetText(@"DeleteErrorMessage") + " \n" + ex.Message + '\n' + ex.StackTrace);
     }
 }
        private NotificationFilter ConvertFilterDTOToFilterEntity(Notification_NotificationFilterDTO Notification_NotificationFilterDTO)
        {
            NotificationFilter NotificationFilter = new NotificationFilter();

            NotificationFilter.Selects   = NotificationSelect.ALL;
            NotificationFilter.Skip      = Notification_NotificationFilterDTO.Skip;
            NotificationFilter.Take      = Notification_NotificationFilterDTO.Take;
            NotificationFilter.OrderBy   = Notification_NotificationFilterDTO.OrderBy;
            NotificationFilter.OrderType = Notification_NotificationFilterDTO.OrderType;

            NotificationFilter.Id                   = Notification_NotificationFilterDTO.Id;
            NotificationFilter.Title                = Notification_NotificationFilterDTO.Title;
            NotificationFilter.Content              = Notification_NotificationFilterDTO.Content;
            NotificationFilter.OrganizationId       = Notification_NotificationFilterDTO.OrganizationId;
            NotificationFilter.NotificationStatusId = Notification_NotificationFilterDTO.NotificationStatusId;
            return(NotificationFilter);
        }
Exemple #19
0
        public Task <List <Notification> > GetNotifications(NotificationFilter filter, bool IncludeType = false, bool IncludeUser = false)
        {
            var queryable = applicationDbContext.Notifications.AsQueryable();

            if (!string.IsNullOrEmpty(filter.UserId))
            {
                queryable = queryable.Where(n => n.UserId == filter.UserId);
            }

            if (filter.OnlyNotSeen)
            {
                queryable = queryable.Where(n => !n.AlreadySeen);
            }

            if (filter.From.HasValue)
            {
                queryable = queryable.Where(n => n.Date > filter.From);
            }

            if (filter.Until.HasValue)
            {
                queryable = queryable.Where(n => n.Date < filter.Until);
            }

            if (filter.NotificationTypeId.HasValue)
            {
                queryable = queryable.Where(n => n.NotificationTypeId == filter.NotificationTypeId);
            }

            queryable = queryable.Paginate(filter);

            if (IncludeType)
            {
                queryable = queryable.Include(n => n.NotificationType);
            }
            if (IncludeUser)
            {
                queryable = queryable.Include(n => n.User);
            }

            queryable = queryable.OrderByDescending(n => n.Date);


            return(queryable.ToListAsync());
        }
        public async Task <ActionResult <int> > Count([FromBody] Notification_NotificationFilterDTO Notification_NotificationFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            NotificationFilter NotificationFilter = ConvertFilterDTOToFilterEntity(Notification_NotificationFilterDTO);

            NotificationFilter = NotificationService.ToFilter(NotificationFilter);
            int count = await NotificationService.Count(NotificationFilter);

            return(count);
        }
        public async Task <Notification[]> GetAllByUserAsync(string userId, NotificationFilter filter = null)
        {
            var result = Context.Set <Notification>().Where(t => t.Owner == userId);

            if (filter == null)
            {
                return(await result.OrderByDescending(t => t.Date).ToArrayAsync());
            }

            if (filter.HasSeen != null)
            {
                result = result.Where(t => t.HasSeen == filter.HasSeen);
            }
            if (!string.IsNullOrWhiteSpace(filter.Category))
            {
                result = result.Where(t => t.Category == filter.Category);
            }
            if (!string.IsNullOrWhiteSpace(filter.Sender))
            {
                result = result.Where(t => t.Sender == filter.Sender);
            }
            if (filter.LastNotificationsId != null)
            {
                result = result.Where(t => t.Id <= filter.LastNotificationsId);
            }
            if (filter.LastDate != null)
            {
                result = result.Where(t => t.Date <= filter.LastDate);
            }

            result = result.OrderByDescending(t => t.Date);

            if (filter.Offset != null)
            {
                result = result.Skip(filter.Offset.Value);
            }
            if (filter.MaxCount != null)
            {
                result = result.Take(filter.MaxCount.Value);
            }

            return(await result.ToArrayAsync());
        }
        public async Task <bool> ValidateId(Notification Notification)
        {
            NotificationFilter NotificationFilter = new NotificationFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = Notification.Id
                },
                Selects = NotificationSelect.Id
            };

            int count = await UOW.NotificationRepository.Count(NotificationFilter);

            if (count == 0)
            {
                Notification.AddError(nameof(NotificationValidator), nameof(Notification.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
        public async Task <ActionResult <List <Notification_NotificationDTO> > > List([FromBody] Notification_NotificationFilterDTO Notification_NotificationFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            NotificationFilter NotificationFilter = ConvertFilterDTOToFilterEntity(Notification_NotificationFilterDTO);

            NotificationFilter = NotificationService.ToFilter(NotificationFilter);
            List <Notification> Notifications = await NotificationService.List(NotificationFilter);

            List <Notification_NotificationDTO> Notification_NotificationDTOs = Notifications
                                                                                .Select(c => new Notification_NotificationDTO(c)).ToList();

            return(Notification_NotificationDTOs);
        }
 public NotificationFilter ToFilter(NotificationFilter filter)
 {
     if (filter.OrFilter == null)
     {
         filter.OrFilter = new List <NotificationFilter>();
     }
     if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
     {
         return(filter);
     }
     foreach (var currentFilter in CurrentContext.Filters)
     {
         NotificationFilter subFilter = new NotificationFilter();
         filter.OrFilter.Add(subFilter);
         List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value;
         foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions)
         {
         }
     }
     return(filter);
 }
        private async Task <bool> HasPermission(long Id)
        {
            NotificationFilter NotificationFilter = new NotificationFilter();

            NotificationFilter = NotificationService.ToFilter(NotificationFilter);
            if (Id == 0)
            {
            }
            else
            {
                NotificationFilter.Id = new IdFilter {
                    Equal = Id
                };
                int count = await NotificationService.Count(NotificationFilter);

                if (count == 0)
                {
                    return(false);
                }
            }
            return(true);
        }
        public async Task <int> Count(NotificationFilter NotificationFilter)
        {
            try
            {
                int result = await UOW.NotificationRepository.Count(NotificationFilter);

                return(result);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(NotificationService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(NotificationService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
        public async Task <List <Notification> > List(NotificationFilter NotificationFilter)
        {
            try
            {
                List <Notification> Notifications = await UOW.NotificationRepository.List(NotificationFilter);

                return(Notifications);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(NotificationService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(NotificationService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
Exemple #28
0
        private IQueryable <NotificationDAO> DynamicOrder(IQueryable <NotificationDAO> query, NotificationFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case NotificationOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

                case NotificationOrder.Title:
                    query = query.OrderBy(q => q.Title);
                    break;

                case NotificationOrder.Content:
                    query = query.OrderBy(q => q.Content);
                    break;

                case NotificationOrder.Organization:
                    query = query.OrderBy(q => q.OrganizationId);
                    break;

                case NotificationOrder.NotificationStatus:
                    query = query.OrderBy(q => q.NotificationStatusId);
                    break;
                }
                break;

            case OrderType.DESC:
                switch (filter.OrderBy)
                {
                case NotificationOrder.Id:
                    query = query.OrderByDescending(q => q.Id);
                    break;

                case NotificationOrder.Title:
                    query = query.OrderByDescending(q => q.Title);
                    break;

                case NotificationOrder.Content:
                    query = query.OrderByDescending(q => q.Content);
                    break;

                case NotificationOrder.Organization:
                    query = query.OrderByDescending(q => q.OrganizationId);
                    break;

                case NotificationOrder.NotificationStatus:
                    query = query.OrderByDescending(q => q.NotificationStatusId);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }
Exemple #29
0
        private IQueryable <NotificationDAO> OrFilter(IQueryable <NotificationDAO> query, NotificationFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <NotificationDAO> initQuery = query.Where(q => false);

            foreach (NotificationFilter NotificationFilter in filter.OrFilter)
            {
                IQueryable <NotificationDAO> queryable = query;
                if (NotificationFilter.Id != null)
                {
                    queryable = queryable.Where(q => q.Id, NotificationFilter.Id);
                }
                if (NotificationFilter.Title != null)
                {
                    queryable = queryable.Where(q => q.Title, NotificationFilter.Title);
                }
                if (NotificationFilter.Content != null)
                {
                    queryable = queryable.Where(q => q.Content, NotificationFilter.Content);
                }
                if (NotificationFilter.OrganizationId != null)
                {
                    query = query.Where(q => q.OrganizationId, NotificationFilter.OrganizationId);
                }
                if (NotificationFilter.NotificationStatusId != null)
                {
                    query = query.Where(q => q.NotificationStatusId, NotificationFilter.NotificationStatusId);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
Exemple #30
0
 private IQueryable <NotificationDAO> DynamicFilter(IQueryable <NotificationDAO> query, NotificationFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => false));
     }
     if (filter.Id != null)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.Title != null)
     {
         query = query.Where(q => q.Title, filter.Title);
     }
     if (filter.Content != null)
     {
         query = query.Where(q => q.Content, filter.Content);
     }
     if (filter.OrganizationId != null)
     {
         query = query.Where(q => q.OrganizationId, filter.OrganizationId);
     }
     if (filter.NotificationStatusId != null)
     {
         query = query.Where(q => q.NotificationStatusId, filter.NotificationStatusId);
     }
     query = OrFilter(query, filter);
     return(query);
 }