Exemple #1
0
        public ActionResult PostEdit([Bind(Exclude = "Expiration,Email")] ModifyPostViewModel post)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Identity.GetUserId();

                if (postl.UserPostModify(post) == false)
                {
                    return(HttpNotFound());
                }
                else
                {
                    TempData["Edit_Success"] = "Successfully modify post";
                    return(RedirectToAction("PostDetails", new { id = post.PostId }));
                }
            }
            else
            {
                var locations = locl.CombineLocation();
                ViewData["location"] = new SelectList(locations, "Id", "Name");

                var types = typel.CombineType();
                ViewData["type"] = new SelectList(types, "Id", "Name");

                var temppost = db.Posts.Find(post.PostId);
                post.Expiration = temppost.Expiration;
                post.Email      = db.Users.Find(User.Identity.GetUserId()).Email;
                return(View(post));
            }
        }
Exemple #2
0
        // GET: Post/Edit/5
        public ActionResult PostEdit(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            var  userId = User.Identity.GetUserId();
            Post post   = db.Posts.Find(id);

            if (post.Hidden == true)
            {
                return(HttpNotFound());
            }
            if (acl.AuthorizeAdmin(userId) != true)
            {
                if (!acl.CheckPostLegal(userId, (int)id))
                {
                    return(HttpNotFound());
                }
            }

            if (!postl.CheckNotExpire((int)id))
            {
                TempData["Expire"] = "The post has expired, cannot edit!";
                return(RedirectToAction("PostDetails", new { id = (int)id }));
            }

            var user = db.Users.Find(userId);

            var locations = locl.CombineLocation();

            ViewData["location"] = new SelectList(locations, "Id", "Name");

            var types = typel.CombineType();

            ViewData["type"] = new SelectList(types, "Id", "Name");


            var modifypostmodel = new ModifyPostViewModel
            {
                PostId       = (int)id,
                Email        = user.Email,
                Expiration   = post.Expiration,
                Title        = post.Title,
                Body         = post.Body,
                LocationName = post.LocaleId,
                TypeName     = post.SubcategoryId
            };

            return(View(modifypostmodel));
        }
Exemple #3
0
        public static bool UserPostModify(ModifyPostViewModel post)
        {
            var oldpost = (from temp in db.Posts
                           where temp.Id == post.PostId
                           select temp).SingleOrDefault();

            if (oldpost == null)
            {
                return(false);
            }
            else
            {
                oldpost.Title         = post.Title;
                oldpost.Body          = post.Body;
                oldpost.AreaId        = db.Locales.Find(post.LocationName).AreaId;
                oldpost.LocaleId      = post.LocationName;
                oldpost.CategoryId    = db.Subcategories.Find(post.TypeName).CategoryId;
                oldpost.SubcategoryId = post.TypeName;
                oldpost.Timestamp     = DateTime.Now;
                db.SaveChanges();
                return(true);
            }
        }