Ejemplo n.º 1
0
        //записываем пост
        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("Запись успешно добавлена!");
        }
Ejemplo n.º 2
0
        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"));
        }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        // 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));
        }
Ejemplo n.º 6
0
        // 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));
        }
Ejemplo n.º 7
0
 public int TagCreate(Post_Tag post_tag)
 {
     return(Execute("INSERT INTO POSTS_TAGS (POST_ID,TAG_ID) VALUES (:POST_ID,:TAG_ID)", post_tag));
 }
Ejemplo n.º 8
0
 public ActionResult Create(Post_Tag post_tag)
 {
     post_tagRepo.Create(post_tag);
     return(RedirectToAction("../Post/Index/"));
 }