// GET: Blog public ActionResult Blog() { BlogRepository blogRepository = new BlogRepository(); BlogPhotoRepository blogPhotoRepository = new BlogPhotoRepository(); BlogCommentRepository blogCommentRepository = new BlogCommentRepository(); UserRepository userRepository = new UserRepository(); List <BlogViewModel> blogView = new List <BlogViewModel>(); var blogresult = blogRepository.GetAll(); var blogphotoresult = blogPhotoRepository.GetAll(); var blogcommentresult = blogCommentRepository.GetAll(); foreach (var item in blogresult) { blogView.Add(new BlogViewModel { Id = item.Id, Content = item.Content, Star = item.Star, Title = item.Title, RegisterDate = item.RegisterDate, UserId = item.UserId, Users = userRepository.GetById(item.UserId), }); } foreach (var item in blogphotoresult) { blogView.ForEach(x => x.Photo = item.Photo); } return(View(blogView)); }
// GET: Home public ActionResult Index() { JsonData jsondot = new JsonData(); string json = jsondot.data; using (var client = new HttpClient()) { List <Brand> jsonRequest = JsonConvert.DeserializeObject <List <Brand> >(json); // Gelen Değeri Modele Aktardım List <Brand> brand = jsonRequest; List <string> marka = new List <string>(); foreach (var item in brand) { marka.Add(item.BrandName); } ViewBag.Markalar = marka; } BlogRepository blogRepository = new BlogRepository(); BlogPhotoRepository blogPhotoRepository = new BlogPhotoRepository(); BlogCommentRepository blogCommentRepository = new BlogCommentRepository(); UserRepository userRepository = new UserRepository(); List <BlogViewModel> blogView = new List <BlogViewModel>(); var blogresult = blogRepository.GetAll(); var blogphotoresult = blogPhotoRepository.GetAll(); var blogcommentresult = blogCommentRepository.GetAll(); foreach (var item in blogresult) { blogView.Add(new BlogViewModel { Id = item.Id, Content = item.Content, Star = item.Star, Title = item.Title, RegisterDate = item.RegisterDate, UserId = item.UserId, Users = userRepository.GetById(item.UserId), }); } foreach (var item in blogphotoresult) { blogView.ForEach(x => x.Photo = item.Photo); } ViewData["Blog"] = blogView; return(View()); }