public ActionResult BlogAdd(BlogViewModel model) { User user = (User)Session["LoginUser"]; BlogRepository blogRepository = new BlogRepository(); BlogPhotoRepository blogPhotoRepository = new BlogPhotoRepository(); var resultblog = blogRepository.Add(new Blog { Content = model.Content, Star = model.Star, UserId = user.Id, Title = model.Title, RegisterDate = DateTime.Now, IsDelete = false }); var blogresult = blogRepository.GetByFilter(x => x.Title == model.Title && x.UserId == user.Id).FirstOrDefault(); blogPhotoRepository.Add(new BlogPhoto { BlogId = blogresult.Id, IsDelete = false, Photo = model.Photo, RegisterDate = DateTime.Now }); TempData["Mesaj"] = resultblog ? new TempDataDictionary { { "class", "alert-success" }, { "Msg", "Kayıt başarıyla eklendi." } } : new TempDataDictionary { { "class", "alert-danger" }, { "Msg", "Kayıt eklenemedi bilgilerini kontrol et." } }; return(View()); }
// 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()); }
// Get BlogUpdate public ActionResult BlogUpdate(int id) { User user = (User)Session["LoginUser"]; BlogRepository blogRepository = new BlogRepository(); BlogPhotoRepository blogPhotoRepository = new BlogPhotoRepository(); var result = blogRepository.GetByFilter(x => x.UserId == user.Id && x.Id == id).FirstOrDefault(); var photoresult = blogPhotoRepository.GetByFilter(x => x.BlogId == id).FirstOrDefault(); BlogViewModel blogView = new BlogViewModel(); blogView.Id = id; blogView.Photo = photoresult.Photo; blogView.Star = result.Star; blogView.Title = result.Title; blogView.Content = result.Content; return(View()); }
public ActionResult Detail(int id) { BlogRepository blogRepository = new BlogRepository(); BlogPhotoRepository blogPhotoRepository = new BlogPhotoRepository(); BlogCommentRepository blogCommentRepository = new BlogCommentRepository(); BlogDetailViewModel blogView = new BlogDetailViewModel(); var blogresult = blogRepository.GetById(id); var blogphotoresult = blogPhotoRepository.GetByFilter(X => X.BlogId == id); var blogcommentresult = blogCommentRepository.GetByFilter(x => x.BlogId == id); blogView.Content = blogresult.Content; blogView.Star = blogresult.Star; blogView.Title = blogresult.Title; blogView.RegisterDate = blogresult.RegisterDate; blogView.UserId = blogresult.UserId; blogView.Users = blogresult.Users; blogView.blogComment = blogcommentresult; blogView.blogPhoto = blogphotoresult; return(View(blogView)); }