コード例 #1
0
ファイル: NewsController.cs プロジェクト: kduytoan1994/Mobile
        public async Task<ActionResult> NewsList()
        {
            try
            {
                ParseQuery<ParseObject> query = ParseObject.GetQuery("News");
                IEnumerable<ParseObject> newsList = await query.FindAsync();

                List<NewsViewModel> _newsList = new List<NewsViewModel>();

                foreach (ParseObject n in newsList)
                {
                    NewsViewModel news = new NewsViewModel();
                    news.newsId = n.ObjectId;
                    news.title = n.Get<string>("title");
                    news.content = n.Get<string>("content");
                    _newsList.Add(news);
                }
                return View(_newsList);

            }
            catch (ParseException pe)
            {
                return View();
            }
        }
コード例 #2
0
 private NewsViewModel GetNewsViewModel(string tag)
 {
     var newsViewModel = new NewsViewModel();
     newsViewModel.RSSFeeds = newsService.GetNewsSources();
     newsViewModel.CurrentRSSFeed = newsService.GetNewsFeedUrl(tag);
     newsViewModel.TitleUrlListViewModel = GetOtherNews(newsViewModel.RSSFeeds);
     return newsViewModel;
 }
コード例 #3
0
 public ActionResult NewsEdit(int id) 
 {
     using (var c = new WebDbContext())
     {
         var post = c.News.Find(id);
         if (post == null) return new HttpNotFoundResult();
         NewsViewModel mdl = new NewsViewModel();
         mdl.Id = post.Id;
         mdl.ImageFile = post.Image;
         mdl.Title = post.Title;
         mdl.HtmlContent = post.HtmlContent;
         return View(mdl);
     } 
 }
コード例 #4
0
        public bool Update(NewsViewModel model)
        {
            var entity = uow.Set <News>().Find(model.Id);

            if (entity == null)
            {
                return(false);
            }
            entity.Index    = model.Index;
            entity.Title    = model.Title;
            entity.Content  = model.Content;
            entity.Year     = model.Year;
            entity.Category = uow.Set <NewsCategory>().Find(model.CategoryId);
            uow.Commit();
            return(true);
        }
コード例 #5
0
        public ActionResult Edit(int id)
        {
            var service = this.Service <INewsService>();
            var news    = service.GetActive(q => q.Id == id).SingleOrDefault();

            if (news != null)
            {
                var model = new NewsViewModel(news);
                model.Categories = (this.Service <ICategoryService>()).GetActive().ProjectTo <CategoryViewModel>(MapperConfig);
                return(View(model));
            }
            else
            {
                return(View(new NewsViewModel()));
            }
        }
コード例 #6
0
        public PartialViewResult ShowNewses()
        {
            pszczupakEntities    ent   = new pszczupakEntities();
            List <NewsViewModel> lista = new List <NewsViewModel>();

            foreach (News item in ent.News.OrderByDescending(x => x.add_date).Take(10))
            {
                NewsViewModel model = new NewsViewModel();
                model.add_date = item.add_date;
                model.news1    = item.news1;
                model.user_id  = item.user_id;
                model.id       = item.id;
                lista.Add(model);
            }
            return(PartialView(lista));
        }
コード例 #7
0
        public ActionResult EditNews(NewsViewModel newsViewModel)
        {
            var news = Mapper.Map <NewsDTO>(newsViewModel);
            //var allSections = newsService.GetAllSections(); // SectionId
            //var selectedSection = allSections.FirstOrDefault(x => x.Id == newsViewModel.SectionId);
            //news.Section = selectedSection;
            var allSections     = newsService.GetAllSections();
            var selectedSection = allSections.FirstOrDefault(x => x.Id == newsViewModel.SectionId);

            news.Section  = selectedSection;
            news.PostedOn = DateTime.Now;
            var tags = Mapper.Map <List <TagDTO> >(news.Tags);

            newsService.Update(news, tags);
            return(RedirectToAction("Index", "Home"));
        }
コード例 #8
0
 public static NewsEntity ToBll(NewsViewModel news)
 {
     if (news == null)
     {
         throw new ArgumentNullException(nameof(news));
     }
     return(new NewsEntity()
     {
         Id = news.Id,
         Content = news.Content,
         Image = news.Image,
         CreatorId = news.CreatorId,
         PublicationDate = news.PublicationDate,
         Title = news.Title
     });
 }
