Exemple #1
0
        public static bool AddOrUpdateNotification(NotificationMessageModel notifyData)
        {
            bool success = false;

            try
            {
                using (var db = new NotificationMessageContext())
                {
                    var data = db.Notification
                               .Where(p => p.UserId == notifyData.UserId &&
                                      p.Type == notifyData.Type)
                               .FirstOrDefault();

                    if (data != null)
                    {
                        data.IsShow = notifyData.IsShow;
                    }
                    else
                    {
                        db.Notification.Add(notifyData);
                    }
                    success = true;

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                success = false;
            }

            return(success);
        }
Exemple #2
0
        public static NotificationMessageModel GetNotificationSettingByUserIdAndType(int userId, TypeNotification type)
        {
            NotificationMessageModel data = null;

            try
            {
                using (var db = new NotificationMessageContext())
                {
                    data = db.Notification
                           .Where(p => p.UserId == userId &&
                                  p.Type == type)
                           .FirstOrDefault();

                    if (data == null)
                    {
                        data = new NotificationMessageModel()
                        {
                            IsShow = true, Type = type
                        };
                    }
                }
            }
            catch (Exception e)
            {
                data = new NotificationMessageModel()
                {
                    IsShow = true, Type = type
                };
            }

            return(data);
        }