public async Task <IViewComponentResult> InvokeAsync(PostView post) { List <Tag> tags = await this.tagService.GetTagsByPost(post); PostItemViewModel model = new PostItemViewModel(post, tags); return(View(model)); }
public ActionResult Index(int id) { var post = _postRepository.GetByID(id); var postTags = _tagRepository.GetAllPostTags().Where(a => a.PostId == post.PostId); var tags = new List <string>(); if (postTags.Any()) { foreach (var tag in postTags) { var t = _tagRepository.GetByID(tag.TagId); if (t != null) { tags.Add(t.Text.Replace("#", "")); } } } var media = _mediaRepository.GetByID(post.MediaId); var location = _locationRepository.GetByID(post.LocationId); var votes = _voteRepository.GetAll().Where(a => a.PostId == post.PostId); var user = _userRepository.GetById(post.UserId); var userMedia = _mediaRepository.GetByID(user.MediaId); string joined = string.Join(", ", tags); joined = joined.Replace("#", ""); var model = new PostItemViewModel { Post = post, Tags = joined, Media = media, Location = location, Likes = votes.Count(a => a.VoteCategoryId == 1), Dislikes = votes.Count(a => a.VoteCategoryId == 2), Username = user.UserName, UserProfileImage = $"https://{userMedia.MediaUrl}", Image = $"https://{media.MediaUrl.Replace(".mp4", ".jpg")}", Created = TimeAgo(post.CreatedDate) }; return(View(model)); }
public ActionResult PostItemForSale(Items_for_sale item) { try { string extension = Path.GetExtension(item.ImageFile.FileName); if (item.ImageFile != null) { string filename = Path.GetFileNameWithoutExtension(item.ImageFile.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; item.item_image_path = "~/UploadedPictures/Items_Pictures/" + filename; filename = Path.Combine(Server.MapPath("~/UploadedPictures/Items_Pictures/"), filename); item.ImageFile.SaveAs(filename); } else { var types = Db.Item_type.ToList(); Items_for_sale mItem = new Items_for_sale(); mItem.item_Types = types; PostItemViewModel model = new PostItemViewModel { User = (User)Session["user"], Item = mItem }; return(View(model)); } sale newSale = new sale(); sale added = Db.sales.Add(newSale); User user = (User)Session["user"]; item.user_id = user.user_id; item.availability = true; item.sales_id = added.sales_id; item.date_added = DateTime.UtcNow.Date; Db.Items_for_sale.Add(item); Db.SaveChanges(); ModelState.Clear(); return(RedirectToAction("UserDashboard", "User")); } catch (Exception e) { var types = Db.Item_type.ToList(); Items_for_sale mItem = new Items_for_sale(); mItem.item_Types = types; PostItemViewModel model = new PostItemViewModel { User = (User)Session["user"], Item = mItem }; return(View(model)); } }
// GET: ItemForSale/Edit/5 public ActionResult Edit(int id) { var types = Db.Item_type.ToList(); Items_for_sale mItem = Db.Items_for_sale.Single(i => i.item_id == id); mItem.item_Types = types; PostItemViewModel model = new PostItemViewModel { User = (User)Session["user"], Item = mItem }; return(View(model)); }
private async Task DoLoadNextChunkAsync(object param) { if (InProgress) { return; } InProgress = true; var dispatcher = Windows.UI.Xaml.Window.Current.Dispatcher; ThreadPool.RunAsync(async(a) => { var posts = await _repositoryService.GetPostsAsync(_displayedPosts, DOWNLOAD_CHUNK_SIZE, true); dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (Posts.Last() is LoadNextListItemViewModel) { var last = Posts.Last(x => x is LoadNextListItemViewModel); if (last != null) { Posts.Remove(last); } } if (posts != null) { foreach (var post in posts) { PostItemViewModel vm = null; vm = PostItemVMFactory.CreateViewModel(post); if (vm != null) { Posts.Add(vm); } } _displayedPosts += posts.Count; if (_displayedPosts < _repositoryService.TotalNumberOfPosts) { Posts.Add(new LoadNextListItemViewModel(_resourceLoader.GetString("DownloadingPosts"), this)); } } InProgress = false; UpdateBindedProperties(); }); }); }
// GET: ItemForSale/Create public ActionResult PostItemForSale() { if (Session["UserId"] != null) { var types = Db.Item_type.ToList(); Items_for_sale item = new Items_for_sale(); item.item_Types = types; PostItemViewModel model = new PostItemViewModel { User = (User)Session["user"], Item = item }; return(View(model)); ; } return(RedirectToAction("Login", "User")); }
public ActionResult Edit(int id, Items_for_sale item) { Items_for_sale myItem = Db.Items_for_sale.Single(i => i.item_id == id); try { if (item.ImageFile != null) { string filename = Path.GetFileNameWithoutExtension(item.ImageFile.FileName); string extension = Path.GetExtension(item.ImageFile.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; myItem.item_image_path = "~/UploadedPictures/Items_Pictures/" + filename; filename = Path.Combine(Server.MapPath("~/UploadedPictures/Items_Pictures/"), filename); item.ImageFile.SaveAs(filename); } myItem.availability = item.availability; myItem.item_name = item.item_name; myItem.item_description = item.item_description; myItem.item_type_id = item.item_type_id; myItem.price_per_item = item.price_per_item; Db.SaveChanges(); ModelState.Clear(); return(RedirectToAction("FindItemForSale", "ItemForSale")); } catch (Exception e) { var types = Db.Item_type.ToList(); Items_for_sale mItem = new Items_for_sale(); mItem.item_Types = types; PostItemViewModel model = new PostItemViewModel { User = (User)Session["user"], Item = mItem }; return(View(model)); } }
private async Task LoadPosts(int start, int number) { var posts = await _repositoryService.GetPostsAsync(start, number, true); if (posts != null) { foreach (var post in posts) { PostItemViewModel vm = null; vm = PostItemVMFactory.CreateViewModel(post); if (vm != null) { Posts.Add(vm); } } _displayedPosts = posts.Count; if (_displayedPosts < _repositoryService.TotalNumberOfPosts) { Posts.Add(new LoadNextListItemViewModel(_resourceLoader.GetString("DownloadingPosts"), this)); } UpdateBindedProperties(); } }
public PostItem(Post post) { InitializeComponent(); BindingContext = new PostItemViewModel(post); }
public PostItemControl() { InitializeComponent(); viewModel = new PostItemViewModel(); this.DataContext = viewModel; }