Beispiel #1
0
        //public bool Update(ArticlesModel model)
        //{
        //    try
        //    {
        //        var article = db.NewsArticles.Find(model.id);
        //        article.headline = article.headline;
        //        article.byLine = article.byLine;
        //        article.source = article.source;
        //        article.text = article.text;
        //        article.lastModifiedDate = DateTime.Now;

        //        var articleCategory = db.NewsArticleCategories.Where(a => a.newsArticleID == model.id).SingleOrDefault();
        //        articleCategory.newsCategoryID = articleCategory

        //        return true;
        //    }
        //    catch (Exception ex)
        //    {
        //        return false;
        //    }s
        //}
        public ActionResult Details(int id)
        {
            var user = new NewsArticles().ViewDetail(id);

            Models.ArticlesModel objArticle = new ArticlesModel();
            // Parse data
            objArticle.id           = user.id;
            objArticle.CategoryID   = user.CategoryID;
            objArticle.newsCategory = db.NewsCategories.Find(user.CategoryID).name;
            objArticle.headline     = user.headline;
            objArticle.extract      = user.extract;
            objArticle.encoding     = user.encoding;
            objArticle.text         = user.text;
            objArticle.publishDate  = user.publishDate;
            objArticle.byLine       = user.byLine;
            objArticle.source       = user.source;
            objArticle.state        = user.state;
            //objArticle.clientQuote = user.clientQuote;
            objArticle.createdDate         = user.createdDate;
            objArticle.lastModifiedDate    = user.lastModifiedDate;
            objArticle.htmlMetaDescription = user.htmlMetaDescription;
            objArticle.htmlMetaKeywords    = user.htmlMetaKeywords;
            objArticle.htmlMetaLangauge    = user.htmlMetaLangauge;
            objArticle.tags     = user.tags;
            objArticle.priority = user.priority;
            //objArticle.format = user.format;
            objArticle.photoHtmlAlt = user.photoHtmlAlt;
            //objArticle.photoWidth = user.photoWidth;
            //objArticle.photoHeight = user.photoHeight;
            objArticle.photoURL = user.photoURL;
            ViewBag.Title       = objArticle.headline;
            return(View(objArticle));
        }
        public ActionResult Detail(int id)
        {
            var article = new NewsArticles().ViewDetail(id);

            //ViewBag.NewsCategory = new NewsCategories().ViewDetail(article.CategoryID);
            return(View(article));
        }
Beispiel #3
0
        public ActionResult News()
        {
            HomeNewsModel HomeNewsModel = null;

            try
            {
                ViewBag.IsNewsPage = true;
                NewsArticles NewsItems = new NewsArticles();
                ViewBag.Title              = "Home";
                HomeNewsModel              = new HomeNewsModel();
                HomeNewsModel.AllNews      = NewsItems.GetAllNews();
                HomeNewsModel.NewsCategory = NewsItems.GetCategories();
                //HomeNewsModel.selectList = HomeNewsModel.NewsCategory.Select(m => new SelectCategory { ID = m.ID, Name = m.Name }).ToList();
                HomeNewsModel.SelectList = new List <SelectListItem>();
                //HomeNewsModel.SelectList = new MultiSelectList(HomeNewsModel.NewsCategory.Select(m => new SelectCategory { ID = m.ID, Name = m.Name }).ToList());
                //List <SelectListItem> FilterList = new List<SelectListItem>();
                foreach (var item in NewsItems.RetrieveAllCategories())
                {
                    HomeNewsModel.SelectList.Add(new SelectListItem
                    {
                        Selected = item.Filter,
                        Text     = item.Name,
                        Value    = Convert.ToString(item.ID)
                    });
                }
            }
            catch (Exception e)
            {
                Log.Info("Exception Thrown:" + e);
                Log.Debug("Exception thrown" + e);
                Log.Error("Error", e);
            }
            return(View(HomeNewsModel));
        }
        async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var activity = await result as IMessageActivity;

            if (activity.Text == DoneCommand)
            {
                context.Done(this);
                return;
            }

            NewsArticles articles = await new CognitiveService().SearchForNewsAsync(artistName);

            var reply = (context.Activity as Activity)
                        .CreateReply($"## Reading news about {artistName}");

            List <ThumbnailCard> cards = GetHeroCardsForArticles(articles);

            cards.ForEach(card =>
                          reply.Attachments.Add(card.ToAttachment()));

            ThumbnailCard doneCard = GetThumbnailCardForDone();

            reply.Attachments.Add(doneCard.ToAttachment());

            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;

            await
            new ConnectorClient(new Uri(reply.ServiceUrl))
            .Conversations
            .SendToConversationAsync(reply);

            context.Wait(MessageReceivedAsync);
        }
