public async Task <List <DtoArticle> > GetArticlesByAuthorId(int id) { var dtos = new List <DtoArticle>(); var articles = await pc.Article.Where(a => a.AuthorId.ToString().Contains(id.ToString())).ToListAsync(); foreach (var article in articles) { var intid = (int)article.AuthorId; var dtoauthor = await _daoAuthor.Find(intid); var dto = new DtoArticle { ArticleId = article.ArticleId, AuthorId = article.AuthorId, AuthorName = dtoauthor.LastName + ", " + dtoauthor.FirstName, Title = article.Title, Body = article.Body }; dtos.Add(dto); } return(dtos); }
public List <DtoArticle> GetArticlesByAuthorId(int id) { var dtoarticles = new List <DtoArticle>(); using (var client = new HttpClient()) { var uri = new Uri("http://localhost/WebAPI/api/article/GetArticlesByAuthorId?id=" + id); var response = client.GetAsync(uri).Result; if (!response.IsSuccessStatusCode) { throw new Exception(response.ToString()); } var responseContent = response.Content; var responseString = responseContent.ReadAsStringAsync().Result; dynamic articles = JArray.Parse(responseString) as JArray; foreach (var obj in articles) { DtoArticle dto = obj.ToObject <DtoArticle>(); dtoarticles.Add(dto); } } return(dtoarticles); }
public void Add(ArticleVM.Article article) { var dto = new DtoArticle { AuthorId = (int)article.AuthorId, Title = article.Title, Body = article.Body }; svc.Add(dto); }
public async Task Add(DtoArticle dto) { var article = new Models.Article { AuthorId = dto.AuthorId, Title = dto.Title, Body = dto.Body }; pc.Article.Add(article); await pc.SaveChangesAsync(); }
public void Add(DtoArticle dto) { var article = new Models.Article { AuthorId = dto.AuthorId, Title = dto.Title, Body = dto.Body }; pc.Article.Add(article); pc.SaveChanges(); }
public void Update(ArticleVM.Article article) { var dto = new DtoArticle { ArticleId = article.ArticleId, AuthorId = article.AuthorId, Title = article.Title, Body = article.Body }; svc.Update(dto); }
public async Task Update(DtoArticle dto) { var article = new Article { ArticleId = dto.ArticleId, AuthorId = dto.AuthorId, Title = dto.Title, Body = dto.Body }; pc.Entry(article).State = EntityState.Modified; await pc.SaveChangesAsync(); }
public void Update(DtoArticle dto) { var article = new Article { ArticleId = dto.ArticleId, AuthorId = dto.AuthorId, Title = dto.Title, Body = dto.Body }; pc.Entry(article).State = EntityState.Modified; pc.SaveChanges(false); }
public async Task <DtoArticle> Find(int id) { var dto = new DtoArticle(); var article = await pc.Article.FindAsync(id); if (article != null) { dto.ArticleId = article.ArticleId; dto.AuthorId = article.AuthorId; dto.Title = article.Title; dto.Body = article.Body; } else { throw new Exception($"Article with ID = {id} was not found."); } return(dto); }
public DtoArticle Find(int id) { var dto = new DtoArticle(); var article = pc.Article.AsNoTracking().SingleOrDefault(a => a.ArticleId == id); if (article != null) { dto.ArticleId = article.ArticleId; dto.AuthorId = article.AuthorId; dto.Title = article.Title; dto.Body = article.Body; } else { throw new Exception($"Article with ID = {id} was not found."); } return(dto); }
public void Add(DtoArticle dto) { using (var client = new HttpClient { BaseAddress = new Uri("http://localhost") }) { string serailizeddto = JsonConvert.SerializeObject(dto); var inputMessage = new HttpRequestMessage { Content = new StringContent(serailizeddto, Encoding.UTF8, "application/json") }; inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage message = client.PostAsync("WebAPI/api/article/Add", inputMessage.Content).Result; if (!message.IsSuccessStatusCode) { throw new Exception(message.ToString()); } } }
public async Task Update(DtoArticle dto) { await dao.Update(dto); }
public async Task Add(DtoArticle dto) { await dao.Add(dto); }
public DtoArticle GetById(int id) { int nextId = 0; string nextTitle = ""; string nextLinkTitle = ""; int previousId = 0; string previousTitle = ""; string previousLinkTitle = ""; var previous = dc.Articles.Where(c => c.Id < id).OrderByDescending(c => c.Id).Take(1).FirstOrDefault(); previousId = previous == null ? 0 : previous.Id; previousLinkTitle = previous == null ? "" : previous.Title.LinkReplace(); previousTitle = previous == null ? "" : previous.Title; var next = dc.Articles.Where(c => c.Id > id).Take(1).FirstOrDefault(); nextId = next == null ? 0 : next.Id; nextLinkTitle = next == null ? "" : next.Title.LinkReplace(); nextTitle = next == null ? "" : next.Title; var data = (from a in dc.Articles join c in dc.Categories on a.CategoryId equals c.Id where a.Id == id select new { Id = a.Id, CategoryId = c.Id, CategoryName = c.Name, Introduction = a.Introduction, Title = a.Title, Img = a.Img, Body = a.Body, Type = a.Type, Date = a.CreatedDate, ArticleTags = a.ArticleTags }).FirstOrDefault(); var article = new DtoArticle(); if (article != null) { article.Id = data.Id; article.CategoryId = data.CategoryId; article.CategoryName = data.CategoryName; article.CategoryLinkName = data.CategoryName.LinkReplace(); article.Introduction = data.Introduction; article.Title = data.Title; article.Img = "data:image/png;base64," + Convert.ToBase64String(data.Img); article.Body = data.Body; article.Type = data.Type; article.CreatedDate = data.Date; article.Tags = dc.Tags.Where(c => data.ArticleTags.Any(t => t.TagId == c.Id) && c.Active == true).Select(c => new DtoTag { Id = c.Id, Name = c.Name, LinkName = c.Name.LinkReplace(), Active = c.Active }).ToList(); article.NextId = nextId; article.NextTitle = nextTitle; article.NextLinkTitle = nextLinkTitle; article.PreviousId = previousId; article.PreviousTitle = previousTitle; article.PreviousLinkTitle = previousLinkTitle; } return(article); }