public IChannel Post(AddChannelDto addChannelDto)
        {
            var identity = (Identity)this.User.Identity;
            if (!addChannelDto.Rss.ToLower().StartsWith("http"))
            {
                addChannelDto.Rss = "http://" + addChannelDto.Rss;
            }

            return this.channelService.AddChannel(identity.User.GetUserGuid(), new Uri(addChannelDto.Rss));
        }
        public ActionResult Add(AddChannelDto dto)
        {
            if (this.ModelState.IsValid == false)
            {
                return this.View("Add", dto);
            }

            this.rssChannelsService.CreateNewChannelIfNotExists(dto);
            this.rssSubscriptionService.SubscribeCurrentUserToChannel(dto);
            return this.RedirectToAction("My");
        }
Beispiel #3
0
        public void SubscribeCurrentUserToChannel(long channelId)
        {
            var rssChannel    = this.rssChannelsRepository.Load(channelId);
            var addChannelDto = new AddChannelDto
            {
                RssChannelLink = rssChannel.Url,
                RssChannelName = rssChannel.Title
            };

            this.SubscribeCurrentUserToChannel(addChannelDto);
        }
        public void CreateNewChannelIfNotExists(AddChannelDto dto)
        {
            var idByChannelUrl = this.channelsRepository.GetIdByChannelUrl(new List <string> {
                dto.RssChannelLink
            });

            if (!idByChannelUrl.Any())
            {
                CreateNewChannel(dto);
            }
        }
        public virtual ActionResult Add(AddChannelDto dto)
        {
            if(this.ModelState.IsValid == false)
            {
                return this.View("Add", dto);
            }

            this.service.CreateNewChannelIfNotExists(dto);
            this.service.SubscribeCurrentUserToChannel(dto);
            return this.RedirectToAction(MVC.Subscriptions.Index());
        }
Beispiel #6
0
        public ActionResult Add(AddChannelDto dto)
        {
            if (this.ModelState.IsValid == false)
            {
                return(this.View("Add", dto));
            }

            this.rssChannelsService.CreateNewChannelIfNotExists(dto);
            this.rssSubscriptionService.SubscribeCurrentUserToChannel(dto);
            return(this.RedirectToAction("My"));
        }
Beispiel #7
0
        public void SubscribeCurrentUserToChannel(AddChannelDto channelId)
        {
            var currentUserId = this.infrastructure.GetCurrentUserId();
            var isUserSubscribedToChannelUrl =
                this.entityRepository.IsUserSubscribedToChannelUrl(currentUserId, channelId.RssChannelLink);

            if (!isUserSubscribedToChannelUrl)
            {
                var idByChannelUrl = this
                                     .entityRepository.GetIdByChannelUrl(new List <string> {
                    channelId.RssChannelLink
                })
                                     .Single();
                this.entityRepository.Subscribe(idByChannelUrl, currentUserId, channelId.RssChannelName);
            }
        }
        private void CreateNewChannel(AddChannelDto dto)
        {
            var rssChannel = this.mapping.Map <RssChannel>(dto);

            this.channelsRepository.SaveToDatabase(new List <RssChannel> {
                rssChannel
            });
            var listIds = this.channelsRepository.GetIdByChannelUrl(new List <string> {
                rssChannel.Url
            });
            var id = listIds.Single();

            var eventRssChannelCreated = new EventRssChannelCreated
            {
                RssChannelId = id
            };

            this.eventRssChannelCreatedRepository.SaveToDatabase(eventRssChannelCreated);
        }
Beispiel #9
0
        private void CreateNewChannel(AddChannelDto dto)
        {
            var rssSourceWithUrlAndTitles =
                new List <RssSourceWithUrlAndTitle>
            {
                new RssSourceWithUrlAndTitle(
                    dto.RssChannelLink,
                    dto.RssChannelName)
            };
            var cui = this.infrastructure.GetCurrentUserId();

            this.entityRepository.SaveToDatabase(cui, rssSourceWithUrlAndTitles);
            var urlsToChannels = new List <string> {
                dto.RssChannelLink
            };
            var listIds = this.entityRepository.GetIdByChannelUrl(urlsToChannels);
            var id      = listIds.Single();

            this.entityRepository.SaveChannelCreatedEventToDatabase(cui, id);
        }
Beispiel #10
0
        public void T001_When_Checking_If_Channel_Exists_Then_Must_Load_It_First_From_Repository()
        {
            // arrange
            var dto = new AddChannelDto();

            var value = new List <long>()
            {
                1, 2, 3
            };

            this.mockChannelRepository
            .Setup(s => s.GetIdByChannelUrl(It.IsAny <List <string> >()))
            .Returns(value);

            // act
            this.sut.CreateNewChannelIfNotExists(dto);

            // assert
            this.mockChannelRepository
            .Verify(v => v.GetIdByChannelUrl(It.IsAny <List <string> >()),
                    Times.Once());
        }
        public void SubscribeCurrentUserToChannel(AddChannelDto channelId)
        {
            var currentUserId = this.authentication.GetCurrentUserId();
            var isUserSubscribedToChannelUrl = this.rssSubscriptionsRepository.IsUserSubscribedToChannelUrl(currentUserId, channelId.RssChannelLink);

            if (!isUserSubscribedToChannelUrl)
            {
                var idByChannelUrl = this.rssChannelsRepository
                    .GetIdByChannelUrl(new List<string> { channelId.RssChannelLink })
                    .Single();

                this.rssSubscriptionsRepository.Subscribe(idByChannelUrl, currentUserId, channelId.RssChannelName);
            }
        }