Beispiel #5
0
        public List <News> GetNews(string year)
        {
            var tournament = Tournaments.Single(x => x.Year == year);
            var news       = NewsArticles.Where(x => x.TournamentId == tournament.Id).ToList();

            return(news);
        }
        List <ThumbnailCard> GetHeroCardsForArticles(NewsArticles articles)
        {
            var cards =
                (from article in articles.Value
                 select new ThumbnailCard
            {
                Title = article.Name,
                Subtitle = "About: " + article.About.FirstOrDefault()?.Name,
                Text = article.Description,
                Images = new List <CardImage>
                {
                    new CardImage
                    {
                        Alt = article.Description,
                        Tap = BuildViewCardAction(article.Url),
                        Url = article.Image.Thumbnail.ContentUrl
                    }
                },
                Buttons = new List <CardAction>
                {
                    BuildViewCardAction(article.Url)
                }
            })
                .ToList();

            return(cards);
        }
Beispiel #7
0
        public ActionResult AddNews(FormCollection formCollection)
        {
            NewsArticles NewsArticles = new NewsArticles();

            if (ModelState.IsValid)
            {
                NewsModel News = new NewsModel();
                //News.ID = Convert.ToInt32(formCollection["ID"]);
                News.Category     = formCollection["Category"].ToString();
                News.Headline     = formCollection["NewsModel.Headline"].ToString();
                News.Text         = formCollection["NewsModel.Text"].ToString();
                News.Summary      = formCollection["NewsModel.Summary"].ToString();
                News.Source       = formCollection["NewsModel.Source"].ToString();
                News.Publish_Date = Convert.ToDateTime(formCollection["NewsModel.Publish_Date"]);
                News.ImageURL     = formCollection["NewsModel.ImageURL"].ToString();
                News.CategoryID   = Convert.ToString(NewsArticles.GetCategoryID(News.Category));
                News.AddedBy      = Convert.ToString(HttpContext.User.Identity.Name);
                NewsArticles.AddNews(News);
                TempData["Success"] = "News article Added successfully";
                AddNewsModel AddNewsModel = new AddNewsModel();
                AddNewsModel.CanAddNews = new UserAccounts().IsUserAuthorizedToAddNews(HttpContext.User.Identity.Name);
                AddNewsModel.Categories = NewsArticles.GetCategories().Select(value => new SelectListItem()
                {
                    Text = value.Name, Value = value.Name
                });
                return(PartialView(AddNewsModel));
            }
            return(View());
        }
Beispiel #8
0
        public ActionResult SearchNews(string search = "", string category = "", int page = 0)
        {
            PageModel SearchResults = new NewsArticles().ReturnSearchResults(search, category, page);

            ViewBag.Title = "Showing results for: " + search;
            return(PartialView("GetNews", SearchResults));
        }
Beispiel #9
0
        public async void MoreInfoNewsArticle(object param)
        {
            NewsArticles newsArticles = param as NewsArticles;

            var parameters = new NavigationParameters();

            parameters.Add("Id", newsArticles.Id);

            await _navigationService.NavigateAsync(new Uri("NavigationPage/NewsArticleDetailPage", UriKind.Relative), parameters);
        }
Beispiel #10
0
 public void Handle(NewsCreated e)
 {
     NewsArticles.Add(new News
     {
         Id           = e.NewsId,
         TournamentId = e.Id,
         Title        = e.Title,
         Content      = e.Content,
         Created      = e.Created
     });
 }
        public NewsArticles GetNewsArticles(IEnumerable <KeyValuePair <string, string> > parameters)
        {
            NewsArticles newsArticles = null;

            if (_newsArticles != null)
            {
                newsArticles = _newsArticles.GetNewsArticles(parameters);
            }

            return(newsArticles);
        }
        public NewsArticles GetNewsArticles()
        {
            NewsArticles newsArticles = null;

            if (_newsArticles != null)
            {
                newsArticles = _newsArticles.GetNewsArticles();
            }

            return(newsArticles);
        }