コード例 #9
0
ファイル: NewsManager.xaml.cs プロジェクト: jjg0519/OA
        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (dgNewsList.SelectedItem == null)
            {
                MessageWindow.Show("", "请先选择一条新闻,再进行删除!", MessageIcon.Error, MessageWindowType.Flow);

                return;
            }
            NewsViewModel item = (NewsViewModel)dgNewsList.SelectedItem;

            viewModel.CurrentEntity          = item;
            viewModel.CurrentEntity.ParentVM = viewModel;
            viewModel.CurrentEntity.DeleteEntity.Execute(null);

            // viewModel.Refresh();
        }
コード例 #10
0
        public async Task <IActionResult> Edit(NewsViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await this._newsService.Edit(model);

            if (!result.Success)
            {
                return(View(model));
            }

            return(RedirectToAction(nameof(Details), new { Id = model.Id }));
        }
コード例 #11
0
        public override ActionResult Index(NewsBlock currentBlock)
        {
            NewsContainer newsContainer = null;

            if (!ContentReference.IsNullOrEmpty(currentBlock.NewsContainer))
            {
                newsContainer = _contentLoader.Get <NewsContainer>(currentBlock.NewsContainer);
            }

            var model = new NewsViewModel
            {
                News = GetNews(newsContainer)
            };

            return(PartialView(model));
        }
コード例 #12
0
 public NewsPage(RootPage root)
 {
     try
     {
         InitializeComponent();
         _model = new NewsViewModel()
         {
             Root = root
         };
         Init();
     }
     catch (Exception ex)
     {
         new ExceptionHandler(TAG, ex);
     }
 }
コード例 #13
0
ファイル: NewsModel.cs プロジェクト: aleksanderbulakh/News
        public NewsViewModel Edit(Guid id)
        {
            var SelectedNew = new NewsViewModel();

            var AllNews = NewsProviderProperty.GetAllNews();

            foreach (var n in AllNews)
            {
                if (n.Id == id)
                {
                    SelectedNew = new NewsViewModel(n);
                }
            }

            return(SelectedNew);
        }
コード例 #14
0
        public void Add(NewsViewModel viewModel)
        {
            _repository.Add(new News
            {
                CreationDate = DateTime.Now,
                IsItDeleted  = false,
                Status       = true,
                SiteLanguage = viewModel.SiteLanguage,

                Title    = viewModel.Title,
                Content  = viewModel.Content,
                Image    = "/Areas/Login/Assets/images/" + viewModel.Image,
                Category = viewModel.Category,
                NewsType = viewModel.NewsType
            });
        }
コード例 #15
0
        public NewsViewModel GetTagsTitles(NewsViewModel viewModel)
        {
            var tags = unitOfWork.GetAll <Tag>();

            viewModel.TagsTitles = new List <string>();
            foreach (var tagId in viewModel.TagsIds)
            {
                var tag = tags.FirstOrDefault(x => x.Id == tagId);
                if (tag != null)
                {
                    viewModel.TagsTitles.Add(tag.Title);
                }
            }

            return(viewModel);
        }
コード例 #16
0
ファイル: NewsModel.cs プロジェクト: aleksanderbulakh/News
        public void Edit(NewsViewModel editedData)
        {
            var AllNews = NewsProviderProperty.GetAllNews();

            foreach (var n in AllNews)
            {
                if (n.Id == editedData.Id)
                {
                    n.Header    = editedData.Header;
                    n.Content   = editedData.Content;
                    n.IsVisible = editedData.IsVisible;
                }
            }

            NewsProviderProperty.SetAllNews(AllNews);
        }
コード例 #17
0
        public async Task <IActionResult> EditNews(int id)
        {
            var news = await _newsService.GetNewsAsync(id);

            var newsViewModel = new NewsViewModel
            {
                Title          = "Edit News",
                AddButtonTitle = "Save",
                RedirectUrl    = Url.Action("Index", "News"),
                NewsTitle      = news.NewsTitle,
                Id             = news.Id,
                Content        = news.Content
            };

            return(View(newsViewModel));
        }
