private void SetNotification(NotificationTypeEnum notificationTypeEnum)
        {
            _notification = _notificationFactory.Get(notificationTypeEnum);
            _notification.Configuration = new NotificationConfiguration()
            {
                Icon = AppModel.Instance.NotifyIcon,
                DefaultSound = Resources.NotificationSound
            };
            try
            {
                _notification.Configuration.CustomSound = AppModel.Instance.CustomNotificationSound;
            }
            catch (CachedSoundFileNotExistsException)
            {
                if (!_notification.NeedCustomSound())
                {
                    return;
                }

                MessageBox.Show(string.Format(Properties.Notifications.AudioFileNotFound, Application.ProductName,
                        Properties.Notifications.NotifSound),Properties.Notifications.AudioFileNotFoundTitle,
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                _model.NotificationSettings = NotificationTypeEnum.SoundNotification;
            }
        }
 /// <summary>
 ///     Create a notification object linked to the enum value
 /// </summary>
 /// <param name="eEnum"></param>
 /// <param name="icon"></param>
 /// <param name="sound"></param>
 /// <returns></returns>
 public static INotification CreateNotification(NotificationTypeEnum eEnum, NotifyIcon icon, CachedSound sound)
 {
     switch (eEnum)
     {
         case NotificationTypeEnum.DefaultWindowsNotification:
             return new NotificationWindows(icon);
         case NotificationTypeEnum.SoundNotification:
             return new NotificationSound();
         case NotificationTypeEnum.NoNotification:
             return new NotificationNone();
         default:
             throw new ArgumentOutOfRangeException(nameof(eEnum), eEnum, null);
     }
 }
 public MobileNotificationFactory Initialize(string title, string description, NotificationTypeEnum type)
 {
     try
     {
         titleOfMessage = title;
         descriptionOfMessage = description;
         notifyType = type;
         notificationsInternal = new List<NotificationMobileJson>();
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return this;
 }
Example #4
0
        private void notificationComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            if (!_loaded)
            {
                return;
            }
            var value = ((ComboBox)sender).SelectedValue;

            if (value == null)
            {
                return;
            }

            NotificationTypeEnum notificationType = (NotificationTypeEnum)value;

            if (notificationType == AppModel.Instance.NotificationSettings)
            {
                return;
            }

            NotificationCustomSoundEnum supportCustomSound = new NotificationFactory().Get(notificationType).SupportCustomSound();

            selectSoundButton.Visible = supportCustomSound != NotificationCustomSoundEnum.NotSupported;

            if (supportCustomSound == NotificationCustomSoundEnum.Required)
            {
                try
                {
                    var sound = AppModel.Instance.CustomNotificationSound;
                    deleteSoundButton.Visible = true;
                }
                catch (CachedSoundFileNotExistsException)
                {
                    selectSoundFileDialog.ShowDialog(this);
                }
            }

            AppModel.Instance.NotificationSettings = notificationType;
        }
Example #5
0
        private bool AddQuizzCommentNotification(NotificationTypeEnum type, int quizzCommentId, bool callSaveChanges = true)
        {
            try
            {
                var quizzComment = _uow.QuizzComments.GetById(quizzCommentId);

                if (quizzComment.AuthorId == _currentUser.Id)
                {
                    return(true);
                }

                var entity = _uow.NewNotifications.GetAll()
                             .Where(n => n.NotificationType == type &&
                                    n.QuizzCommentId == quizzCommentId &&
                                    n.ToUserId == n.QuizzComment.AuthorId)
                             .FirstOrDefault();

                if (entity == null)
                {
                    CreateNewQuizzCommentNotification(type, quizzComment);
                }
                else
                {
                    UpdateQuizzCommentNotification(entity);
                }

                if (callSaveChanges)
                {
                    _uow.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(false);
            }
        }
        private static Color GetMessageTextColorFor(NotificationTypeEnum notificationType)
        {
            switch (notificationType)
            {
            case NotificationTypeEnum.Info:
                return(Color.FromHex("#00529B"));

            case NotificationTypeEnum.Success:
                return(Color.FromHex("#4F8A10"));

            case NotificationTypeEnum.Warning:
                return(Color.FromHex("£9F6000"));

            case NotificationTypeEnum.Error:
                return(Color.FromHex("#D8000C"));

            case NotificationTypeEnum.Network:
                return(Color.White);

            default:
                return(Color.Pink);
            }
        }
        private static Color GetBackgroundColorFor(NotificationTypeEnum notificationType)
        {
            switch (notificationType)
            {
            case NotificationTypeEnum.Info:
                return(Color.FromHex("#BDE5F8"));

            case NotificationTypeEnum.Success:
                return(Color.FromHex("#DFF2BF"));

            case NotificationTypeEnum.Warning:
                return(Color.FromHex("#FEEFB3"));

            case NotificationTypeEnum.Error:
                return(Color.FromHex("#FFD2D2"));

            case NotificationTypeEnum.Network:
                return(Color.Black);

            default:
                return(Color.LightPink);
            }
        }
    public void ShowNotification(NotificationTypeEnum NotificationType, string text)
    {
        NotificationText.text = text;
        switch (NotificationType)
        {
        case NotificationTypeEnum.Score:
            NotificationIcon.text  = "+";
            NotificationIcon.color = Color.green;
            break;

        case NotificationTypeEnum.Foul:
            NotificationIcon.text  = "-";
            NotificationIcon.color = Color.red;
            break;

        case NotificationTypeEnum.Info:
            NotificationIcon.text  = "i";
            NotificationIcon.color = Color.yellow;
            break;
        }
        NotificationUI.SetBool("Show", true);
        StartCoroutine(NotificationUIBoolFalsing());
    }
        private bool AddDepQuizzmateNotification(NotificationTypeEnum type, User dependent, FriendRequest friendRequest)
        {
            if (dependent.UserType == UserTypeEnum.Standard)
            {
                return(true);
            }

            foreach (var depEntity in dependent.AsChildDependsOn)
            {
                if (depEntity.UserId == friendRequest.RequestFromId)
                {
                    continue;
                }
                if (NotificationTypeUtil.WillNotify(depEntity, type) == false)
                {
                    continue;
                }

                CreateNewQuizzmateNotification(type, friendRequest.Id, dependent.Id, depEntity.UserId);
            }

            return(true);
        }
        private string GetUiNotificationMessage(NotificationTypeEnum notificationType)
        {
            var message = string.Empty;

            switch (notificationType)
            {
            case NotificationTypeEnum.ActivityLikeAdded:
            case NotificationTypeEnum.CommentAdded:
            case NotificationTypeEnum.CommentEdited:
            case NotificationTypeEnum.CommentReplied:
            case NotificationTypeEnum.EventUpdated:
            case NotificationTypeEnum.EventHided:
                message = $"<strong>{TokensConstants.FullName} {_localizationService.Translate(notificationType.ToString())}</strong>"
                          + $"<p>{TokensConstants.ActivityTitle}</p>";
                break;

            case NotificationTypeEnum.BeforeStart:
                message = $"<strong>{_localizationService.Translate(notificationType.ToString())}</strong>"
                          + $"<p>{TokensConstants.ActivityTitle}</p>";
                break;
            }

            return(message);
        }
        private bool AddDepQuizzmateNotification(NotificationTypeEnum type, FriendRequest friendRequest, int dependentId, bool callSaveChanges = true)
        {
            try
            {
                User dependent = _uow.Users.GetAll()
                                 .Where(u => u.Id == dependentId)
                                 .Include(u => u.DependentPermission)
                                 .Include(u => u.AsChildDependsOn.Select(d => d.User))
                                 .FirstOrDefault();

                AddDepQuizzmateNotification(type, dependent, friendRequest);

                if (callSaveChanges)
                {
                    _uow.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(false);
            }
        }
Example #12
0
        private void SetNotification(NotificationTypeEnum notificationTypeEnum)
        {
            _notification = _notificationFactory.Get(notificationTypeEnum);
            _notification.Configuration = new NotificationConfiguration()
            {
                Icon         = _model.TrayIcon.NotifyIcon,
                DefaultSound = Resources.NotificationSound
            };
            try
            {
                _notification.Configuration.CustomSound = AppModel.Instance.CustomNotificationSound;
            }
            catch (CachedSoundFileNotExistsException)
            {
                if (!_notification.NeedCustomSound())
                {
                    return;
                }

                MessageBox.Show(string.Format(SettingsStrings.audioFileNotFound, SettingsStrings.notificationOptionSound),
                                SettingsStrings.audioFileNotFoundCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                _model.NotificationSettings = NotificationTypeEnum.SoundNotification;
            }
        }
 public NotificationDisplayer(NotificationTypeEnum notificationTypeEnum, string label)
 {
     Type  = notificationTypeEnum;
     Label = label;
 }
        private PushNotificationResponse SendPushNotification(NotificationTypeEnum notificationType, PushNotificationSubscriber subscriber, string message, int intervalValue)
        {
            // Create HTTP Web Request object.
                string subscriptionUri = subscriber.ServiceToken;
                HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);

                // MPNS expects a byte array, so convert message accordingly.
                byte[] notificationMessage = Encoding.Default.GetBytes(message);

                // Set the notification request properties.
                sendNotificationRequest.Method = WebRequestMethods.Http.Post;
                sendNotificationRequest.ContentLength = notificationMessage.Length;
                sendNotificationRequest.ContentType = "text/xml";
                sendNotificationRequest.Headers.Add("X-MessageID", Guid.NewGuid().ToString());

                switch (notificationType)
                {
                    case NotificationTypeEnum.Tile:
                        sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");
                        break;
                    case NotificationTypeEnum.Toast:
                        sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
                        break;
                    case NotificationTypeEnum.Raw:
                        // A value for the X-WindowsPhone-Target header is not specified for raw notifications.
                        break;
                }

                sendNotificationRequest.Headers.Add("X-NotificationClass", intervalValue.ToString());

                // Merge byte array payload with headers.
                using (Stream requestStream = sendNotificationRequest.GetRequestStream())
                {
                    requestStream.Write(notificationMessage, 0, notificationMessage.Length);
                }

                string statCode = string.Empty;
                PushNotificationResponse notificationResponse;

                try
                {
                    // Send the notification and get the response.
                    HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
                    statCode = Enum.GetName(typeof(HttpStatusCode), response.StatusCode);

                    // Create PushNotificationResponse object.
                    notificationResponse = new PushNotificationResponse((int)intervalValue, subscriber.ServiceToken);
                    notificationResponse.StatusCode = statCode;
                    foreach (string header in WP7Constants.WP_RESPONSE_HEADERS)
                    {
                        notificationResponse.Properties[header] = response.Headers[header];
                    }
                }
                catch (Exception ex)
                {
                    statCode = ex.Message;
                    notificationResponse = new PushNotificationResponse((int)intervalValue, subscriber.ServiceToken);
                    notificationResponse.StatusCode = statCode;
                }

                return notificationResponse;
        }
 public static string GetName(this NotificationTypeEnum notificationTypeEnum)
 {
     return(Enum.GetName(typeof(NotificationTypeEnum), notificationTypeEnum));
 }
Example #16
0
 public NotificationSettingsUpdatedEvent(NotificationTypeEnum prevSettings, NotificationTypeEnum newSettings)
 {
     PrevSettings = prevSettings;
     NewSettings  = newSettings;
 }
        private async Task NotifyAd(Shared.Functional.AdModel ad, string eventType, EmailTemplateEnum emailTemplate, NotificationTypeEnum notificationType, string callbackUrl)
        {
            _logger.LogInformation($"notify user {ad.OwnerId} for ad {ad.Id}");

            await _eventTrackingService.Create(ad.OwnerId, "Ad", eventType);

            var notification = new Notification
            {
                Id                = Guid.NewGuid(),
                CreatedDate       = DateTime.Now,
                CssClass          = "advalidate",
                ImageUrl          = "alert-advalidate",
                MessageTitle      = eventType,
                NotificationIcon  = "alert-advalidate",
                NotificationType  = notificationType.GetName(),
                NotificationUrl   = callbackUrl,
                UserId            = ad.OwnerId,
                DisplayMax        = 1,
                IsDisplayOnlyOnce = true
            };

            await _notificationService.Create(notification);

            await SendEmailTemplate(ad, emailTemplate, callbackUrl);
        }
Example #18
0
        public static async void CreateNotification(Guid Receipient, string header, string content, NotificationTypeEnum type, Guid id)
        {
            using (var context = new Context())
            {
                await context.Notification.AddAsync(new Notification()
                {
                    Id          = Guid.NewGuid(),
                    RecipientId = Receipient,
                    SenderId    = SignInManager.CurrentUser.Id,
                    IsReceived  = false,
                    Header      = header,
                    Content     = content,
                    Type        = type,
                    ObjectId    = id
                });

                await context.SaveChangesAsync();
            }
        }
 public async Task <Notification> Create(string userId, string title, string notificationUrl, string cssClass, string imageUrl, string notificationIcon, NotificationTypeEnum notificationType)
 {
     return(await Create(new Notification
     {
         UserId = userId,
         CssClass = cssClass,
         DisplayMax = 1,
         ImageUrl = imageUrl,
         IsDisplayOnlyOnce = true,
         MessageTitle = title,
         NotificationUrl = notificationUrl,
         NotificationIcon = notificationIcon,
         NotificationType = notificationType.GetName()
     }));
 }
Example #20
0
 public NotificationSettingsUpdatedEvent(NotificationTypeEnum prevSettings, NotificationTypeEnum newSettings)
 {
     PrevSettings = prevSettings;
     NewSettings = newSettings;
 }
Example #21
0
        private void NotifyChangedYouStatusInRoom(int senderUserId, int reciverUserId, NotificationTypeEnum type, int aliasId)
        {
            List <int> userIds = new List <int>();

            userIds.Add(reciverUserId);

            SaveNotification(senderUserId, userIds, (int)type, aliasId, null);
        }
Example #22
0
        public async Task <ServiceResult <object> > Notify(int userId, string message, NotificationTypeEnum notificationType)
        {
            var user = Context.Users.FirstOrDefault(u => u.Id == userId);

            if (user == null)
            {
                return(NotFound("用户不存在"));
            }
            if (ConnectionService.IsOnline(userId))
            {
                await HubContext.Clients.Client(ConnectionService.GetConnectionId(userId)).SendAsync("OnNotify", (int)notificationType, message);

                return(Success("在线通知成功"));
            }
            else
            {
                var notification = new Notification
                {
                    Content          = message,
                    UserId           = userId,
                    NotificationType = notificationType
                };
                Context.Notifications.Add(notification);
                await Context.SaveChangesAsync();

                return(Success("离线通知保存成功"));
            }
        }
Example #23
0
        public async Task <ServiceResult <object> > NotifyGroupMembers(int groupId, string message, NotificationTypeEnum notificationType)
        {
            var group = Context.ChatGroups.FirstOrDefault(g => g.Id == groupId);

            if (group == null)
            {
                return(NotFound("群聊不存在"));
            }
            var groupMemberIds = Context.GroupMemberships.Where(m => m.ChatGroupId == groupId).Select(m => m.UserId).ToList();

            if (notificationType == NotificationTypeEnum.ChatMessage)
            {
                foreach (var userId in groupMemberIds)
                {
                    if (!ConnectionService.IsOnline(userId))
                    {
                        var notification = new Notification
                        {
                            Content          = message,
                            UserId           = userId,
                            NotificationType = notificationType
                        };
                        Context.Notifications.Add(notification);
                    }
                }
            }
            await Context.SaveChangesAsync();

            await HubContext.Clients.Group(groupId.ToString()).SendAsync("OnNotify", (int)notificationType, message);

            return(Success("群聊通知发送成功"));
        }
Example #24
0
 public Notification(NotificationTypeEnum notificationType, string message)
 {
     this.NotificationType = notificationType;
     this.Message          = message;
 }
Example #25
0
 public Notification(NotificationTypeEnum notificationType, string message, Exception ex)
     : this(notificationType, message)
 {
     this.ExceptionObj = ex;
 }
Example #26
0
        public async Task SendMailByTypeAndDayAsync(MailBase mail, string email, DateTime date, NotificationTypeEnum mailTemplateTypeEnum)
        {
            var query = new EmailLogQuery
            {
                StartCreateDate = new DateTime(date.Year, date.Month, date.Day),
                TypeId          = GetEmailTemplateId(mailTemplateTypeEnum),
                ToEmail         = email
            };

            _sentMailsService.GetAllByFilter(query, out var totalCount);
            if (totalCount == 0)
            {
                await SendAsync(mail);
            }
        }
 public async Task <IList <Notification> > GetNotifications(string userId, NotificationTypeEnum notificationType) =>
 await _UnitOfWork.NotificationRepository.GetNotifications(userId, notificationType.GetName());
 public async Task <IList <Notification> > GetNotifications(string ownerId, NotificationTypeEnum notificationType, DateTime createdDate, string callbackUrl) =>
 await _UnitOfWork.NotificationRepository.Where(a => a.UserId == ownerId && a.NotificationType == NotificationTypeEnum.AdStartPublished.GetName() && a.CreatedDate > createdDate &&
                                                a.NotificationUrl == callbackUrl);
Example #29
0
        public int Build(MessageTemplaceEnum messageTemplace, MessageTypeEnum messageType, NotificationTypeEnum notificationType, List <int> userIdList)
        {
            var template = db.MessageTemplateQuery.FirstOrDefault(x => x.Code == messageTemplace.ToString());

            if (template == null)
            {
                Lib.Log.WriteExceptionLog($"NotificationManager.Build:找不到消息模版{messageTemplace.ToString()}");
                return(default);
Example #30
0
 public async Task <GroupInvitationDataModel> GetGroupInvitationDataModelAsync(NotificationTypeEnum notificationType, Guid groupId, Guid notifierId,
                                                                               Guid receiverId)
 {
     return(new GroupInvitationDataModel
     {
         Url = $"/groups/room?groupId={groupId}".ToLinkModel(),
         Title = (await _groupService.GetAsync(groupId))?.Title,
         NotificationType = notificationType,
         GroupId = groupId,
         NotifierId = notifierId,
         ReceiverId = receiverId
     });
 }
Example #31
0
        private PushNotificationResponse SendPushNotification(NotificationTypeEnum notificationType, PushNotificationSubscriber subscriber, string message, int intervalValue)
        {
            // Create HTTP Web Request object.
            string         subscriptionUri         = subscriber.ServiceToken;
            HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);

            // MPNS expects a byte array, so convert message accordingly.
            byte[] notificationMessage = Encoding.Default.GetBytes(message);

            // Set the notification request properties.
            sendNotificationRequest.Method        = WebRequestMethods.Http.Post;
            sendNotificationRequest.ContentLength = notificationMessage.Length;
            sendNotificationRequest.ContentType   = "text/xml";
            sendNotificationRequest.Headers.Add("X-MessageID", Guid.NewGuid().ToString());

            switch (notificationType)
            {
            case NotificationTypeEnum.Tile:
                sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");
                break;

            case NotificationTypeEnum.Toast:
                sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
                break;

            case NotificationTypeEnum.Raw:
                // A value for the X-WindowsPhone-Target header is not specified for raw notifications.
                break;
            }

            sendNotificationRequest.Headers.Add("X-NotificationClass", intervalValue.ToString());

            // Merge byte array payload with headers.
            using (Stream requestStream = sendNotificationRequest.GetRequestStream())
            {
                requestStream.Write(notificationMessage, 0, notificationMessage.Length);
            }

            string statCode = string.Empty;
            PushNotificationResponse notificationResponse;

            try
            {
                // Send the notification and get the response.
                HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
                statCode = Enum.GetName(typeof(HttpStatusCode), response.StatusCode);

                // Create PushNotificationResponse object.
                notificationResponse            = new PushNotificationResponse((int)intervalValue, subscriber.ServiceToken);
                notificationResponse.StatusCode = statCode;
                foreach (string header in WP7Constants.WP_RESPONSE_HEADERS)
                {
                    notificationResponse.Properties[header] = response.Headers[header];
                }
            }
            catch (Exception ex)
            {
                statCode                        = ex.Message;
                notificationResponse            = new PushNotificationResponse((int)intervalValue, subscriber.ServiceToken);
                notificationResponse.StatusCode = statCode;
            }

            return(notificationResponse);
        }
 public void Show(string message, string title, NotificationTypeEnum notificationType)
 {
     Show(message, title, notificationType, 3000);
 }
        private bool AddQuizzNotification(NotificationTypeEnum type, int quizzId, bool callSaveChanges = true)
        {
            try
            {
                var dependent = _uow.Quizzes.GetAll()
                                .Where(q => q.Id == quizzId)
                                .Select(q => q.Owner)
                                .Include(u => u.DependentPermission)
                                .Include(u => u.AsChildDependsOn.Select(d => d.User))
                                .FirstOrDefault();

                if (dependent.UserType == UserTypeEnum.Standard)
                {
                    return(true);
                }

                var quizz = _uow.Quizzes.GetById(quizzId);

                if (quizz == null)
                {
                    return(false);
                }

                foreach (var depEntity in dependent.AsChildDependsOn)
                {
                    if (isParentCurrentUser(depEntity))
                    {
                        continue;
                    }

                    if (type == NotificationTypeEnum.DepQuizzReceiveComment && isCurrentUserQuizzOwner(quizz))
                    {
                        continue;
                    }

                    if (NotificationTypeUtil.WillNotify(depEntity, type) == false)
                    {
                        continue;
                    }

                    var entity = _uow.NewNotifications.GetAll()
                                 .Where(n => n.NotificationType == type &&
                                        n.QuizzId == quizzId &&
                                        n.ToUserId == depEntity.User.Id)
                                 .FirstOrDefault();

                    if (entity == null)
                    {
                        CreateNewQuizzNotification(type, quizzId, depEntity.UserId);
                    }
                    else
                    {
                        UpdateQuizzNotification(entity);
                    }
                }

                if (callSaveChanges)
                {
                    _uow.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(false);
            }
        }
Example #34
0
        protected static void SendNotification(Guid processId, List<Guid> identityId, string subject, string message, string wfinfo, NotificationTypeEnum type)
        {
            Email mailer = new Email();

            if (identityId == null)
                identityId = new List<Guid>();

            if (type == NotificationTypeEnum.NotificationWorkflowMyDocBack || type == NotificationTypeEnum.NotificationWorkflowMyDocChangeState)
            {
                var budgetItem = DynamicRepository.GetByView("BudgetItem_Edit", FilterCriteriaSet.And.Equal(processId, "Id")).FirstOrDefault();
                if (budgetItem != null)
                    identityId.Add(budgetItem.CreatorEmployeeId_SecurityUserId);
            }

            if (identityId.Count == 0)
                return;

            var userFilter = FilterCriteriaSet.And.In(identityId, "Id");

            if(type == NotificationTypeEnum.DocumentAddToInbox)
            {
                userFilter = userFilter.Merge(FilterCriteriaSet.And.Equal(true, "NotificationWorkflowInbox"));
            }
            else if(type == NotificationTypeEnum.NotificationWorkflowMyDocBack)
            {
                userFilter = userFilter.Merge(FilterCriteriaSet.And.Equal(true, "NotificationWorkflowMyDocBack"));
            }
            else if(type == NotificationTypeEnum.NotificationWorkflowMyDocChangeState)
            {
                userFilter = userFilter.Merge(FilterCriteriaSet.And.Equal(true, "NotificationWorkflowMyDocChangeState"));
            }

            var suList = DynamicRepository.GetByEntity("SecurityUser", userFilter);

            if (suList.Count == 0)
                return;

            var param = new Dictionary<string, string>();

            param.Add("Subject", subject);
            param.Add("Message", message);
            param.Add("WFInfo", wfinfo);

            AddObjectParams(param, processId,
                type == NotificationTypeEnum.NotificationWorkflowMyDocBack);

            var emailList = suList.Select(c => (string)c.Email).ToList();
            mailer.SendEmail("NotificationEmail", param, emailList);
        }
 /// <summary>
 /// Create an instance of model validator.
 /// </summary>
 /// <param name="notificationType">The notification type.</param>
 /// <param name="notificationContent">The notification content.</param>
 /// <returns>Instance of <see cref="IModelValidator"/>.</returns>
 public IModelValidator ExecuteCreation(NotificationTypeEnum notificationType, NotificationContentRequestModel notificationContent)
 => _factories[notificationType].Create(notificationContent);
 public NotificationDisplayer(NotificationTypeEnum notificationTypeEnum, string label)
 {
     Type = notificationTypeEnum;
     Label = label;
 }
Example #37
0
        /// <summary>
        /// Handle the creation of a reward
        /// </summary>
        /// <param name="category">Which type of reward will be</param>
        /// <param name="targetUser">user who will receive the reward</param>
        /// <param name="isPlus">Sum or rest points this reward</param>
        /// <param name="entity1">Info to store in the history</param>
        /// <param name="entity2">Other info to store in the history</param>
        /// <param name="notificationType">How will be the user notified</param>
        /// <param name="devices">Firebase notification targets</param>
        /// <returns>void - notify client that a reward was created via websocket</returns>
        public async Task <RewardResponse> HandleRewardAsync(RewardCategoryEnum category, int targetUser, bool isPlus, object entity1, object entity2,
                                                             NotificationTypeEnum notificationType = NotificationTypeEnum.SIGNAL_R, IEnumerable <Device> devices = null)
        {
            var userStatics = await _userStatisticsService.GetOrCreateUserStatisticsByUserAsync(targetUser);

            var currentPoints = userStatics.Points;
            var cutPoints     = await _cutPointService.GetNextCutPointsAsync(currentPoints, 5);

            var data = new RewardHistoryData
            {
                // Make sure that this is an important info to store in the history
                Entity1 = JsonConvert.SerializeObject(entity1),
                Entity2 = JsonConvert.SerializeObject(entity2)
            };
            var reward = new CreateRewardRequest
            {
                UserId             = targetUser,
                RewardCategoryEnum = (int)category,
                IsPlus             = isPlus,
                Data = JsonConvert.SerializeObject(data),
            };

            var dbReward = await _rewardService.CreateRewardAsync(reward);

            RewardResponse mapped = null;

            // assign only if the reward was created after validations
            if (dbReward != null)
            {
                mapped = new RewardResponse
                {
                    Id               = dbReward.Id,
                    CategoryId       = (int)dbReward.RewardCategory.Category,
                    Category         = dbReward.RewardCategory.Category.ToString(),
                    IsPlus           = dbReward.IsPlus,
                    Points           = dbReward.Points,
                    RewardPoints     = dbReward.RewardPoints,
                    RewardCategoryId = dbReward.RewardCategoryId,
                    UserId           = dbReward.UserId,
                    CreatedAt        = dbReward.CreatedAt
                };

                switch (notificationType)
                {
                case NotificationTypeEnum.SIGNAL_R:
                    await SendSignalRNotificationAsync(HubConstants.REWARD_CREATED, mapped);

                    break;

                case NotificationTypeEnum.FIREBASE:
                    var lang = await _userService.GetUserLanguageFromUserIdAsync(mapped.UserId);

                    var title = (lang == "EN") ? "You have receipt a new reward" : "Has recibido una nueva recompensa";
                    var body  = "";
                    if (category == RewardCategoryEnum.EAT_BALANCED_CREATED_STREAK || category == RewardCategoryEnum.EAT_CREATED_STREAK)
                    {
                        body = GetFirebaseMessageForStreakReward(category, (int)entity1, mapped, lang);
                    }

                    if (category == RewardCategoryEnum.DISH_BUILT)
                    {
                        body = GetFirebaseMessageForDishBuildReward(mapped, lang);
                    }

                    if (category == RewardCategoryEnum.NEW_REFERAL)
                    {
                        body = GetFirebaseMessageForNewReferralReward(mapped, lang);
                    }

                    if (category == RewardCategoryEnum.EAT_BALANCED_CREATED || category == RewardCategoryEnum.EAT_CREATED)
                    {
                        body = GetFirebaseMessageForCreateEatReward(mapped, lang, category);
                    }

                    if (category == RewardCategoryEnum.CUT_POINT_REACHED)
                    {
                        body = GetFirebaseMessageForCutPointReachedReward(mapped, lang);
                    }

                    if (devices != null)
                    {
                        await _notificationService.SendFirebaseNotificationAsync(title, body, devices);
                    }
                    break;

                default:
                    break;
                }

                await HandleCutPointRewardsAsync(cutPoints, targetUser);
            }

            return(mapped);
        }