Beispiel #13
0
        public static NewsArticles Run([TimerTrigger("* 0 */6 * * *")] TimerInfo myTimer, ILogger log)
        //public static NewsArticles Run([TimerTrigger("* * * * * *")]TimerInfo myTimer, ILogger log)
        {
            var result = new NewsArticles
            {
                PartitionKey = "bbc-news",
                RowKey       = Guid.NewGuid().ToString(),
                Articles     = News.GetNews()
            };

            return(result);
        }
Beispiel #14
0
        public NewsArticles GetNewsArticles(IEnumerable <KeyValuePair <string, string> > parameters)
        {
            NewsArticles newsArticles = null;
            NewsArticle  newsArticle  = null;

            if (parameters != null)
            {
                foreach (var keyValuePair in parameters)
                {
                    if (!string.IsNullOrWhiteSpace(keyValuePair.Key) && !string.IsNullOrWhiteSpace(keyValuePair.Value))
                    {
                        uri = UriHelper.AddParameter(uri, keyValuePair.Key, keyValuePair.Value);
                    }
                }
            }

            var rootobject = WebRequestHelper.JsonToObject <Rootobject>(uri);

            if (rootobject != null && rootobject.articles != null && rootobject.articles.Length > 0)
            {
                foreach (var article in rootobject.articles)
                {
                    if (newsArticles == null)
                    {
                        newsArticles = new NewsArticles()
                        {
                            TotalNewsArticles = rootobject.totalResults
                        };
                    }

                    if (newsArticles.SelectedNewsArticles == null)
                    {
                        newsArticles.SelectedNewsArticles = new Collection <NewsArticle>();
                    }

                    newsArticle = new NewsArticle
                    {
                        Author             = article.author,
                        DatePublished      = article.publishedAt,
                        Description        = article.description,
                        Image              = article.urlToImage,
                        Name               = article.title,
                        SourceOrganisation = article.source?.name,
                        Url = article.url
                    };

                    newsArticles.SelectedNewsArticles.Add(newsArticle);
                }
            }

            return(newsArticles);
        }
Beispiel #15
0
        // GET: Home
        public ActionResult Index()
        {
            var newArticles = new NewsArticles();

            ViewBag.NewsArticles1 = newArticles.ListNewsArticle1(1);
            ViewBag.NewsArticles6 = newArticles.ListNewsArticle6(1);
            ViewBag.NewsArticles2 = newArticles.ListNewsArticle2(5);
            ViewBag.NewsArticles3 = newArticles.ListNewsArticle3(1);
            ViewBag.NewsArticles4 = newArticles.ListNewsArticle4(5);
            ViewBag.NewsArticles5 = newArticles.ListNewsArticle5(7);

            return(View());
        }
Beispiel #16
0
        public ActionResult Highlights()
        {
            List <NewsModel> HighlightsList;

            try
            {
                HighlightsList = new NewsArticles().GetHighlightsList();
            }
            catch (Exception)
            {
                throw;
            }
            return(PartialView(HighlightsList));
        }
        public ActionResult Category(int cateId)
        {
            var newArticles = new NewsArticles();

            ViewBag.NewsArticles1 = newArticles.ListNewsArticle1(1);
            ViewBag.NewsArticles6 = newArticles.ListNewsArticle6(1);
            ViewBag.NewsArticles2 = newArticles.ListNewsArticle2(5);
            ViewBag.NewsArticles3 = newArticles.ListNewsArticle3(1);
            ViewBag.NewsArticles4 = newArticles.ListNewsArticle4(5);
            ViewBag.NewsArticles5 = newArticles.ListNewsArticle5(7);

            var category = new NewsCategories().ViewDetail(cateId);

            return(View(category));
        }
Beispiel #18
0
        public ActionResult GetNews(int category, string categoryName, int page)
        {
            PageModel NewsList = null;

            try
            {
                ViewBag.IsNewsPage = true;
                NewsList           = new NewsArticles().GetCategoryNews(category, page);
                ViewBag.Title      = categoryName;
            }
            catch (Exception)
            {
                throw;
            }
            return(PartialView("GetNews", NewsList));
        }
