Пример #1
0
        public ActionResult SaveSharing(long id, string urlThumbnail, YouTubeViewModel oModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = oCore.businessControllers.bcYouTube.Share(oUserProfile.oAccount, id, oModel.description);
                    if (result.Item2)
                    {
                        return PartialView("~/Views/Posts/ShareConfirm.cshtml", new Tuple<Post, bool, string>(result.Item1.Post, result.Item2, result.Item3));
                    }
                    else
                    {
                        ModelState.AddModelError("url", result.Item3);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("url", Resources.Resources.PhotoPublishingError1);

                //Salva o erro no arquivo de log do sistema
                ex.Save(new StackTrace(ex, true), ErrorLog.system);
            }

            var oPost = oCore.iRepositories.IPostRepository.Select(id);
            if (oPost == null || !oPost.IsActive || !oPost.IsYouTube)
            {
                return PartialView("~/Views/Posts/ShareConfirm.cshtml", new Tuple<Post, bool, string>(oPost, false, Resources.Resources.OperationError));
            }

            oModel.id = oPost.id;
            oModel.url = oPost.filename;
            oModel.videoId = oPost.YouTube.videoId;
            oModel.categoryId = oPost.categoryId;

            ViewBag.SharingPost = oPost;
            ViewBag.YouTubeThumbnail = urlThumbnail;

            return PartialView("Share", oModel);
        }
Пример #2
0
        public ActionResult Publish(YouTubeViewModel oModel)
        {
            var channels = oCore.iRepositories.ICategoryTypeRepository.Select(CTRecordStatus.Ative).OrderBy(model => model.name);
            ViewBag.Categories = channels;

            try
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        var yt = new YouTube()
                        {
                            videoId = oModel.videoId
                        };

                        if (yt.ResolveYoutube())
                        {
                            yt.ResolveYoutube(TopAppRouter.YoutubeDataSource, TopAppRouter.YoutubeApiKey, TopAppRouter.YoutubeApiResources, TopAppRouter.RemoteConectionTimeout);
                        }
                        else
                        {
                            yt.ExternalData = new YouTubeTemplate()
                            {
                                Id = yt.videoId
                            };

                            yt.videoId = Newtonsoft.Json.JsonConvert.SerializeObject(yt.ExternalData);
                            yt.ResolveYoutube(TopAppRouter.YoutubeDataSource, TopAppRouter.YoutubeApiKey, TopAppRouter.YoutubeApiResources, TopAppRouter.RemoteConectionTimeout);
                        }

                        if (yt.ResolveYoutube(TopAppRouter.YoutubeDataSource, TopAppRouter.YoutubeApiKey, TopAppRouter.YoutubeApiResources, TopAppRouter.RemoteConectionTimeout))
                        {
                            oModel.videoId = Newtonsoft.Json.JsonConvert.SerializeObject(yt.ExternalData);
                        }
                    }
                    catch
                    {

                    }

                    oModel.categoryId = (oModel.categoryId == null || oModel.categoryId == 0) ? 1 : oModel.categoryId;
                    var result = oCore.businessControllers.bcYouTube.Create(oUserProfile.oAccount, oModel.url, oModel.description, oModel.videoId, (long)oModel.categoryId);
                    if (result.Item2)
                    {
                        var chn = channels.SingleOrDefault(ch => ch.id == oModel.categoryId);
                        Country oCountry;
                        if (oUserProfile == null || oUserProfile.oAccount.Country1 == null)
                            oCountry = oCurrentUserLocation.Country;
                        else
                            oCountry = oUserProfile.oAccount.Country1;

                        return PartialView("Confirm", new Tuple<YouTube, CategoryType, System.Collections.Generic.IEnumerable<Post>>(result.Item1, chn, oCore.businessControllers.bcChannel.LatestPosts(oCountry, oUserProfile.oAccount, chn, PostType.YouTube, 6)));
                    }
                    else
                    {
                        ViewBag.ErrorMsg = Resources.Resources.YouTubeSharingError;
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMsg = Resources.Resources.YouTubeSharingError1;

                //Salva o erro no arquivo de log do sistema
                ex.Save(new StackTrace(ex, true), ErrorLog.system);
            }

            return PartialView("New", oModel);
        }
Пример #3
0
        public ActionResult Share(long id, string urlThumbnail)
        {
            try
            {
                var oPost = oCore.iRepositories.IPostRepository.Select(id);
                if (oPost == null || !oPost.IsActive || !oPost.IsYouTube)
                {
                    return PartialView("~/Views/Posts/ShareConfirm.cshtml", new Tuple<Post, bool, string>(oPost, false, Resources.Resources.OperationError));
                }

                oPost.YouTube.ResolveYoutube();
                var oModel = new YouTubeViewModel()
                {
                    id = oPost.id,
                    url = oPost.filename,
                    videoId = oPost.YouTube.ExternalData.Id,
                    categoryId = oPost.categoryId
                };

                ViewBag.SharingPost = oPost;
                ViewBag.YouTubeThumbnail = urlThumbnail;

                return PartialView(oModel);
            }
            catch (Exception ex)
            {
                //Salva o erro no arquivo de log do sistema
                ex.Save(new StackTrace(ex, true), ErrorLog.system);
            }

            return PartialView("~/Views/Posts/ShareConfirm.cshtml", new Tuple<Post, bool, string>(null, false, Resources.Resources.ProcessError));
        }