예제 #1
0
 private async Task <List <Notification> > GetUnSentNotifications(EnumList.NotifyMethod method)
 {
     return(await _context.Notifications.Where(x => x.Method == method)
            .Where(x => !x.Completed)
            .Where(x => x.Attempts < 3)
            .Where(x => x.TimeToSend <= Format.NorwayDateTimeNow()).ToListAsync());
 }
예제 #2
0
        public IActionResult Notifications(EnumList.Notifications type, EnumList.NotifyMethod method, bool receive = false)
        {
            //ToDo :: Implement Method here
            var userId = _access.GetUserId(User);

            if (string.IsNullOrEmpty(userId))
            {
                return(BadRequest());
            }

            var user = _context.Users.Find(userId);

            if (user == null)
            {
                return(BadRequest());
            }

            var userNotifications = _context.NoNotifications.Where(x => x.UserId == userId).Where(x => x.Method == method).ToList();


            if (receive)
            {
                if (!userNotifications.Any())
                {
                    return(BadRequest());
                }

                var notification = userNotifications.SingleOrDefault(x => x.NotificationType == type);
                if (notification == null)
                {
                    return(BadRequest());
                }

                _context.Remove(notification);
                _context.SaveChanges();
                return(Ok());
            }

            if (userNotifications.Any(x => x.NotificationType == type))
            {
                return(BadRequest());
            }

            var newNotNotify = new NoNotification {
                User = user, NotificationType = type, Method = method
            };

            _context.Add(newNotNotify);
            _context.SaveChanges();

            return(Ok());
        }
예제 #3
0
        public async Task <IActionResult> RevokeNotifications(EnumList.NotifyMethod method)
        {
            if (method == EnumList.NotifyMethod.Email)
            {
                await _notifications.RevokeEmail();
            }
            else
            {
                await _notifications.RevokeSms();
            }

            return(Ok());
        }