/// <summary>
        /// Gets list object of the table Notifications.
        /// </summary>
        /// <param name="paginationDto">Attributes to apply the pagination.</param>
        /// <param name="listFilterNotifications">List that contains the DTOs from Notifications table that filter the query.</param>
        /// <returns>List object of the table Notifications.</returns>
        /// <author>Mauricio Suárez.</author>
        public List <NotificationsDto> GetNotifications(PaginationDto paginationDto, NotificationsDto dtoNotifications)
        {
            List <NotificationsDto> listFilterNotifications = new List <NotificationsDto>();

            listFilterNotifications.Add(dtoNotifications);
            return(this.ExecuteGetNotifications(paginationDto, listFilterNotifications));
        }
        /// <summary>
        /// Save or update records for the table
        /// </summary>
        /// <param name="listDataNotifications">List of data to store Notifications.</param>
        /// <returns>The result of processing the list.</returns>
        /// <author>Mauricio Suárez.</author>
        public bool SaveNotifications(NotificationsDto dtoNotifications)
        {
            List <NotificationsDto> listDataNotifications = new List <NotificationsDto>();

            listDataNotifications.Add(dtoNotifications);
            return(this.SaveNotifications(listDataNotifications));
        }
        /// <summary>
        /// Gets list object of the table Notifications.
        /// </summary>
        /// <param name="lFilterNotifications">List that contains the DTOs from Notifications table that filter the query.</param>
        /// <returns>List object of the table Notifications.</returns>
        /// <author>Mauricio Suárez.</author>
        public List <NotificationsDto> GetNotifications(NotificationsDto dtoNotifications)
        {
            List <NotificationsDto> listFilterNotifications = new List <NotificationsDto>();

            listFilterNotifications.Add(dtoNotifications);
            return(this.ExecuteGetNotifications(null, listFilterNotifications));
        }
        public IHttpActionResult SendNotifications(NotificationsDto notificationsDto)
        {
            var user = _context.Users.SingleOrDefault(u => u.Id == notificationsDto.UserId);

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

            var movie = _context.Movies.SingleOrDefault(m => m.Id == notificationsDto.MovieId);

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

            var rentals        = _context.UserRentals.SingleOrDefault(u => u.Movie.Id == notificationsDto.MovieId && u.Users.Id == notificationsDto.UserId);
            int dateDifference = 0;

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

            dateDifference = rentals.DateReturned.HasValue ? Convert.ToInt32(rentals.DateReturned.Value.Subtract(DateTime.Now).TotalDays) : 0;

            if (notificationsDto.Message == null)
            {
                notificationsDto.Message = string.Format("Your rental subscription for the movie {0} ends in {1} days", rentals.Movie.Name.ToUpper(), dateDifference);
            }

            var notify = new Notifications
            {
                DateReceived = DateTime.Now,
                Movie        = movie,
                User         = user,
                Message      = notificationsDto.Message,
                HasBeenRead  = false
            };


            _context.Notifications.Add(notify);
            _context.SaveChanges();


            return(Ok());
        }
        public async Task<IActionResult> GetNotifications([FromQuery] long etag = 0)
        {
            var timestamp = Instant.FromUnixTimeMilliseconds(etag);

            var notifications = await userNotificationsStore.QueryAsync(App.Id, UserId, 100, timestamp, HttpContext.RequestAborted);

            var response = new NotificationsDto
            {
                Notifications = notifications.Select(NotificationDto.FromNotification).ToArray()
            };

            if (notifications.Any())
            {
                response.Etag = notifications.Max(x => x.Updated).ToUnixTimeMilliseconds();
            }
            else if (timestamp != default)
            {
                return NoContent();
            }

            return Ok(response);
        }