public ActionResult PublicShow(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //EF 6 technique BlogTopic blogtopic = db.Topics.SqlQuery("select * from BlogTopics where TopicId=@TopicId", new SqlParameter("@TopicId", id)).FirstOrDefault(); if (blogtopic == null) { return(HttpNotFound()); } string blogs_query = "Select * from DoctorsBlogs inner join BlogTopicDoctorsBlogs on DoctorsBlogs.BlogId = BlogTopicDoctorsBlogs.DoctorsBlog_BlogId where BlogTopicDoctorsBlogs.BlogTopic_TopicId=@TopicId"; var t_parameter = new SqlParameter("@TopicId", id); List <DoctorsBlog> blogs = db.DoctorsBlogs.SqlQuery(blogs_query, t_parameter).ToList(); // We use the AddBlogTopic viewmodel so that we can show the blogs which have that specific topic AddBlogTopic viewmodel = new AddBlogTopic(); viewmodel.Topics = blogtopic; viewmodel.Blogs = blogs; return(View(viewmodel)); }
public ActionResult PublicShow(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //EF 6 technique DoctorsBlog doctorsblog = db.DoctorsBlogs.SqlQuery("select * from DoctorsBlogs where BlogId=@BlogId", new SqlParameter("@BlogId", id)).FirstOrDefault(); if (doctorsblog == null) { return(HttpNotFound()); } string topic_query = "select * from BlogTopics inner join BlogTopicDoctorsBlogs on BlogTopics.TopicId = BlogTopicDoctorsBlogs.BlogTopic_TopicId where BlogTopicDoctorsBlogs.DoctorsBlog_BlogId=@BlogId"; var t_parameter = new SqlParameter("@BlogId", id); List <BlogTopic> usedtopics = db.Topics.SqlQuery(topic_query, t_parameter).ToList(); AddBlogTopic viewmodel = new AddBlogTopic(); viewmodel.Blog = doctorsblog; viewmodel.BlogTopics = usedtopics; return(View(viewmodel)); }
public ActionResult Show(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //EF 6 technique DoctorsBlog doctorsblog = db.DoctorsBlogs.SqlQuery("select * from DoctorsBlogs where BlogId=@BlogId", new SqlParameter("@BlogId", id)).FirstOrDefault(); if (doctorsblog == null) { return(HttpNotFound()); } string topic_query = "select * from BlogTopics inner join BlogTopicDoctorsBlogs on BlogTopics.TopicId = BlogTopicDoctorsBlogs.BlogTopic_TopicId where BlogTopicDoctorsBlogs.DoctorsBlog_BlogId=@BlogId"; var t_parameter = new SqlParameter("@BlogId", id); List <BlogTopic> usedtopics = db.Topics.SqlQuery(topic_query, t_parameter).ToList(); string all_topics_query = "select * from BlogTopics"; List <BlogTopic> AllTopics = db.Topics.SqlQuery(all_topics_query).ToList(); // We use the AddBlogTopic viewmodel so that we can show the topics that are on that blog post and also so that we can see the dropdown list of topics // so that the user can add a topic AddBlogTopic viewmodel = new AddBlogTopic(); viewmodel.Blog = doctorsblog; viewmodel.BlogTopics = usedtopics; viewmodel.Add_Topic = AllTopics; return(View(viewmodel)); }
public ActionResult Add() { // On the new blog entry we can select a topic List <BlogTopic> Topics = db.Topics.SqlQuery("select * from BlogTopics").ToList(); string userId = User.Identity.GetUserId(); ApplicationUser currentUser = db.Users.FirstOrDefault(x => x.Id == userId); //We use the AddBlogTopic viewmodel to show the topics and be able to add them to the blog entry. //We also get the user who made the entry through the view model that way it also goes into their personal list. AddBlogTopic AddBlogTopicViewModel = new AddBlogTopic(); AddBlogTopicViewModel.BlogTopics = Topics; AddBlogTopicViewModel.User = currentUser; return(View(AddBlogTopicViewModel)); }
public ActionResult Update(int id) { //need information about a particular blog entry DoctorsBlog selectedblog = db.DoctorsBlogs.SqlQuery("select * from DoctorsBlogs where BlogId=@BlogId", new SqlParameter("@BlogId", id)).FirstOrDefault(); string topic_query = "select * from BlogTopics inner join BlogTopicDoctorsBlogs on BlogTopics.TopicId = BlogTopicDoctorsBlogs.BlogTopic_TopicId where BlogTopicDoctorsBlogs.DoctorsBlog_BlogId=@BlogId"; var t_parameter = new SqlParameter("@BlogId", id); List <BlogTopic> usedtopics = db.Topics.SqlQuery(topic_query, t_parameter).ToList(); //We use the AddBlogTopic viewmodel to show the topics. AddBlogTopic AddBlogTopicViewModel = new AddBlogTopic(); AddBlogTopicViewModel.Blog = selectedblog; AddBlogTopicViewModel.BlogTopics = usedtopics; return(View(AddBlogTopicViewModel)); }