コード例 #18
0
        public IActionResult AddNews(NewsViewModel model)
        {
            var newNews = new News
            {
                ID         = new Guid(),
                Article    = model.Article,
                Body       = model.Body,
                Source     = model.OriginSite,
                DatePosted = DateTime.Now
            };

            _context.News.Add(newNews);
            _context.SaveChanges();
            Log.Logger.Information($"Info|{DateTime.Now}|News {newNews.Article} were added|{newNews.ID}");
            return(View());
        }
コード例 #19
0
        public ActionResult Edit(NewsViewModel model)
        {
            var dbEntry = dbContext.News.Find(model.Id);

            if (dbEntry == null)
            {
                throw new Exception("Unknown entry requested.");
            }

            dbEntry.Extend(model);

            dbContext.Entry <News>(dbEntry).State = EntityState.Modified;
            dbContext.SaveChanges();

            return(View(dbEntry));
        }
コード例 #20
0
        public async Task <IActionResult> Create(NewsViewModel model)
        {
            if (model != null)
            {
                model.Organization = await GetOrgNameAsync();

                model.PubDate = DateTime.Now;

                db.Newses.Add(model);
                await db.SaveChangesAsync();

                return(View());
            }

            return(NotFound());
        }
コード例 #21
0
        public IActionResult Edit(int id, NewsViewModel viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                viewModel.Updated = DateTime.Now;
                newsService.Edit(viewModel);
                return(RedirectToAction("Index"));
            }

            PopPopulateLists(viewModel);
            return(View(viewModel));
        }
コード例 #22
0
        public IActionResult News(int id)
        {
            var dbNews = this.newsService.GetById(id);

            NewsViewModel viewModel = new NewsViewModel
            {
                Content    = dbNews.Content,
                CreatedOn  = dbNews.CreatedOn,
                Id         = dbNews.Id,
                PictureUrl = dbNews.PictureUrl,
                Title      = dbNews.Title,
                Views      = dbNews.TimesSeen,
            };

            return(this.View(viewModel));
        }
コード例 #23
0
ファイル: NewsService.cs プロジェクト: luuthi/DOANTONGHOP
 public void UpdateNews(NewsViewModel viewModel)
 {
     SqlDb_Ultis.ExeNonStored("Tbl_NewsUpDate",
                              "@Id", viewModel.Id,
                              "@Title", viewModel.Title,
                              "@Description", viewModel.Description,
                              "@Content", viewModel.Content,
                              "@Image", viewModel.Image,
                              "@Order", viewModel.Order,
                              "@CanComment", viewModel.CanComment,
                              "@Category", viewModel.Category,
                              "@Status", viewModel.Status,
                              "@GroupId", viewModel.GroupId,
                              "@Modifier", viewModel.Modifier,
                              "@ModifyDate", viewModel.ModifyDate);
 }
コード例 #24
0
ファイル: NewsController.cs プロジェクト: Ginkhust/Mobile
        public async Task<ActionResult> EditNews(string id)
        {
            try
            {
                ParseQuery<ParseObject> query = ParseObject.GetQuery("News");
                ParseObject news = await query.GetAsync(id);

                NewsViewModel _news = new NewsViewModel(news);

                return View(_news);
            }
            catch (ParseException pe)
            {
                return View();
            }
        }
コード例 #25
0
 public NewsListPage(NewsViewModel viewModel)
 {
     ViewModel           = viewModel;
     BindingContext      = ViewModel;
     ViewModel.OnClicked = new Command(() =>
     {
         //var page = new NewsPage(article.Url);
         //Navigation.PushAsync(page);
     });
     ViewModel.OnTap = (m) =>
     {
         var page = new NewsPage(m);
         Navigation.PushAsync(page);
     };
     InitializeComponent();
 }
