Пример #1
0
        /// <summary>
        /// Update notification as make seen status true.
        /// </summary>
        /// <param name="userId">UserId</param>
        /// <param name="notification">Notification object</param>
        /// <returns>Returns boolean value according to Notification is added successfully or not</returns>
        public bool UpdateNotification(int userId, Common.Entity.Notification notification)
        {
            try
            {
                using (TrainingTrackerEntities context = new TrainingTrackerEntities())
                {
                    context.UserNotificationMappings
                    .Where(s => s.UserId == userId && !s.Seen && s.NotificationId == notification.NotificationId)
                    .ToList()
                    .ForEach(s => { s.Seen = true; });

                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogUtility.ErrorRoutine(ex);
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Function AddNotification which add notification for a list of user.
        /// </summary>
        /// <param name="notification">Notification object</param>
        /// <param name="userIds">List of userid</param>
        /// <returns>Return true if a notification is added successfully else false.</returns>
        public bool AddNotification(Common.Entity.Notification notification, List <int> userIds)
        {
            try
            {
                using (TrainingTrackerEntities context = new TrainingTrackerEntities())
                {
                    var entityFrameworkNotification = new EntityFramework.Notification
                    {
                        Description       = notification.Description,
                        Link              = notification.Link,
                        NotificationType  = (int)notification.TypeOfNotification,
                        AddedOn           = notification.AddedOn,
                        NotificationTitle = notification.Title,
                        AddedBy           = notification.AddedBy
                    };

                    foreach (var user in userIds)
                    {
                        entityFrameworkNotification.UserNotificationMappings.Add(new UserNotificationMapping
                        {
                            UserId = user,
                            Seen   = false
                        });
                    }

                    context.Notifications.Add(entityFrameworkNotification);
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                LogUtility.ErrorRoutine(e);
                return(false);
            }
        }