public async Task <ActionResult <List <PostAndKeyword> > > GetWriterPost([FromBody] UsernameDTO usernameDTO) { List <TblPosts> listNotHaving = getListPostNotInHavingPosts(usernameDTO.Username); List <TblPosts> listResponse = new List <TblPosts>(); List <PostAndKeyword> listPostAndKeywordResponse = new List <PostAndKeyword>(); for (int i = 0; i < listNotHaving.Count; i++) { TblPosts currentPost = listNotHaving[i]; if (currentPost.PostType.Equals("Writer")) { listResponse.Add(currentPost); PostAndKeyword postAndKeyword = new PostAndKeyword(); postAndKeyword.Id = currentPost.Id; postAndKeyword.Title = currentPost.Title; postAndKeyword.Description = currentPost.Description; postAndKeyword.CharacterLimit = currentPost.CharacterLimit; postAndKeyword.Amount = currentPost.Amount; postAndKeyword.PostType = currentPost.PostType; postAndKeyword.RelatedDocument = currentPost.RelatedDocument; postAndKeyword.IsPublic = currentPost.IsPublic; postAndKeyword.CreatedDate = currentPost.CreatedDate; postAndKeyword.Status = currentPost.Status; postAndKeyword.listKeywords = findListKeyByPostId(currentPost.Id); listPostAndKeywordResponse.Add(postAndKeyword); } } return(listPostAndKeywordResponse); }
public async Task <IActionResult> PutTblPosts(int id, TblPosts tblPosts) { if (id != tblPosts.Id) { return(BadRequest()); } _context.Entry(tblPosts).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblPostsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <TransactionHistory> > createTransactionHistory(TransactionHistoryDTO dto) { TransactionHistory transactionHistory = new TransactionHistory(); //truyền xuống dto có 4 field: postid, giver, receiver, transactiondate transactionHistory.PostId = dto.PostId; transactionHistory.Giver = dto.Giver; transactionHistory.Receiver = dto.Receiver; transactionHistory.TransactionDate = DateTime.Now; TblUsersHavingPosts usersHavingPosts = _context.TblUsersHavingPosts.FromSqlRaw("select * from TblUsersHavingPosts where " + "Username = {0} and PostId = {1}", dto.Receiver, dto.PostId).First(); //tìm bài post của freelancer đã hoàn thành usersHavingPosts.Status = "finished"; //set status = finished _context.Entry(usersHavingPosts).State = EntityState.Modified; TblPosts post = _context.TblPosts.FromSqlRaw("select * from TblPosts where " + "Id = {0}", dto.PostId).First(); //tìm bài post trong TblPosts post.IsPublic = false; //ko public bài post nữa _context.Entry(post).State = EntityState.Modified; Int64 postAmount = _context.TblPosts.Find(dto.PostId).Amount; //lấy ra amount của bài post transactionHistory.Amount = postAmount; //lưu vào transaction history _context.TransactionHistory.Add(transactionHistory); //add transaction dto vào table TransactionHistory TblUsers company = _context.TblUsers.Find(dto.Giver); //tìm ra company company.Amount -= postAmount; //lấy amount hiện tại của company - amount của bài post đã finished _context.Entry(company).State = EntityState.Modified; TblUsers freelancer = _context.TblUsers.Find(dto.Receiver); //tìm ra freelancer freelancer.Amount += postAmount; //lấy amount hiện tại của freelancer + amount của bài post đã finished _context.Entry(freelancer).State = EntityState.Modified; await _context.SaveChangesAsync(); return(transactionHistory); }
//Hàm này trả về index trong 1 list private int findIndexByIdPodst(int id, List <TblPosts> listPostResponse) { for (int i = 0; i < listPostResponse.Count; i++) { TblPosts currentPost = listPostResponse[i]; if (currentPost.Id == id) { return(i); } } return(-1); }
public async Task <ActionResult <List <TblPosts> > > GetCompanyPosts(UsernameDTO usernameDTO) { List <TblPosts> listCompanyPosts = new List <TblPosts>(); List <TblUsersHavingPosts> listCreatedPosts = _context.TblUsersHavingPosts .FromSqlRaw("select PostId from tblUsersHavingPosts where Username = {0} and Status = 'created'", usernameDTO.Username) .ToList <TblUsersHavingPosts>(); for (int i = 0; i < listCreatedPosts.Count; i++) { TblUsersHavingPosts curCreatedPost = listCreatedPosts[i]; TblPosts companyPost = _context.TblPosts.Find(curCreatedPost); listCompanyPosts.Add(companyPost); } return(listCompanyPosts); }
//Hàm này trả về list Post không có trong tblUserHavingPosts private List <TblPosts> getListPostNotInHavingPosts(string username) { List <TblUsersHavingPosts> listHavingPosts = _context.TblUsersHavingPosts .FromSqlRaw("select * from TblUsersHavingPosts") .ToList <TblUsersHavingPosts>(); List <TblPosts> listPost = _context.TblPosts .FromSqlRaw("select * from TblPosts where IsPublic = 1") .ToList <TblPosts>(); List <int> listPostId = new List <int>(); List <TblPosts> listPostResponse = listPost; //Lấy ra listPostId for (int i = 0; i < listHavingPosts.Count; i++) { TblUsersHavingPosts current = listHavingPosts[i]; if (username.Equals(current.Username)) { listPostId.Add(current.PostId); } } for (int i = 0; i < listPostId.Count; i++) { int currentId = listPostId[i]; for (int j = 0; j < listPostResponse.Count; j++) { TblPosts currentPost = listPostResponse[j]; if (currentId == currentPost.Id) { int index = findIndexByIdPodst(currentPost.Id, listPostResponse); if (index != -1) { listPostResponse.RemoveAt(index); break; } } } } return(listPostResponse); }
public async Task <ActionResult <List <PostAndKeyword> > > GetAcceptedPosts(UsernameDTO usernameDTO) { List <TblUsersHavingPosts> listRequested = _context.TblUsersHavingPosts .FromSqlRaw("select * from tblUsersHavingPosts where Username = {0} and Status = 'requested'", usernameDTO.Username) .ToList <TblUsersHavingPosts>(); List <TblPosts> listAccepted = _context.TblPosts .FromSqlRaw("select * from tblPosts where Id in " + "(select PostId from tblUsersHavingPosts where Username = {0} and Status = 'accepted')", usernameDTO.Username) .ToList <TblPosts>(); List <TblPosts> listResponse = new List <TblPosts>(); List <PostAndKeyword> listPostAndKeywordResponse = new List <PostAndKeyword>(); if (listAccepted.Count > 0) { for (int i = 0; i < listAccepted.Count; i++) { TblPosts currentPost = listAccepted[i]; if (currentPost.PostType.Equals("Writer") || currentPost.PostType.Equals("Design") || currentPost.PostType.Equals("Translate")) { listResponse.Add(currentPost); PostAndKeyword postAndKeyword = new PostAndKeyword(); postAndKeyword.Id = currentPost.Id; postAndKeyword.Title = currentPost.Title; postAndKeyword.Description = currentPost.Description; postAndKeyword.CharacterLimit = currentPost.CharacterLimit; postAndKeyword.Amount = currentPost.Amount; postAndKeyword.PostType = currentPost.PostType; postAndKeyword.RelatedDocument = currentPost.RelatedDocument; postAndKeyword.IsPublic = currentPost.IsPublic; postAndKeyword.CreatedDate = currentPost.CreatedDate; postAndKeyword.Status = currentPost.Status; postAndKeyword.listKeywords = findListKeyByPostId(currentPost.Id); listPostAndKeywordResponse.Add(postAndKeyword); } } _context.TblUsersHavingPosts.RemoveRange(listRequested); await _context.SaveChangesAsync(); return(listPostAndKeywordResponse); } return(null); }
public async Task <ActionResult <TblPosts> > PostTblPosts(TblPosts tblPosts) { _context.TblPosts.Add(tblPosts); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (TblPostsExists(tblPosts.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetTblPosts", new { id = tblPosts.Id }, tblPosts)); }
public IActionResult getTotalPostToChart() { int nWriter = 0; int nDesign = 0; int nTranslate = 0; PostChartDTO postChartDTO = new PostChartDTO(); List <TblPosts> listPost = _context.TblPosts.ToList <TblPosts>(); for (int i = 0; i < listPost.Count; i++) { TblPosts currentPost = listPost[i]; if (currentPost.IsPublic == true) { if (currentPost.PostType.Equals("Writer")) { nWriter++; } if (currentPost.PostType.Equals("Design")) { nDesign++; } if (currentPost.PostType.Equals("Translate")) { nTranslate++; } } } postChartDTO.NumberWriter = nWriter; postChartDTO.NumberDesign = nDesign; postChartDTO.NumberTranslate = nTranslate; return(Ok(postChartDTO)); }
public PostCategoriesUpdatedEvent(TblPosts post, List <int> categoriesList) { Post = post; CategoriesList = categoriesList; }
public virtual PostModel PreparePostModel(TblPosts post, TblUsers currentUser, UrlHelper url) { var result = post.Adapt <PostModel>(); result.Title = post.GetLocalized(p => p.Title); result.PageTitle = post.GetLocalized(p => p.PageTitle); result.MetaDescription = post.GetLocalized(p => p.MetaDescription); result.MetaKeyWords = post.GetLocalized(p => p.MetaKeyWords); var likesCount = _userLikesService.GetNumberOfLikes(post.Id); result.NumberOfLikes = likesCount; result.LastUpdate = post.LastUpDate ?? post.PublishDate; result.Categories = post.Categories .Select(p => new PostCategoriesModel() { Id = p.Id, CategoryName = p.GetLocalized(x => x.CategoryName), Slug = p.Slug, CategoryUrl = post.PostType == PostType.BlogPost ? url.Action("FilterByCategory", "Blog", new { slug = p.Slug }) : url.Action("FilterByCategory", "Product", new { slug = p.Slug }) }) .ToList(); result.TagsList = post.Tags .Select(p => new Tuple <int, string>(p.Id, p.GetLocalized(x => x.Tag))) .ToList(); result.LikeWishlistButtonsModel = new LikeWishlistButtonsModel() { PostId = post.Id, AlreadyAddedToWishlist = _userWishlistService.UserAddedThisPostToWishlist(post.Id, currentUser?.Id), AlreadyLiked = _userLikesService.UserLikedThisPost(post.Id, currentUser?.Id) }; result.Images.Clear(); foreach (var img in post.Images.OrderBy(p => p.DisplayOrder)) { result.Images.Add(new PostImagesModel() { Title = img.GetLocalized(p => p.Title) ?? result.PageTitle, Alt = img.GetLocalized(p => p.Alt) ?? result.Title, ImageUrl = img.GetLocalized(p => p.ImageUrl), DisplayOrder = img.DisplayOrder }); } result.Descriptions.Clear(); foreach (var desc in post.Descriptions.OrderBy(p => p.DisplayOrder)) { var description = desc.GetLocalized(x => x.HtmlDescription); result.Descriptions.Add(new PostDescriptionsModel() { Description = description, Title = desc.GetLocalized(x => x.Title), IsRtl = description.StripHtml().IsRtlLanguage() }); } result.Attributes.Clear(); foreach (var attr in post.Attributes) { result.Attributes.Add(new PostAttributesModel() { Type = attr.PostAttribute.AttributeType, Name = attr.PostAttribute.GetLocalized(p => p.Name), Value = attr.PostAttribute.AttributeType == PostAttributeType.Option ? attr.AttributeOption.GetLocalized(p => p.Name) : attr.GetLocalized(p => p.Value), DisplayOrder = attr.DisplayOrder }); } if (post.PostType == PostType.BlogPost) { result.PostUrl = new Uri(url.Action("Post", "Blog", new { slug = post.Slug }, _httpContext.Request.Url.Scheme)).ToString(); } else if (post.PostType == PostType.Product) { result.PostUrl = new Uri(url.Action("Index", "Product", new { slug = post.Slug }, _httpContext.Request.Url.Scheme)).ToString(); } else { result.PostUrl = new Uri(url.Action("Index", "Search", new SearchTermModel() { PostType = null, OrderBy = SearchResultSortType.Score, SearchPlace = SearchPlace.Title, Query = post.Title }, _httpContext.Request.Url.Scheme)).ToString(); } return(result); }
public PostTagsUpdatedEvent(TblPosts post, List <string> tagsList) { Post = post; TagsList = tagsList; }
protected virtual Document MapPost(TblPosts post, TblLanguages language, PostType?postType) { var title = post.GetLocalized(p => p.Title, language.Id); var descriptions = post.Descriptions.Where(p => p.AddToSearchEngineIndexes).Aggregate("", (current, description) => current + description.GetLocalized(p => p.HtmlDescription, language.Id)?.ConvertHtmlToText() + Environment.NewLine + Environment.NewLine); var tags = post.Tags.Aggregate("", (current, tag) => current + tag.GetLocalized(p => p.Tag, language.Id) + ", "); var categories = post.Categories.Aggregate("", (current, cat) => current + (cat.Id + " , ")); var keyWords = post.GetLocalized(p => p.MetaKeyWords, language.Id); var document = new Document(); document.Add(new Field("ID", post.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); document.Add(new Field("PostType", postType?.ToString() ?? "", Field.Store.YES, Field.Index.NOT_ANALYZED)); document.Add(new Field("LanguageId", language.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); document.Add(new Field("LanguageCode", language.IsoCode, Field.Store.YES, Field.Index.NOT_ANALYZED)); document.Add(new Field("PublishDate", DateTools.DateToString(post.PublishDate, DateTools.Resolution.SECOND), Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field("LastUpDate", DateTools.DateToString(post.LastUpDate ?? post.PublishDate, DateTools.Resolution.SECOND), Field.Store.YES, Field.Index.ANALYZED)); var numberOfViewField = new NumericField("NumberOfVisit", Field.Store.YES, true); numberOfViewField.SetIntValue(post.NumberOfViews); document.Add(numberOfViewField); if (!string.IsNullOrEmpty(title)) { var titleField = new Field("Title", title, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS) { Boost = 100 }; document.Add(titleField); } if (!string.IsNullOrWhiteSpace(descriptions.Replace(Environment.NewLine, ""))) { var descriptionField = new Field("Description", descriptions, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS) { Boost = 50 }; document.Add(descriptionField); } if (!string.IsNullOrWhiteSpace(tags.Replace(", ", ""))) { var tagField = new Field("Tags", tags, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS) { Boost = 50 }; document.Add(tagField); } var categoriesField = new Field("Categories", categories, Field.Store.YES, Field.Index.ANALYZED); document.Add(categoriesField); if (!string.IsNullOrEmpty(keyWords)) { var keywordsField = new Field("Keywords", keyWords, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS) { Boost = 50 }; document.Add(keywordsField); } return(document); }