コード例 #26
0
        private string UploadedFile(NewsViewModel model)
        {
            string uniqueFileName = null;

            if (model.ImageFile != null)
            {
                string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images", "NewsImages");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ImageFile.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.ImageFile.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
コード例 #27
0
        public NewsPage()
        {
            InitializeComponent();

            BindingContext = _vm = new NewsViewModel ();

            _vm.IsRefreshing = true;

            // For the auto scroll
            MessagingCenter.Subscribe<MessageItem>(this._vm, "ScrollTop", (sender) =>
            {
                // Scroll to the top of the collection view
                newsCollectionView.ScrollTo(0);
            });

        }
コード例 #28
0
ファイル: NewsService.cs プロジェクト: Meytol/NewsAgency
        public async Task <NewsPaginationSection> GetLastNewsByAuthorIdAsync(int quentity, int authorId, int page = 1)
        {
            var authorNewses = await FindBy(news => news.AuthorId == authorId)
                               .Include(news => news.Author)
                               .Include(news => news.NewsCategories)
                               .ThenInclude(newsCategory => newsCategory.Category)
                               .OrderByDescending(newsCategory => newsCategory.CreatedOn)
                               .Skip((page - 1) * quentity)
                               .Take(quentity)
                               .ToListAsync();

            var wholeNewsesQuentity = await FindBy(news => news.AuthorId == authorId).CountAsync();

            var numOfPages = (wholeNewsesQuentity / quentity);

            if (authorNewses.Count() % quentity > 0)
            {
                numOfPages++;
            }

            var authorNewsSetction = new NewsPaginationSection
            {
                NewsViewModels    = new List <NewsViewModel>(),
                CurrentPageNumber = page,
                NumberOfPages     = numOfPages
            };

            foreach (var authorNews in authorNewses)
            {
                var news = new NewsViewModel
                {
                    NewsTitle      = authorNews.Title,
                    NewsHeadLine   = authorNews.Headline,
                    ImageUrl       = authorNews.ImageUrl,
                    CategoryTitle  = authorNews.NewsCategories.FirstOrDefault(nc => nc.IsMain).Category.Title,
                    CategoryId     = authorNews.NewsCategories.FirstOrDefault(nc => nc.IsMain).Category.Id,
                    NewsId         = authorNews.Id,
                    CreatedOn      = authorNews.CreatedOn,
                    AuthorFullName = authorNews.Author.FullName,
                    AuthorId       = authorNews.AuthorId,
                };

                authorNewsSetction.NewsViewModels.Add(news);
            }

            return(authorNewsSetction);
        }
コード例 #29
0
        public async Task <IActionResult> CreateOrUpdate(string newsId)
        {
            NewsViewModel newsViewModel = new NewsViewModel();

            ViewBag.Tags = _uw._Context.Tags.Select(t => t.TagName).ToList();
            newsViewModel.NewsCategoriesViewModel = new NewsCategoriesViewModel(await _uw.CategoryRepository.GetAllCategoriesAsync(), null);
            if (newsId.HasValue())
            {
                var news = await(from n in _uw._Context.News
                                 join e in _uw._Context.NewsCategories on n.NewsId equals e.NewsId into nc
                                 from nct in nc.DefaultIfEmpty()
                                 join w in _uw._Context.NewsTags on n.NewsId equals w.NewsId into bc
                                 from bct in bc.DefaultIfEmpty()
                                 join t in _uw._Context.Tags on bct.TagId equals t.TagId into cg
                                 from cog in cg.DefaultIfEmpty()
                                 where (n.NewsId == newsId)
                                 select new NewsViewModel
                {
                    NewsId          = n.NewsId,
                    Title           = n.Title,
                    Abstract        = n.Abstract,
                    Description     = n.Description,
                    PublishDateTime = n.PublishDateTime,
                    IsPublish       = n.IsPublish,
                    ImageName       = n.ImageName,
                    IsInternal      = n.IsInternal,
                    IdOfCategories  = nct != null ? nct.CategoryId : "",
                    Url             = n.Url,
                    NameOfTags      = cog != null ? cog.TagName : "",
                }).ToListAsync();

                if (news != null)
                {
                    newsViewModel = _mapper.Map <NewsViewModel>(news.FirstOrDefault());
                    if (news.FirstOrDefault().PublishDateTime > DateTime.Now)
                    {
                        newsViewModel.FuturePublish      = true;
                        newsViewModel.PersianPublishDate = news.FirstOrDefault().PublishDateTime.ConvertMiladiToShamsi("yyyy/MM/dd");
                        newsViewModel.PersianPublishTime = news.FirstOrDefault().PublishDateTime.Value.TimeOfDay.ToString();
                    }
                    newsViewModel.NewsCategoriesViewModel = new NewsCategoriesViewModel(await _uw.CategoryRepository.GetAllCategoriesAsync(), news.Select(n => n.IdOfCategories).Distinct().ToArray());
                    newsViewModel.NameOfTags = news.Select(t => t.NameOfTags).Distinct().ToArray().CombineWith(',');
                }
            }

            return(View(newsViewModel));
        }
コード例 #30
0
        /// <summary>
        /// Вызывается перед отображением этой страницы во фрейме.
        /// </summary>
        /// <param name="e">Данные события, описывающие, каким образом была достигнута эта страница.
        /// Этот параметр обычно используется для настройки страницы.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;

            if (e.NavigationMode == NavigationMode.Back)
            {
                e = null;
            }


            bool internetAccess = NetworkInterface.GetIsNetworkAvailable();

            if (internetAccess)
            {
                if (e != null && e.Parameter != null)
                {
                    string[] param = (string[])e.Parameter;

                    newsVM      = new NewsViewModel(param);
                    DataContext = newsVM;
                    if (Settings.DeviceTypeDetectHelper.GetDeviceFormFactorType() == Settings.DeviceFormFactorType.Desktop)
                    {
                        ListView_News.Visibility  = Visibility.Collapsed;
                        GridView_News.ItemsSource = newsVM;
                        e = null;
                    }
                    else
                    {
                        GridView_News.Visibility  = Visibility.Collapsed;
                        ListView_News.ItemsSource = newsVM;
                        e = null;
                    }
                }
                else
                {
                    Frame.GoBack();
                }
            }
            else
            {
                var dialog = new MessageDialog("Проверьте соединение с интернетом");
                await dialog.ShowAsync();

                Frame.GoBack();
            }
        }
コード例 #31
0
        public async Task <List <NewsViewModel> > GetAllByChannel(Guid channelId)
        {
            var newsHeaderList = new List <NewsHeader>();

            using (var connection = new SqlConnection(this.connectionString))
            {
                var query     = "select n.id,n.Title, n.Published, n.Link from News n where n.ChannelId = @channelId order by n.Published desc";
                var queryData = new
                {
                    channelId = channelId
                };

                var queryResult = await connection.QueryAsync <NewsHeader>(query, queryData);

                newsHeaderList.AddRange(queryResult);
            }


            var account       = CloudStorageAccount.Parse(this.emulator);
            var serviceClient = account.CreateCloudBlobClient();
            var container     = serviceClient.GetContainerReference("rss");

            var sharedAccessBlobPolicy = new SharedAccessBlobPolicy
            {
                Permissions            = SharedAccessBlobPermissions.Read,
                SharedAccessStartTime  = DateTime.UtcNow,
                SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
            };

            var itemsToDownload = newsHeaderList.Select(x =>
            {
                var itemBlobUrl   = $"items/{channelId}/{x.Id.ToString()}.json";
                var blob          = container.GetBlobReference(itemBlobUrl);
                var sas           = blob.GetSharedAccessSignature(sharedAccessBlobPolicy);
                var newsViewModel = new NewsViewModel
                {
                    Id         = x.Id,
                    Title      = x.Title,
                    Published  = x.Published,
                    ContentUrl = blob.Uri + sas,
                    Link       = x.Link
                };
                return(newsViewModel);
            });

            return(itemsToDownload.ToList());
        }
コード例 #32
0
ファイル: NewsService.cs プロジェクト: SCDeveloper66/SC_Api
        public async Task <NewsViewModel> GetInfomationAsync()
        {
            var data = new NewsViewModel();

            data.message = new messageModel();
            try
            {
                var userId = JwtHelper.GetUserIdFromToken(HttpContext);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }
                using (var context = new StandardcanContext())
                {
                    var jsonData = JsonConvert.SerializeObject(new
                    {
                        emp_id = userId
                    });
                    SystemLog systemLog = new SystemLog()
                    {
                        module   = "api/News/GetInfomation",
                        data_log = jsonData
                    };
                    await _systemLogService.InsertSystemLogAsync(systemLog);

                    SqlParameter emp_id = new SqlParameter("emp_id", userId ?? "");
                    var          spData = context.SpMbProfileDefault.FromSqlRaw("sp_mb_profile_default @emp_id", emp_id).ToList();
                    foreach (var item in spData)
                    {
                        data.notification_count = item.notification_count;
                        data.sc_creadit         = item.sc_creadit;
                        data.profile_img        = item.profile_img;
                        data.profile_name       = item.profile_name;
                        data.profile_depart     = item.profile_depart;
                    }
                    data.message.status = "1";
                    data.message.msg    = "Success";
                }
            }
            catch (Exception ex)
            {
                data.message.status = "2";
                data.message.msg    = ex.Message;
            }
            return(data);
        }
