Esempio n. 1
0
        public async Task Insert(NotifyAdd notifyAdd)
        {
            try
            {
                var notification = new Notification()
                {
                    Id               = Guid.NewGuid().ToString(),
                    User             = notifyAdd.UserName,
                    DateTime         = notifyAdd.DateTime,
                    NotificationType = notifyAdd.NotificationType,
                    Hyperlink        = notifyAdd.Hyperlink,
                    Message          = notifyAdd.Message,
                    ProfileId        = notifyAdd.ProfileId,
                    Parameters       = JsonConvert.SerializeObject(notifyAdd.Parameters),
                    RawMessage       = JsonConvert.SerializeObject(notifyAdd),
                    Read             = false,
                    Status           = 1
                };

                await _context.Notifications.AddAsync(notification);

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw new ApplicationException(e.Message);
            }
        }
Esempio n. 2
0
 public async Task AddNotification(string body, EmailConf emailGeneral, string subject, string attachment = null)
 {
     try
     {
         var notification = new NotificationQueue
         {
             Subject          = subject,
             Body             = body,
             Attachment       = attachment,
             To               = emailGeneral.Email,
             ToName           = emailGeneral.FullName,
             From             = _settings.Value.From,
             FromName         = _settings.Value.FromName,
             ReplyTo          = _settings.Value.ReplyTo,
             ReplyToName      = _settings.Value.ReplyToName,
             Priority         = emailGeneral.Priority,
             CreatedTimestamp = DateTime.Now,
             FailCount        = 0
         };
         _notificationDbContext.NotificationQueues.Add(notification);
         await _notificationDbContext.SaveChangesAsync();
     }
     catch (Exception e)
     {
         _logger.LogError(e.Message);
     }
 }
        public async Task AddNotificationAsync(Guid buildId, string channelId, WatchLevel watchLevel)
        {
            var notification = new NotificationDetails(buildId, channelId, watchLevel);

            logger.LogInformation($"Adding notification: '{notification}'");

            notificationDb.Add(notification);
            await notificationDb.SaveChangesAsync();
        }
Esempio n. 4
0
 public async Task Do_MarkAsRead(
     IEnumerable <Notification> notifications)
 {
     foreach (var item in notifications)
     {
         item.Unread = false;
         Edit_Notification(item);
     }
     await _notificationCtx.SaveChangesAsync();
 }
Esempio n. 5
0
        public async Task <EmailLog> Insert(string email, string recipientName, string message, int statusCode, int appId, string subject = null, int?customerId = null, string exceptionMessage = null)
        {
            var mailLog = new EmailLog
            {
                Email            = email,
                RecipientName    = recipientName,
                Message          = message,
                Subject          = subject,
                StatusCode       = statusCode,
                CustomerId       = customerId,
                AppId            = appId,
                ExceptionMessage = exceptionMessage
            };

            _context.EmailLog.Add(mailLog);
            await _context.SaveChangesAsync();

            return(await Task.FromResult(mailLog));
        }
Esempio n. 6
0
        /// <summary>
        /// Send message.
        /// </summary>
        /// <param name="message">All fields of message should be correct to ensure ef updates the correct data.</param>
        /// <returns></returns>
        public virtual async Task <BaseResponse> Send(TMessage message)
        {
            var rsp = await Sender.Send(message);

            if (Db.Entry(message).State == EntityState.Detached)
            {
                Db.Attach(message);
            }
            message.TryTimes++;
            if (rsp.Code != 0)
            {
                message.Status = MessageStatus.Failed;
            }
            else
            {
                message.Status = MessageStatus.Succeed;
                message.SendDt = DateTime.Now;
            }
            await Db.SaveChangesAsync();

            return(rsp);
        }
Esempio n. 7
0
        public async Task <bool> RegisterUser(UserDetails userDetails)
        {
            try
            {
                _notificationDBContext.UserDetails.Add(userDetails);
                var userId = await _notificationDBContext.SaveChangesAsync();

                if (userId > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                // To Do Log
                throw;
            }
        }
Esempio n. 8
0
 private async Task Send(string userId, PushMessage notification)
 {
     foreach (var subscription in await GetUserSubscriptions(userId))
     {
         try
         {
             await client.RequestPushMessageDeliveryAsync(
                 subscription.ToWebPushSubscription(),
                 notification,
                 new VapidAuthentication(vapidPublicKey, vapidPrivateKey));
         }
         catch (Exception e) when(e.Message == "Subscription no longer valid")
         {
             context.AppPushSubscriptions.Remove(subscription);
             await context.SaveChangesAsync();
         }
     }
Esempio n. 9
0
        public async Task <SmsLog> Insert(string mobileNumber, string message, int statusCode, int appId, string exceptionMessage = null, string responseJson = null)
        {
            var smsLog = new SmsLog
            {
                MobileNumber     = mobileNumber,
                Message          = message,
                StatusCode       = statusCode,
                AppId            = appId,
                ExceptionMessage = exceptionMessage,
                ResponseJson     = responseJson
            };

            _context.SmsLog.Add(smsLog);
            await _context.SaveChangesAsync();

            return(await Task.FromResult(smsLog));
        }
Esempio n. 10
0
        public async Task Handle(UserCreatedEvent @event)
        {
            var customer = await _customerRepository.Add(new Customer
            {
                Id        = @event.Id,
                Email     = @event.Email,
                FirstName = @event.FirstName,
                LastName  = @event.LastName
            });

            var user = await _userRepository.Add(new User
            {
                Id        = @event.Id,
                FirstName = @event.FirstName,
                LastName  = @event.LastName,
                Email     = @event.Email
            });

            await _dbContext.SaveChangesAsync();
        }
        public async Task Handle(UserUpdatedEvent @event)
        {
            var updatedUser = _userRepository.Update(new User
            {
                Id        = @event.Id,
                Email     = @event.Email,
                FirstName = @event.FirstName,
                LastName  = @event.LastName
            });

            var updatedCustomer = _customerRepository.Update(new Customer
            {
                Id        = @event.Id,
                FirstName = @event.FirstName,
                LastName  = @event.LastName,
                Email     = @event.Email
            });

            await updatedUser;
            await updatedCustomer;
            await _dbContext.SaveChangesAsync();
        }
 public async Task SaveChangesAsync() => await dbContext.SaveChangesAsync();