public Task <bool> updateNotificationsAsync(object notif)
        {
            if (notif is AmountConstraint)
            {
                AmountConstraint castedNotif = (AmountConstraint)notif;
                var existingNotif            = _context.AmountConstraint
                                               .Where(x => x.NotificationId == castedNotif.NotificationId)
                                               .FirstOrDefault();
                if (existingNotif != null)
                {
                    existingNotif.Min = castedNotif.Min;
                    existingNotif.Max = castedNotif.Max;
                    _context.SaveChanges();
                }
                else
                {
                    return(Task.FromResult(false));
                }
            }
            else if (notif is TimeConstraint)
            {
                TimeConstraint castedNotif   = (TimeConstraint)notif;
                var            existingNotif = _context.TimeConstraint
                                               .Where(x => x.NotificationId == castedNotif.NotificationId)
                                               .FirstOrDefault();
                if (existingNotif != null)
                {
                    existingNotif.TimeIn  = castedNotif.TimeIn;
                    existingNotif.TimeOut = castedNotif.TimeOut;
                    _context.SaveChanges();
                }
                else
                {
                    return(Task.FromResult(false));
                }
            }
            else if (notif is LocationConstraint)
            {
                LocationConstraint castedNotif = (LocationConstraint)notif;
                var existingNotif = _context.LocationConstraint
                                    .Where(x => x.NotificationId == castedNotif.NotificationId)
                                    .FirstOrDefault();
                if (existingNotif != null)
                {
                    existingNotif.Location = castedNotif.Location;
                    _context.SaveChanges();
                }
                else
                {
                    return(Task.FromResult(false));
                }
            }

            return(Task.FromResult(true));
        }
        /// <summary>
        /// Returns a list of the user's AmountConstraint notifcation rules
        /// </summary>
        /// <param name="notifID"></param>
        /// <returns> List of AmountConstraint</returns>
        public async Task <List <AmountConstraint> > GetAmountConstraints(List <UserToNotifications> notifArray)
        {
            List <AmountConstraint> amountConstraints = new List <AmountConstraint>();
            List <AmountConstraint> testC             = new List <AmountConstraint>();

            foreach (var z in notifArray)
            {
                testC = _context.AmountConstraint.Where(x => x.NotificationId == z.NotificationId).ToList();

                if (testC.Count > 0)
                {
                    AmountConstraint temp = _context.AmountConstraint.Where(x => x.NotificationId == z.NotificationId).ToList()[0];

                    amountConstraints.Add(temp);
                }
            }

            return(amountConstraints);
        }
        public Task <bool> DeleteNotificationAsync(object notif)
        {
            if (notif is AmountConstraint)
            {
                AmountConstraint castedNotif = (AmountConstraint)notif;
                var existingNotif            = _context.AmountConstraint
                                               .Where(x => x.NotificationId == castedNotif.NotificationId)
                                               .FirstOrDefault();
                var existingJoin = _context.UserToNotifications
                                   .Where(y => y.NotificationId == castedNotif.NotificationId)
                                   .FirstOrDefault();
                if (existingNotif != null)
                {
                    _context.AmountConstraint.Remove(existingNotif);
                    _context.UserToNotifications.Remove(existingJoin);
                    _context.SaveChanges();
                }
                else
                {
                    return(Task.FromResult(false));
                }
            }
            else if (notif is TimeConstraint)
            {
                TimeConstraint castedNotif   = (TimeConstraint)notif;
                var            existingNotif = _context.TimeConstraint
                                               .Where(x => x.NotificationId == castedNotif.NotificationId)
                                               .FirstOrDefault();
                var existingJoin = _context.UserToNotifications
                                   .Where(y => y.NotificationId == castedNotif.NotificationId)
                                   .FirstOrDefault();
                if (existingNotif != null)
                {
                    _context.TimeConstraint.Remove(existingNotif);
                    _context.UserToNotifications.Remove(existingJoin);
                    _context.SaveChanges();
                }
                else
                {
                    return(Task.FromResult(false));
                }
            }
            else if (notif is LocationConstraint)
            {
                LocationConstraint castedNotif = (LocationConstraint)notif;
                var existingNotif = _context.LocationConstraint
                                    .Where(x => x.NotificationId == castedNotif.NotificationId)
                                    .FirstOrDefault();
                var existingJoin = _context.UserToNotifications
                                   .Where(y => y.NotificationId == castedNotif.NotificationId)
                                   .FirstOrDefault();
                if (existingNotif != null)
                {
                    _context.LocationConstraint.Remove(existingNotif);
                    _context.UserToNotifications.Remove(existingJoin);
                    _context.SaveChanges();
                }
                else
                {
                    return(Task.FromResult(false));
                }
            }

            return(Task.FromResult(true));
        }
 /// <summary>
 /// Adds a new AmountConstraint notification rule to database context
 /// </summary>
 /// <param name="newNotif"></param>
 /// <returns>true or false from Task</returns>
 public Task <AmountConstraint> AddAmountNotification(AmountConstraint newNotif)
 {
     _context.AmountConstraint.Add(newNotif);
     _context.SaveChanges();
     return(Task.FromResult(newNotif));
 }