コード例 #33
0
    public void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["id"] != null)
            {
                GetData(Request.QueryString["id"]);
            }
            else
            {
                GetData();
            }

        }

        NewsViewModel = new NewsViewModel();
    }
コード例 #34
0
        public ActionResult Edit(int id)
        {
            var temp = _context.News.FirstOrDefault(t => t.Id == id);

            NewsViewModel model = new NewsViewModel()
            {
                Country     = temp.Country,
                Description = temp.Description,
                Image       = temp.Image,
                Time        = temp.Time,
                Title       = temp.Title,
                Date        = temp.Date,
                Id          = temp.Id
            };

            return(View(model));
        }
コード例 #35
0
        public ActionResult Create(NewsViewModel news)
        {
            if (ModelState.IsValid)
            {
                var newsModel = Mapper.Map <News>(news);
                newsModel.CreatedOn = DateTime.Now;

                this.Data.News.Add(newsModel);
                this.Data.SaveChanges();

                this.Notify(GlobalConstants.AddNews, NotificationType.success);

                return(this.RedirectToAction("Details", "News", new { id = newsModel.Id }));
            }

            return(this.View(news));
        }
コード例 #36
0
 public ActionResult NewsEdit(NewsViewModel model)
 {
     if (ModelState.IsValid)
     {
         using (var c = new WebDbContext())
         {
             var oPost = c.News.Find(model.Id);
             oPost.HtmlContent = model.HtmlContent;
             oPost.Image = model.ImageFile;
             oPost.Title = model.Title;
             oPost.Date = DateTime.Now;
             c.SaveChanges();
         }
         GameCache.ReCache(false, false, true);
         return RedirectToAction("NewsList");
     }
     return View(model);
 }
