Ejemplo n.º 1
0
 public PushNotificationSetting SwitchNotification(int userId, bool switchFlag)
 {
     try
     {
         PushNotificationSetting setting = dbContext.PushNotificationSetting.SingleOrDefault(x => x.UserId == userId);
         if (setting != null)
         {
             setting.IsTurnOn = switchFlag;
             dbContext.SaveChanges();
             return(setting);
         }
         else
         {
             PushNotificationSetting newSetting = new PushNotificationSetting
             {
                 UserId   = userId,
                 IsTurnOn = switchFlag
             };
             dbContext.PushNotificationSetting.Add(newSetting);
             dbContext.SaveChanges();
             return(newSetting);
         }
     }
     catch (Exception ex)
     {
         logger.LogDebug(ex.Message);
     }
     return(null);
 }
Ejemplo n.º 2
0
 public PushNotificationSetting UpdateMobileToken(int userId, string mobileToken)
 {
     try
     {
         PushNotificationSetting setting = dbContext.PushNotificationSetting.SingleOrDefault(x => x.UserId == userId);
         if (setting != null)
         {
             setting.MobileToken = mobileToken;
             dbContext.SaveChanges();
             return(setting);
         }
         else
         {
             PushNotificationSetting newSetting = new PushNotificationSetting
             {
                 UserId      = userId,
                 MobileToken = mobileToken
             };
             dbContext.PushNotificationSetting.Add(newSetting);
             dbContext.SaveChanges();
             return(newSetting);
         }
     }
     catch (Exception ex)
     {
         logger.LogDebug(ex.Message);
     }
     return(null);
 }
Ejemplo n.º 3
0
        //[AllowAnonymous]
        public MessageModel <NotificationSettingDTO> GetNotificationState()
        {
            var userId = int.Parse(User.FindFirstValue("id"));
            PushNotificationSetting result = notificationService.GetNotificationState(userId);
            NotificationSettingDTO  dto    = mapper.Map <NotificationSettingDTO>(result);

            return(new MessageModel <NotificationSettingDTO>
            {
                Msg = result == null ? "error" : "",
                Data = dto
            });
        }
Ejemplo n.º 4
0
        //[AllowAnonymous]
        public MessageModel <NotificationSettingDTO> SwitchNotification([FromBody] NotificationSettingRequest request)
        {
            var userId = int.Parse(User.FindFirstValue("id"));
            PushNotificationSetting result = notificationService.SwitchNotification(userId, request.IsTurnOn);
            NotificationSettingDTO  dto    = mapper.Map <NotificationSettingDTO>(result);

            return(new MessageModel <NotificationSettingDTO>
            {
                Msg = result == null ? "error" : "",
                Data = dto
            });
        }
Ejemplo n.º 5
0
        //[AllowAnonymous]
        public MessageModel <NotificationSettingDTO> UpdateMobileToken([FromBody] NotificationTokenRequest request)
        {
            var userId = int.Parse(User.FindFirstValue("id"));
            //int userId = 1;
            PushNotificationSetting result = notificationService.UpdateMobileToken(userId, request.MobileToken);
            NotificationSettingDTO  dto    = mapper.Map <NotificationSettingDTO>(result);

            return(new MessageModel <NotificationSettingDTO>
            {
                Msg = result == null?"error":"",
                Data = dto
            });
        }
Ejemplo n.º 6
0
 private string GetTokenByUserId(int userId)
 {
     try
     {
         PushNotificationSetting setting = dbContext.PushNotificationSetting.SingleOrDefault(x => x.UserId == userId);
         if (setting != null)
         {
             return(setting.MobileToken);
         }
     }
     catch (Exception ex)
     {
         logger.LogError(ex.Message);
     }
     return(null);
 }