public async Task SaveToPush(IDictionary <Subscriptions, List <Message> > events, string orderLink)
        {
            var sql = @"
                insert into ""OutboxNotifications""
                (""IdempotencyKey"", ""Data"", ""Transport"", ""Status"")
                values(@key, @data, @subscriptions, @status)
                on conflict(""IdempotencyKey"") do nothing";

            using (IDbConnection connection = _connectionFactory.BuildConnection())
            {
                foreach (KeyValuePair <Subscriptions, List <Message> > @event in events)
                {
                    foreach (Message message in @event.Value)
                    {
                        await connection.ExecuteAsync(
                            sql,
                            new
                        {
                            key  = $"{@event.Key}_{orderLink}_{message.To}".ToLower(),
                            data = JsonConvert.SerializeObject(message, new JsonSerializerSettings {
                                TypeNameHandling = TypeNameHandling.All
                            }),
                            subscriptions = @event.Key.ToString(),
                            status        = OutboxNotificationsStatusEntity.New.ToString()
                        });
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task MergePulledOrdersAsync(IEnumerable <Order> orders, int freelanceBurseId)
        {
            if (!orders.Any())
            {
                return;
            }

            using (IDbConnection connection = _connectionFactory.BuildConnection())
            {
                var query = @"
                    insert into ""Orders""
                    (""Title"", ""Description"", ""Link"", ""Publication"", ""FreelanceBurseId"", ""Status"")
                    values(@title, @description, @link, @publication, @freelanceBurseId, @status)
                    on conflict (""Link"") do nothing";

                await connection.ExecuteAsync(
                    query,
                    orders.Select(
                        p => new
                {
                    title       = p.Body.Title,
                    description = p.Body.Description,
                    link        = p.Body.Link.ToString(),
                    publication = p.Body.Publication,
                    freelanceBurseId,
                    status = ProcessingStatus.New.ToString()
                }));
            }
        }
Exemplo n.º 3
0
        public async Task <User[]> GetForNotifications(Order order)
        {
            using (IDbConnection connection = _connectionFactory.BuildConnection())
            {
                string query = @$ "
                select distinct u." "TelegramId" ", u." "Active" ", u." "Email" ", u." "Subscriptions" "
                from " "Users" " u
                    join " "UsersToKeywords" " UTK on u." "Id" " = UTK." "UserId" "
                    join " "Keywords" " k on UTK." "KeywordId" " = k." "Id" "
                where
                    u." "Active" " = true
                    and (u." "TelegramId" " is not null or u." "Email" " is not null)";

                IEnumerable <UserEntity> result = await connection.QueryAsync <UserEntity>(
                    query,
                    new
                {
                    title       = order.Body.Title,
                    description = order.Body.Description
                });

                return(result.Select(
                           p =>
                {
                    var contact = new Contact(p.TelegramId, p.Email);

                    return new User(p.Active, contact, p.Subscriptions);
                })
                       .ToArray());
            }
        }
Exemplo n.º 4
0
        public async Task <FreelanceBurse[]> GetAll()
        {
            using (IDbConnection connection = _connectionFactory.BuildConnection())
            {
                var query = @"
                    select ""Id"", ""Name"", ""Link""
                    from ""FreelanceBurses""";

                IEnumerable <FreelanceBurseEntity> result = await connection.QueryAsync <FreelanceBurseEntity>(query);

                return(result.Select(p => new FreelanceBurse(p.Id, new Uri(p.Link), p.Name)).ToArray());
            }
        }