コード例 #37
0
        public ActionResult News_Destroy([DataSourceRequest]DataSourceRequest request, NewsViewModel newsToDelete)
        {
            if (ModelState.IsValid)
            {
                var entity = new News
                {
                    Id = newsToDelete.Id,
                    Title = newsToDelete.Title,
                    Content = newsToDelete.Content,
                    DateCreated = newsToDelete.DateCreated,
                    CategoryId = newsToDelete.CategoryId
                };

                this.news.Delete(entity.Id);
            }

            return Json(new[] { newsToDelete }.ToDataSourceResult(request, ModelState));
        }
コード例 #38
0
        public ActionResult News_Create([DataSourceRequest]DataSourceRequest request, NewsViewModel newsToadd)
        {
            if (ModelState.IsValid)
            {
                var entity = new News
                {
                    Title = newsToadd.Title,
                    Content = newsToadd.Content,
                    DateCreated = newsToadd.DateCreated,
                    CategoryId = newsToadd.CategoryId,
                    AuthorId = this.CurrentUser.Id
                };

                this.news.AddNews(entity);
                newsToadd.Id = entity.Id;
            }

            return Json(new[] { newsToadd }.ToDataSourceResult(request, ModelState));
        }
コード例 #39
0
ファイル: NewsController.cs プロジェクト: Ginkhust/Mobile
        public async Task<ActionResult> EditNews(string id, NewsViewModel n)
        {
            try
            {
                ParseQuery<ParseObject> query = ParseObject.GetQuery("News");
                ParseObject news = await query.GetAsync(n.newsId);

                news["title"] = n.title;
                news["content"] = n.content;
                news["imageUrl"] = n.imageUrl;
                await news.SaveAsync();
                return RedirectToAction("NewsList");

            }
            catch (ParseException pe)
            {
                return View();
            }
        }
