//записываем пост public string PostCreate(PostVM postVM, int user_id) { //мапим вюмодель в сущность var post = new Entity.Post() { Title = postVM.Title, Content = postVM.Content, User_Id = user_id, }; if (postRepository.PostCreate(post) == 0) { throw new AppException("Ошибка записи в блог"); } //получаем крайний айди поста var postLastId = postRepository.PostGetLast(); //получаем все тэги var allTags = postRepository.TagFindAll(); foreach (var tag in postVM.Tags) { var tag_id = allTags.FirstOrDefault(x => x.Title == tag.Title).Id; var post_tag = new Post_Tag() { Post_Id = postLastId, Tag_Id = tag_id }; //записываем тэги по посту postRepository.TagCreate(post_tag); } return("Запись успешно добавлена!"); }
public ActionResult DeleteConfirmed(int id) { Post_Tag post_Tag = db.Tag_Of_Post.Find(id); db.Tag_Of_Post.Remove(post_Tag); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,TagId,Post_Id")] Post_Tag post_Tag) { if (ModelState.IsValid) { db.Entry(post_Tag).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TagId = new SelectList(db.All_Tags, "Id", "Tag_Name", post_Tag.TagId); return(View(post_Tag)); }
public ActionResult Create([Bind(Include = "Id,TagId,Post_Id")] Post_Tag post_Tag) { if (ModelState.IsValid) { db.Tag_Of_Post.Add(post_Tag); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TagId = new SelectList(db.All_Tags, "Id", "Tag_Name", post_Tag.TagId); return(View(post_Tag)); }
// GET: Post_Tag/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Post_Tag post_Tag = db.Tag_Of_Post.Find(id); if (post_Tag == null) { return(HttpNotFound()); } return(View(post_Tag)); }
// GET: Post_Tag/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Post_Tag post_Tag = db.Tag_Of_Post.Find(id); if (post_Tag == null) { return(HttpNotFound()); } ViewBag.TagId = new SelectList(db.All_Tags, "Id", "Tag_Name", post_Tag.TagId); return(View(post_Tag)); }
public int TagCreate(Post_Tag post_tag) { return(Execute("INSERT INTO POSTS_TAGS (POST_ID,TAG_ID) VALUES (:POST_ID,:TAG_ID)", post_tag)); }
public ActionResult Create(Post_Tag post_tag) { post_tagRepo.Create(post_tag); return(RedirectToAction("../Post/Index/")); }