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(); } }
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; }
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); } }
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); }
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())); } }
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)); }
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")); }
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 }); }
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(); }
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 })); }
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)); }
public NewsPage(RootPage root) { try { InitializeComponent(); _model = new NewsViewModel() { Root = root }; Init(); } catch (Exception ex) { new ExceptionHandler(TAG, ex); } }
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); }
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 }); }
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); }
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); }
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)); }
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()); }
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)); }
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()); }
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)); }
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)); }
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); }
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(); } }
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(); }
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); }
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); }); }
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); }
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)); }
/// <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(); } }
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()); }
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); }
public void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["id"] != null) { GetData(Request.QueryString["id"]); } else { GetData(); } } NewsViewModel = new NewsViewModel(); }
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)); }
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)); }
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); }
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)); }
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)); }
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(); } }
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(); } }
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"); }
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); }
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(); } }
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)); }
// // GET: /News/Create public ActionResult Create() { ViewBag.PageTitle = "Create New Article"; ViewBag.Title = "Create Article"; var model = new NewsViewModel(); return View("CreateEdit", model); }
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); }