コード例 #40
0
ファイル: NewsController.cs プロジェクト: kduytoan1994/Mobile
        public async Task<ActionResult> EditNews(string id)
        {
            try
            {
                ParseQuery<ParseObject> query = ParseObject.GetQuery("News");
                ParseObject news = await query.GetAsync(id);

                NewsViewModel _news = new NewsViewModel();
                _news.newsId = id;
                _news.title = news.Get<string>("title");
                _news.content = news.Get<string>("content");

                return View(_news);
            }
            catch (ParseException pe)
            {
                return View();
            }
        }
コード例 #41
0
 public ActionResult NewsCreate(NewsViewModel model)
 {
     if (ModelState.IsValid)
     {
         NewsPost npost = new NewsPost();
         npost.Date = DateTime.Now;
         npost.Title = model.Title;
         npost.Image = model.ImageFile;
         npost.Shares = 0;
         npost.HtmlContent = model.HtmlContent;
         npost.Author = "Admin";
         using (var c = new WebDbContext())
         {
             c.News.Add(npost);
             c.SaveChanges();
         }
         GameCache.ReCache(false, false, true);
     }
     
     return RedirectToAction("NewsList","Admin");
 }
コード例 #42
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     NewsModel = NavigationServices.CurrentViewModel as NewsViewModel;
     if (e.NavigationMode == NavigationMode.New && NavigationContext.QueryString.ContainsKey("id"))
     {
         string id = NavigationContext.QueryString["id"];
         if (!String.IsNullOrEmpty(id))
         {
             _isDeepLink = true;
             NewsModel = new NewsViewModel();
             NavigationServices.CurrentViewModel = NewsModel;
             NewsModel.LoadItem(id);
         }
     }
     if (NewsModel != null)
     {
         NewsModel.ViewType = ViewTypes.Detail;
     }
     DataContext = NewsModel;
     base.OnNavigatedTo(e);
 }
コード例 #43
0
ファイル: NewsController.cs プロジェクト: Ginkhust/Mobile
        public async Task<ActionResult> NewsList()
        {
            try
            {
                ParseQuery<ParseObject> query = ParseObject.GetQuery("News");
                IEnumerable<ParseObject> newsList = await query.FindAsync();

                List<NewsViewModel> _newsList = new List<NewsViewModel>();

                foreach (ParseObject n in newsList)
                {
                    NewsViewModel news = new NewsViewModel(n);
                    _newsList.Add(news);
                }
                return View(_newsList);

            }
            catch (ParseException pe)
            {
                return View();
            }
        }
コード例 #44
0
        public ActionResult News_Update([DataSourceRequest]DataSourceRequest request, NewsViewModel newsToUpdate)
        {
            if (ModelState.IsValid)
            {
                var entity = new News
                {
                    Id = newsToUpdate.Id,
                    Title = newsToUpdate.Title,
                    Content = newsToUpdate.Content,
                    DateCreated = newsToUpdate.DateCreated,
                    CategoryId = newsToUpdate.CategoryId,
                    AuthorId = CurrentUser.Id
                };

                this.news.Update(entity);
            }

            return Json(new[] { newsToUpdate }.ToDataSourceResult(request, ModelState));
        }
コード例 #45
0
ファイル: NewsController.cs プロジェクト: jonantoine/gcr
        //
        // GET: /News/Create
        public ActionResult Create()
        {
            ViewBag.PageTitle = "Create New Article";
            ViewBag.Title = "Create Article";

            var model = new NewsViewModel();

            return View("CreateEdit", model);
        }
コード例 #46
0
ファイル: NewsController.cs プロジェクト: jonantoine/gcr
        public ActionResult Edit(int id, NewsViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var article = newsService.GetById(id);
                    article = NewsViewModel.ToModel(model, article);
                    newsService.SaveNews(article);

                    return RedirectToAction("Admin");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex);
                this.LogError(ex);
            }

            ViewBag.PageTitle = "Edit Article";
            ViewBag.Title = "Edit Article";
            return View("CreateEdit", model);
        }