Beispiel #19
0
        public async Task <NewsArticles> SearchForNewsAsync(string artistName)
        {
            const string BaseUrl = "https://api.cognitive.microsoft.com/bing/v5.0";
            string       url     = $"{BaseUrl}/news/search?" +
                                   $"q={Uri.EscapeUriString(artistName)}&" +
                                   $"category=Entertainment_Music&" +
                                   $"count=5";

            string accessKey = ConfigurationManager.AppSettings["SearchKey"];
            var    client    = new HttpClient();

            client.DefaultRequestHeaders.Add(AccessKey, accessKey);

            string response = await client.GetStringAsync(url);

            NewsArticles articles = JsonConvert.DeserializeObject <NewsArticles>(response);

            return(articles);
        }
Beispiel #20
0
        public ActionResult AddCategory(FormCollection form)
        {
            NewsArticles NewsArticles = new NewsArticles();

            if (ModelState.IsValid)
            {
                string Category = Convert.ToString(form["Category"]);
                if (NewsArticles.CheckIfCategoryExists(Category))
                {
                    ModelState.AddModelError("Category", "A duplicate category cannot be added");
                }
                else
                {
                    NewsArticles.AddCategory(Category);
                    TempData["Success"] = "Category Added Successfully!";
                }
            }

            return(View());
        }
Beispiel #21
0
        /// <summary>
        /// Reads the first article.
        /// </summary>
        /// <returns>The expected <see cref="ReadArticlePage"/> that should result from this action.</returns>
        public ReadArticlePage ReadFirstArticle()
        {
            WaitForLoad();

            var article = NewsArticles.FirstOrDefault();

            if (article == null)
            {
                return(new ReadArticlePage(Helper.ReadArticlePage.AbsoluteUri, Helper.ReadArticlePageTitle));
            }

            var readNowLink = article.FindElement(By.CssSelector(".card-action a"));
            var url         = readNowLink.GetAttribute("href");
            var title       = article.FindElement(By.CssSelector(".card-title")).Text;
            var pageTitle   = string.Format("{0} | {1}", title, Helper.ReadArticlePageTitle);

            readNowLink.Click();

            return(new ReadArticlePage(url, pageTitle));
        }
Beispiel #22
0
 public ActionResult Edit(ArticlesModel category)
 {
     if (ModelState.IsValid)
     {
         var         narticle   = new NewsArticles();
         NewsArticle newArticle = db.NewsArticles.Find(category.id);
         newArticle.CategoryID = category.CategoryID;
         newArticle.headline   = category.headline;
         newArticle.extract    = category.extract;
         newArticle.encoding   = category.encoding;
         newArticle.text       = category.text;
         //newArticle.publishDate = category.publishDate;
         newArticle.byLine = category.byLine;
         newArticle.source = category.source;
         newArticle.state  = category.state;
         //newArticle.clientQuote = category.clientQuote;
         newArticle.lastModifiedDate    = DateTime.Now;
         newArticle.htmlMetaDescription = category.htmlMetaDescription;
         newArticle.htmlMetaKeywords    = category.htmlMetaKeywords;
         newArticle.htmlMetaLangauge    = category.htmlMetaLangauge;
         newArticle.tags     = category.tags;
         newArticle.priority = category.priority;
         //newArticle.format = category.format;
         newArticle.photoHtmlAlt = category.photoHtmlAlt;
         //newArticle.photoWidth = category.photoWidth;
         //newArticle.photoHeight = category.photoHeight;
         newArticle.photoURL = category.photoURL;
         bool result = narticle.Update(newArticle);
         if (result)
         {
             return(RedirectToAction("Index", "NewsArticles"));
         }
         else
         {
             ModelState.AddModelError("", "Cập nhật tin tức không thành công!");
         }
     }
     return(View("Index"));
 }
