public ActionResult MagentoDisconnect(ChannelMagentoViewModel channelMagento)
        {
            var userId = int.Parse(Session["CurrentUserId"].ToString());

            var getUserChannelMagento = userChannelSerivce.FindUserChannels(userId).SingleOrDefault(userChannel => userChannel.ChannelId == channelMagento.Id && userChannel.ChannelType == Shared.Enums.ChannelType.Magento && userChannel.IsActive == true);

            if (getUserChannelMagento != null)
            {
                getUserChannelMagento.IsActive = false;
                userChannelSerivce.Update(getUserChannelMagento);

                var connections = connectionService.GetConnectionsByUserChannelId(getUserChannelMagento.Id);
                foreach (var item in connections)
                {
                    item.IsActive = false;
                    connectionService.Update(item);
                }
            }

            return(RedirectToAction("Index", new { userId = userId }));
        }
        public ActionResult MagentoConnect(ChannelMagentoViewModel model)
        {
            var userId      = int.Parse(Session["CurrentUserId"].ToString());
            var isConnected = magentoService.IsConnected(model.Host, model.Username, model.Password);

            if (isConnected)
            {
                var channelMagento = mapper.Map <ChannelMagento>(model);
                channelMagento.CreatedDate = DateTime.UtcNow;
                channelMagento.Id          = channelMagentoService.Create(channelMagento);

                var userMagentoChannel = new UserChannel()
                {
                    UserId      = userId,
                    ChannelId   = channelMagento.Id,
                    ChannelType = Shared.Enums.ChannelType.Magento,
                    IsActive    = true,
                };

                userMagentoChannel.Id = userChannelSerivce.Create(userMagentoChannel);

                var userEbayChannel = userChannelSerivce.FindUserChannels(userId).SingleOrDefault(userChannel => userChannel.ChannelType == Shared.Enums.ChannelType.Ebay && userChannel.IsActive);

                if (userEbayChannel != null)
                {
                    CreateConnection(userEbayChannel.Id, userMagentoChannel.Id);
                }

                var userEmailChannel = userChannelSerivce.FindUserChannels(userId).SingleOrDefault(userChannel => userChannel.ChannelType == Shared.Enums.ChannelType.Email && userChannel.IsActive);
                if (userEmailChannel != null)
                {
                    CreateConnection(userEmailChannel.Id, userMagentoChannel.Id);
                }
            }

            return(RedirectToAction("Index", new { userId = userId }));
        }