Beispiel #1
0
        public List <PostersDTO> LoadPostersData(string languageCode)
        {
            List <PostersDTO> postersRequest = null;

            string memoryCacheKey = languageCode;

            if (!memoryCache.TryGetValue(memoryCacheKey, out postersRequest))
            {
                postersRequest = new List <PostersDTO>();
                List <PerformanceDataModel> selectedPerformances =
                    perfomanceRepository.GetPerformanceTitlesAndImages(languageCode);
                foreach (var performance in selectedPerformances)
                {
                    postersRequest.Add(new PostersDTO()
                    {
                        MainImage =
                            performance.MainImageUrl == null
                                ? imageService.ImageToBase64(performance.MainImage)
                                : performance.MainImageUrl,
                        Title         = performance.Title,
                        PerformanceId = performance.PerformanceId
                    });
                }
                memoryCache.Set(memoryCacheKey, postersRequest);
            }

            return(postersRequest);
        }
Beispiel #2
0
        public void SendPushNotification()
        {
            var cacheProvider = new CacheProvider(memoryCache);

            //performances
            List <PerformanceDataModel> performancesWp =
                cacheProvider.GetAndSave(
                    () => Constants.PerformancesCacheKey + "uk",
                    () => perfomanceRepository.GetPerformanceTitlesAndImages("uk"));

            //schedule
            IEnumerable <ScheduleDataModelBase> scheduleWp =
                cacheProvider.GetAndSave(
                    () => Constants.ScheduleCacheKey + "uk",
                    () => scheduleRepository.GetListPerformancesByDateRange("uk", DateTime.Now));

            //statements above need to be changed when cache preload is implemented

            IEnumerable <PushTokenDataModelPartial> pushTokensPartial = pushTokenRepository.GetAllPushTokensToSendNotifications();

            List <PushTokenDataModel> pushTokens =
                (from partialInfo in pushTokensPartial
                 join performance in performancesWp on partialInfo.PerformanceId equals performance.PerformanceId
                 join schedule in scheduleWp on performance.PerformanceId equals schedule.PerformanceId

                 where (schedule.Beginning.Day == (DateTime.Today.AddDays(partialInfo.Frequency).Day) &&
                        (schedule.PerformanceId == partialInfo.PerformanceId))

                 select new PushTokenDataModel
            {
                Token = partialInfo.Token,
                LanguageCode = partialInfo.LanguageCode,
                ImageUrl = performance.MainImageUrl,
                Title = performance.Title
            })
                .Distinct(new PushTokenDataModelComparer())  //select distinct push tokens in order not to send several notifications
                .ToList();

            List <PushNotificationDTO> reqBody = (pushTokens.Select(p =>
                                                                    new PushNotificationDTO
            {
                To = p.Token,
                Title = p.LanguageCode == "en" ? "Lviv Puppet Theater" : "Львівський театр ляльок",
                Body = p.LanguageCode == "en" ?
                       $"{p.Title} coming soon" : $"{p.Title} скоро на сцені",
                Icon = $"{p.ImageUrl}",
                Color = "#9984d4"
            })).ToList();

            using (System.Net.WebClient client = new System.Net.WebClient())
            {
                client.Headers.Add("accept", "application/json");
                client.Headers.Add("accept-encoding", "gzip, deflate");
                client.Headers.Add("Content-Type", "application/json");
                client.UploadString(
                    "https://exp.host/--/api/v2/push/send",
                    JsonConvert.SerializeObject(reqBody));
            }
        }
        public IEnumerable <WishlistDTO> LoadWishlist(string AccountId, string languageCode)
        {
            var cacheProvider = new CacheProvider(memoryCache);

            var performancesWp = cacheProvider.GetAndSave(
                () => GetKey(languageCode),
                () => perfomanceRepository.GetPerformanceTitlesAndImages(languageCode));

            var perfIds = WishlistRepository.GetPerformanceIdsInWishlist(AccountId, languageCode);

            var result = from perfId in perfIds
                         join perfWp in performancesWp
                         on perfId equals perfWp.PerformanceId
                         select new WishlistDTO
            {
                PerformanceId = perfId,
                MainImage     = perfWp.MainImageUrl,
                Title         = perfWp.Title
            };

            return(result);
        }