Beispiel #23
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        NewsMessageModel nmsg = new NewsMessageModel();

        nmsg.touser = "******";
        List <NewsArticles> list     = new List <NewsArticles>();
        NewsArticles        articles = new NewsArticles();

        articles.description = "图文描述";
        articles.picurl      = "图片Url";
        articles.title       = "图片标题";
        articles.url         = "跳转Url";
        list.Add(articles);
        NewsArticles articles1 = new NewsArticles();

        articles1.description = "图文描述1";
        articles1.picurl      = "图片Url1";
        articles1.title       = "图片标题1";
        articles1.url         = "跳转Url1";
        list.Add(articles1);
        nmsg.news.articles = list;

        string json = JsonHelper.JsonSerializer(nmsg);
        string url  = "http://10.1.40.136:8040/Service/SaveService.ashx";

        HttpRequestHelper.HttpPostWebRequest(url, 10000, json);
        //string msg = SendMessageApi.CommSendMessageTest(json);//接手post请求测试
        //MusicMessageModel msModel = new MusicMessageModel();
        //msModel.touser = "******";
        //msModel.music.description = "音乐描述";
        //msModel.music.hqmusicurl = "高品质链接";
        //msModel.music.thumb_media_id = "缩略ID";
        //msModel.music.title = "主题";
        //msModel.music.musicurl = "音乐链接";
        //string json = JsonHelper.JsonSerializer(msModel);
        //msg = string.Format("<script>jsonF('{0}')</script>", msg);
        //div_show.InnerHtml = msg;
    }
        // GET: News
        public ActionResult Index()
        {
            List <NewsArticles> allNews      = new List <NewsArticles>();
            string        newsTextLocation   = "~/newscontent/text/";
            string        newsImagesLocation = "/Content/Images/news/";
            List <string> newsFileNames      = ConfigurationManager.AppSettings["newsFileNames"].Split('|').ToList();
            List <string> newsHeaders        = ConfigurationManager.AppSettings["newsHeaders"].Split('|').ToList();
            List <string> newsImages         = ConfigurationManager.AppSettings["newsImages"].Split('|').ToList();
            News          finalNews          = new News();

            var combinedNews = newsFileNames
                               .Zip(newsHeaders, (files, headers) => new {
                Files   = files,
                Headers = headers
            })
                               .Zip(newsImages, (fileHeader, images) => new {
                Files   = fileHeader.Files,
                Headers = fileHeader.Headers,
                Images  = images
            });

            foreach (var newsitem in combinedNews)
            {
                NewsArticles news          = new NewsArticles();
                string       fileLocation  = Server.MapPath(newsTextLocation) + newsitem.Files;
                string       newsContent   = System.IO.File.ReadAllText(fileLocation, Encoding.UTF8);
                string       imageLocation = newsImagesLocation + newsitem.Images;
                string       header        = newsitem.Headers;
                news.newsText   = newsContent;
                news.newsHeader = header;
                news.imageName  = imageLocation;
                allNews.Add(news);
            }
            finalNews.allNews = allNews;

            return(View(finalNews));
        }
        public IActionResult List(ListViewModel listViewModel)
        {
            if (listViewModel == null)
            {
                listViewModel = new ListViewModel();
            }

            string       memoryCacheKey = _memoryCacheKeyPrefix;
            NewsArticles newsArticles   = null;

            var parameters = new List <KeyValuePair <string, string> >();

            if (!string.IsNullOrWhiteSpace(listViewModel.Query))
            {
                parameters.Add(new KeyValuePair <string, string>("q", listViewModel.Query));
                memoryCacheKey = string.Format("{0}|{1}:{2}", memoryCacheKey, "q", listViewModel.Query);
            }

            if (!string.IsNullOrWhiteSpace(listViewModel.From))
            {
                parameters.Add(new KeyValuePair <string, string>("from", listViewModel.From));
                memoryCacheKey = string.Format("{0}|{1}:{2}", memoryCacheKey, "from", listViewModel.From);
            }

            if (!string.IsNullOrWhiteSpace(listViewModel.To))
            {
                parameters.Add(new KeyValuePair <string, string>("to", listViewModel.To));
                memoryCacheKey = string.Format("{0}|{1}:{2}", memoryCacheKey, "to", listViewModel.To);
            }

            if (!string.IsNullOrWhiteSpace(listViewModel.SortBy))
            {
                parameters.Add(new KeyValuePair <string, string>("sortBy", listViewModel.SortBy));
                memoryCacheKey = string.Format("{0}|{1}:{2}", memoryCacheKey, "sortBy", listViewModel.SortBy);
            }

            if (listViewModel.Page > 0)
            {
                parameters.Add(new KeyValuePair <string, string>("page", listViewModel.Page.ToString()));
                memoryCacheKey = string.Format("{0}|{1}:{2}", memoryCacheKey, "q", listViewModel.Page.ToString());
            }

            if (_memoryCache != null)
            {
                newsArticles = _memoryCache.Get <NewsArticles>(memoryCacheKey);
            }

            if (newsArticles == null)
            {
                if (parameters.Count > 0)
                {
                    newsArticles = _newsArticles.GetNewsArticles(parameters);
                }
                else
                {
                    newsArticles = _newsArticles.GetNewsArticles();
                }

                if (newsArticles != null && _memoryCache != null)
                {
                    _memoryCache.Set(memoryCacheKey, newsArticles);
                }
            }

            if (newsArticles != null)
            {
                if (listViewModel.Page == null)
                {
                    listViewModel.Page = 1;
                }

                listViewModel.NewsArticles = newsArticles.SelectedNewsArticles as IList <NewsArticle>;
                listViewModel.TotalResults = newsArticles.TotalNewsArticles;

                if (Request != null)
                {
                    var uriBuilder = new UriBuilder(UriHelper.GetDisplayUrl(Request));
                    var query      = HttpUtility.ParseQueryString(uriBuilder.Query);

                    if (listViewModel.Page > 1)
                    {
                        query.Remove("page");
                        query.Add("page", (listViewModel.Page - 1).ToString());
                        uriBuilder.Query = query.ToString();
                        listViewModel.PreviousPageUrl = uriBuilder.ToString();
                    }

                    if (listViewModel.TotalResults != null && listViewModel.Page <= (listViewModel.TotalResults / 20))
                    {
                        query.Remove("page");
                        query.Add("page", (listViewModel.Page + 1).ToString());
                        uriBuilder.Query          = query.ToString();
                        listViewModel.NextPageUrl = uriBuilder.ToString();
                    }
                }
            }

            return(View(listViewModel));
        }
