Example #1
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));
            }
        }
Example #2
0
        public PerformanceDetailsBaseDTO LoadPerformanceDetails(string Accountid, string languageCode, int performanceId)
        {
            var cacheProvider = new CacheProvider(memoryCache);

            var isChecked = isCheckedPerformanceRepository.IsChecked(Accountid, performanceId);

            performanceDetailsRequest = cacheProvider.GetAndSave(
                () => GetCacheKey(languageCode, performanceId),
                () =>
            {
                var performance = performanceDetailsRepository
                                  .GetInformationAboutPerformance(Accountid, languageCode, performanceId)
                                  as PerformanceDetailsDataModelWp;

                var tags         = tagRepository.GetTagsByPerformanceId(performanceId).Result;
                var creativeTeam = creativeTeamRepository.GetCreativeTeam(languageCode, performanceId);

                performanceDetailsRequest = new PerformanceDetailsWpDTO()
                {
                    Title        = performance.Title,
                    Duration     = performance.Duration,
                    MinimumAge   = performance.MinimumAge,
                    MinPrice     = performance.MinPrice,
                    MaxPrice     = performance.MaxPrice,
                    Description  = performance.Description,
                    MainImage    = performance.MainImage,
                    GalleryImage = performance.GalleryImage,
                    HashTag      = from tg in tags
                                   select tg,
                    TeamMember = from tm in creativeTeam
                                 select new TeamMemberDTO()
                    {
                        FirstName = tm.FirstName,
                        LastName  = tm.LastName,
                        Role      = tm.Role,
                        RoleKey   = tm.RoleKey,
                    },
                };

                return(performanceDetailsRequest);
            });

            performanceDetailsRequest.IsChecked = isChecked;

            return(performanceDetailsRequest);
        }
        public IEnumerable <ScheduleBaseDTO> FilterByDate(
            string languageCode,
            DateTime?startDate)
        {
            var cacheProvider = new CacheProvider(memoryCache);

            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ScheduleBaseDTO, ScheduleWpDTO>())
                         .CreateMapper();

            IEnumerable <ScheduleDataModelBase> schedule =
                cacheProvider.GetAndSave(
                    () => Constants.ScheduleCacheKey + languageCode,
                    () => scheduleRepositoryWp.GetListPerformancesByDateRange(languageCode, startDate));

            IEnumerable <ScheduleWpDTO> scheduleList =
                mapper.Map <IEnumerable <ScheduleDataModelBase>, List <ScheduleWpDTO> >(schedule);

            return(scheduleList = scheduleList.Where(s => (!startDate.HasValue || s.Beginning >= startDate)));
        }
        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);
        }