コード例 #1
0
        //[Authorize]
        public ActionResult Delete_Comment(int id)
        {
            var check_id = System.Web.HttpContext.Current.User.Identity.GetUserId();

            ViewBag.Person_id = check_id;

            var          com = db.Comments.FirstOrDefault(x1 => x1.Id == id);
            Comment_view res = null;

            if (com != null)
            {
                if (com.Person_id == check_id)
                {
                    db.Comments.Remove(com);
                    db.SaveChanges();
                    ViewBag.Message = "Удалено";
                }
                else
                {
                    ViewBag.Message = "Удалить невозможно";
                    var user = db.Users.First(x1 => x1.Id == com.Person_id);
                    res = new Comment_view(com)
                    {
                        Image_user = user.Image, User_name = user.Name
                    };
                }
            }



            return(PartialView(res));
        }
コード例 #2
0
        public ActionResult Object_view(int id)
        {
            var check_id = System.Web.HttpContext.Current.User.Identity.GetUserId();

            ViewBag.Person_id = check_id;
            var not_res            = db.Objects.FirstOrDefault(x1 => x1.Id == id);
            Object_os_for_view res = new Object_os_for_view(not_res);
            var img = db.Images.Where(x1 => x1.Something_id == id.ToString() && x1.What_something == "Object");

            res.Images = img.ToList();
            var com        = db.Comments.Where(x1 => x1.Object_id == id && !string.IsNullOrEmpty(x1.Text)).ToList();
            var com_person = com.FirstOrDefault(x1 => x1.Person_id == check_id);

            if (com_person == null)
            {
                ViewBag.Can_commented = true;
            }
            else
            {
                //if(string.IsNullOrEmpty(com_person.Text))
                // ViewBag.Can_commented = true;
                // else
                ViewBag.Can_commented = false;
                //
                var user = db.Users.First(x1 => x1.Id == check_id);
                var tmp  = new Comment_view(com_person)
                {
                    Image_user = user.Image, User_name = user.Name
                };

                res.Comments.Add(tmp);
            }

            foreach (var i in com)
            {
                if (i.Person_id != check_id)
                {
                    var user = db.Users.First(x1 => x1.Id == i.Person_id);
                    var tmp  = new Comment_view(i)
                    {
                        Image_user = user.Image, User_name = user.Name
                    };

                    res.Comments.Add(tmp);
                }
            }



            return(View(res));
        }