Beispiel #26
0
        /// <summary>
        /// Latest news articles are displayed.
        /// </summary>
        /// <returns><c>true</c> if the latest news articles are visible, <c>false</c> otherwise.</returns>
        public bool LatestNewsArticlesExist()
        {
            WaitForLoad();

            return(NewsArticles.Any());
        }
Beispiel #27
0
    /// <summary>
    /// 回复消息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        string         data    = string.Empty;
        SendMessageApi sendApi = new SendMessageApi();

        #region 文本消息
        if (hidMsgType.Value == CommonEnum.enumMsgType.text.ToString())//文本消息
        {
            TextMessageModel txtModel = new TextMessageModel();
            txtModel.msgtype      = hidMsgType.Value;                            //消息类型
            txtModel.touser       = getmodel.TMIOpenId;                          //接收人
            txtModel.msgrelative  = getmodel.TMIMsgRelative;                     //消息唯一标识
            txtModel.msgsource    = CommonEnum.enumMsgSource.send.GetHashCode(); //消息来源
            txtModel.text.content = txtContent.Text.Trim();
            if (!sendApi.SendTextMessage(txtModel))
            {
                Response.Write("<script>alert('发送失败')</script>");
                return;
            }
            data = JsonHelper.JsonSerializer(txtModel);
        }
        #endregion

        #region 图片消息
        else if (hidMsgType.Value == CommonEnum.enumMsgType.image.ToString())//图片消息
        {
            ImageMessageModel imgModel = new ImageMessageModel();
            string            fileName = GetFileName(Fileimg.PostedFile, "imgMsg");
            if (string.IsNullOrEmpty(fileName))
            {
                Response.Write("<script>alert('上传文件为空')</script>");
                return;
            }
            imgModel.msgtype        = hidMsgType.Value;
            imgModel.touser         = getmodel.TMIOpenId;
            imgModel.msgrelative    = getmodel.TMIMsgRelative;                                                          //消息唯一标识
            imgModel.msgsource      = CommonEnum.enumMsgSource.send.GetHashCode();                                      //消息来源
            imgModel.image.media_id = CommMsgParam.UploadMultimedia(fileName, CommonEnum.enumMsgType.image.ToString()); //上传多媒体返回media_Id
            if (!sendApi.SendImageMessage(imgModel))
            {
                Response.Write("<script>alert('发送失败')</script>");
                return;
            }
            data = JsonHelper.JsonSerializer(imgModel);
        }
        #endregion

        #region 语音消息
        else if (hidMsgType.Value == CommonEnum.enumMsgType.voice.ToString())//语音消息
        {
            VoiceMessageModel vocModel = new VoiceMessageModel();
            string            fileName = GetFileName(Filevoice.PostedFile, "voiceMsg");
            if (string.IsNullOrEmpty(fileName))
            {
                Response.Write("<script>alert('上传文件为空')</script>");
                return;
            }
            vocModel.msgtype        = hidMsgType.Value;
            vocModel.touser         = getmodel.TMIOpenId;                                                               //接收人
            vocModel.msgrelative    = getmodel.TMIMsgRelative;                                                          //消息唯一标识
            vocModel.msgsource      = CommonEnum.enumMsgSource.send.GetHashCode();                                      //消息来源
            vocModel.voice.media_id = CommMsgParam.UploadMultimedia(fileName, CommonEnum.enumMsgType.voice.ToString()); //上传多媒体返回media_Id
            if (!sendApi.SendVoiceMessage(vocModel))
            {
                Response.Write("<script>alert('发送失败')</script>");
                return;
            }
            data = JsonHelper.JsonSerializer(vocModel);
        }
        #endregion

        #region 视频消息
        else if (hidMsgType.Value == CommonEnum.enumMsgType.video.ToString())//视频消息
        {
            VideoMessageModel vdoModel = new VideoMessageModel();
            string            fileName = GetFileName(FileVideo.PostedFile, "videoMsg");//上传返回名称
            if (string.IsNullOrEmpty(fileName))
            {
                Response.Write("<script>alert('上传文件为空')</script>");
                return;
            }
            vdoModel.msgtype              = hidMsgType.Value;
            vdoModel.touser               = getmodel.TMIOpenId;                                                               //接收人
            vdoModel.msgrelative          = getmodel.TMIMsgRelative;                                                          //消息唯一标识
            vdoModel.msgsource            = CommonEnum.enumMsgSource.send.GetHashCode();                                      //消息来源
            vdoModel.video.media_id       = CommMsgParam.UploadMultimedia(fileName, CommonEnum.enumMsgType.video.ToString()); //上传多媒体返回media_Id
            vdoModel.video.thumb_media_id = CommMsgParam.UploadMultimedia(fileName, CommonEnum.enumMsgType.thumb.ToString()); //上传多媒体返回media_Id
            vdoModel.video.title          = title.Text;
            vdoModel.video.description    = description.Text;
            if (!sendApi.SendVideoMessage(vdoModel))
            {
                Response.Write("<script>alert('发送失败')</script>");
                return;
            }
            data = JsonHelper.JsonSerializer(vdoModel);
        }
        #endregion

        #region 音乐消息
        else if (hidMsgType.Value == CommonEnum.enumMsgType.music.ToString())//音乐消息
        {
            MusicMessageModel musModel = new MusicMessageModel();
            string            fileName = GetFileName(FileMusic.PostedFile, "musicMsg");
            if (string.IsNullOrEmpty(fileName))
            {
                Response.Write("<script>alert('上传文件为空')</script>");
                return;
            }
            musModel.msgtype              = hidMsgType.Value;
            musModel.touser               = getmodel.TMIOpenId;                          //接收人
            musModel.msgrelative          = getmodel.TMIMsgRelative;                     //消息唯一标识
            musModel.msgsource            = CommonEnum.enumMsgSource.send.GetHashCode(); //消息来源
            musModel.music.musicurl       = musicUrl.Text.Trim();
            musModel.music.hqmusicurl     = hqMusicUrl.Text;
            musModel.music.title          = title.Text;
            musModel.music.description    = description.Text;
            musModel.music.thumb_media_id = CommMsgParam.UploadMultimedia(fileName, CommonEnum.enumMsgType.thumb.ToString());//上传多媒体返回media_Id;
            if (!sendApi.SendMusicMessage(musModel))
            {
                Response.Write("<script>alert('发送失败')</script>");
                return;
            }
            data = JsonHelper.JsonSerializer(musModel);
        }
        #endregion

        #region 图文消息
        else if (hidMsgType.Value == CommonEnum.enumMsgType.news.ToString())//图文消息
        {
            NewsMessageModel newsModel = new NewsMessageModel();
            newsModel.msgtype     = hidMsgType.Value;
            newsModel.touser      = getmodel.TMIOpenId;                          //接收人
            newsModel.msgrelative = getmodel.TMIMsgRelative;                     //消息唯一标识
            newsModel.msgsource   = CommonEnum.enumMsgSource.send.GetHashCode(); //消息来源
            List <NewsArticles> list = new List <NewsArticles>();
            string   newslist        = hidnewsType.Value.TrimEnd('|');
            string[] newsListArr     = newslist.Split('|');
            string   picUrls         = string.Empty;//获取所有的图片链接
            for (int i = 0; i < newsListArr.Length; i++)
            {
                NewsArticles articles = new NewsArticles();
                string[]     listArr  = newsListArr[i].Split(',');
                articles.title       = listArr[0]; //图文标题
                articles.url         = listArr[1]; //点击跳转的链接
                articles.picurl      = listArr[2]; //图文消息的链接
                articles.description = listArr[3]; //描述
                list.Add(articles);
                picUrls += list[0] + ",";
            }
            newsModel.news.articles = list;
            if (!sendApi.SendNewsMessage(newsModel))
            {
                Response.Write("<script>alert('发送失败')</script>");
                return;
            }
            data = JsonHelper.JsonSerializer(newsModel);
        }
        #endregion

        SaveMessage(data);//保存消息
    }
