コード例 #1
0
        // GET: ServiceConnection
        public ActionResult Index(int?userId)
        {
            Session["CurrentUserId"] = userId;
            if (!userId.HasValue)
            {
                return(HttpNotFound());
            }

            var userChannels = userChannelSerivce.FindUserChannels(userId.Value).Where(channel => channel.IsActive);

            if (userChannels.Any())
            {
                viewModel = GenerateServiceConnectionVM(userChannels);
            }
            else
            {
                viewModel = new ServiceConnectionViewModel();
            }

            return(View(viewModel));
        }
コード例 #2
0
        private ServiceConnectionViewModel GenerateServiceConnectionVM(IEnumerable <UserChannel> userChannels)
        {
            //get channels' Ids
            var channelMagento = userChannels.SingleOrDefault(channel => channel.ChannelType == Shared.Enums.ChannelType.Magento);
            var channelEbay    = userChannels.SingleOrDefault(channel => channel.ChannelType == Shared.Enums.ChannelType.Ebay);
            var channelEmail   = userChannels.SingleOrDefault(channel => channel.ChannelType == Shared.Enums.ChannelType.Email);

            //assign channels into viewmodel
            ServiceConnectionViewModel model = new ServiceConnectionViewModel();

            if (channelMagento != null)
            {
                model.channelMagento = mapper.Map <ChannelMagentoViewModel>(
                    channelMagentoService.GetChannel(channelMagento.ChannelId)
                    );
                model.channelMagento.IsConnected = magentoService.IsConnected(model.channelMagento.Host, model.channelMagento.Username, model.channelMagento.Password);
            }
            if (channelEbay != null)
            {
                model.channelEbay = mapper.Map <ChannelEbayViewModel>(
                    channelEbayService.GetChannel(channelEbay.ChannelId)
                    );
                var validateToken = ebayService.IsValidToken(model.channelEbay.Token);
                if (!validateToken.HasError && validateToken.Result)
                {
                    model.channelEbay.IsConnected = true;
                }
            }
            if (channelEmail != null)
            {
                var channelEmailModel = channelEmailService.GetChannel(channelEmail.ChannelId);
                model.channelEmail = mapper.Map <ChannelEmailViewModel>(channelEmailModel);
                var token = mapper.Map <SmartHub.Channels.Gmail.Models.Token>(channelEmailModel);
                model.channelEmail.IsConnected = gmailService.IsConnected(token);
            }
            return(model);
        }