Beispiel #28
0
        public App()
        {
            InitializeComponent();

            MainPage = new NewsArticles();
        }
Beispiel #29
0
        public MainWindowViewModel()
        {
            //NewsArticles.Add(new Article() { Title = "Uno" });
            //NewsArticles.Add(new Article() { SourceImg = "Dos" });
            //NewsArticles.Add(new Article() { Byline = "Tres" });

            #region Data binding first part

            foreach (Article u in Data.articles)
            {
                if (u.articleID > Data.articles.Count - 10)
                {
                    NewsArticles.Insert(0, u);
                }
            }

            foreach (Article u in Data.articles)
            {
                if (u.articleID == Data.articles.Count - 1)
                {
                    OneArticle.Insert(0, u);
                }
            }


            foreach (Article u in Data.articles)
            {
                if (u.articleID == Data.articles.Count - 2)
                {
                    OneArticle2.Insert(0, u);
                }
            }


            foreach (Article u in Data.articles)
            {
                if (u.articleID == Data.articles.Count - 3)
                {
                    OneArticle3.Insert(0, u);
                }
            }

            foreach (Article u in Data.articles)
            {
                if (u.articleID == Data.articles.Count - 4)
                {
                    OneArticle4.Insert(0, u);
                }
            }

            foreach (Article u in Data.articles)
            {
                if (u.articleID == Data.articles.Count - 5)
                {
                    OneArticle5.Insert(0, u);
                }
            }

            foreach (Article u in Data.articles)
            {
                if (u.articleID == Data.articles.Count - 6)
                {
                    OneArticle6.Insert(0, u);
                }
            }

            #endregion

            foreach (Article u in Data.articles)
            {
                if (SomeCategory.currentCategory == "News")
                {
                    if (u.articleID < Data.articles.Count & u.category == "News")
                    {
                        NewsArticles_Category.Insert(0, u);
                    }
                }
                else if (SomeCategory.currentCategory == "Politics")
                {
                    if (u.articleID < Data.articles.Count & u.category == "Politics")
                    {
                        //NewsArticles_Category.Clear();
                        NewsArticles_Category.Insert(0, u);
                    }
                }
                else if (SomeCategory.currentCategory == "Opinion")
                {
                    if (u.articleID < Data.articles.Count & u.category == "Opinion")
                    {
                        //NewsArticles_Category.Clear();
                        NewsArticles_Category.Insert(0, u);
                    }
                }
                else if (SomeCategory.currentCategory == "Sports")
                {
                    if (u.articleID < Data.articles.Count & u.category == "Sports")
                    {
                        //NewsArticles_Category.Clear();
                        NewsArticles_Category.Insert(0, u);
                    }
                }

                else if (SomeCategory.currentCategory == "Entertainment")
                {
                    if (u.articleID < Data.articles.Count & u.category == "Entertainment")
                    {
                        //NewsArticles_Category.Clear();
                        NewsArticles_Category.Insert(0, u);
                    }
                }
                else if (SomeCategory.currentCategory == "Social")
                {
                    if (u.articleID < Data.articles.Count & u.category == "Social")
                    {
                        //NewsArticles_Category.Clear();
                        NewsArticles_Category.Insert(0, u);
                    }
                }
            }
        }
Beispiel #30
0
 public void Handle(NewsDeleted e)
 {
     NewsArticles.RemoveAll(x => x.Id == e.NewsId);
 }