Пример #1
0
        // GET: Posts/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Post post = db.Posts.Find(id);

            if (post == null)
            {
                return(HttpNotFound());
            }

            var model = new PostEditVM();

            model.StartDate            = post.StartDate;
            model.AreMaterialsIncluded = post.AreMaterialsIncluded;
            model.Description          = post.Description;
            model.Id        = post.Id;
            model.ImageUrl  = post.ImageUrl;
            model.OwnerName = post.ProjectOwner.FirstName + " " + post.ProjectOwner.LastName;
            model.Title     = post.Title;
            model.Url       = post.Url;

            return(View(model));
        }
Пример #2
0
        public IActionResult Save(PostEditVM x)
        {
            if (!ModelState.IsValid)
            {
                x.Categories = AllCategories();
                return(PartialView("Edit", x));
            }

            Post post;

            if (x.PostId == 0)
            {
                post = new Post();
                ctx.Posts.Add(post);
            }
            else
            {
                post = ctx.Posts.Find(x.PostId);
            }

            post.Title       = x.Title;
            post.Description = x.Description;
            post.Body        = x.Body;
            post.Category    = ctx.Categories.Find(x.CategoryId);
            //post.Moderator = HttpContext.GetLogiranogModeratora();

            ctx.SaveChanges();

            if (x.PredefinedCategory)
            {
                return(RedirectToAction("IndexPartial", "Category", new { area = "Admin" }));
            }

            return(PartialView("Index", PreparePosts()));
        }
Пример #3
0
        //Posts/Create
        public ActionResult Create()
        {
            var model = new PostEditVM();

            model.StartDate = DateTime.Now.AddDays(1);

            return(View());
        }
Пример #4
0
        //
        // GET: /Posts/Edit/5

        public ActionResult Edit(int id = 0, int threadid = 0)
        {
            Post post = db.Posts.Find(id);

            if (post == null)
            {
                return(HttpNotFound());
            }
            var viewmodel = new PostEditVM()
            {
                post = post, threadid = threadid
            };

            return(View(viewmodel));
        }
Пример #5
0
        public IActionResult Create(PostEditVM model)
        {
            if (ModelState.IsValid)
            {
                var post = new Post();
                post.Slug        = model.Slug;
                post.Title       = model.Title;
                post.Abstract    = model.Abstract;
                post.Body        = model.Body;
                post.PublishDate = model.PublishDate;
                this.blogPostRepository.Add(post);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Пример #6
0
        public ActionResult Create(PostEditVM post)
        {
            var currentUserId = User.Identity.GetUserId();
            var currentUser   = db.Users.Find(currentUserId);

            var newPost = new Post()
            {
                ProjectOwner         = currentUser,
                Url                  = post.Url,
                ImageUrl             = post.ImageUrl,
                StartDate            = post.StartDate,
                AreMaterialsIncluded = post.AreMaterialsIncluded,
                Description          = post.Description
            };

            currentUser.MyPosts.Add(newPost);

            db.Posts.Add(newPost);
            db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Пример #7
0
        public ActionResult Edit(PostEditVM model)
        {
            Post post = db.Posts.Find(model.Id);

            if (ModelState.IsValid)
            {
                post.StartDate            = model.StartDate;
                post.AreMaterialsIncluded = model.AreMaterialsIncluded;
                post.Description          = model.Description;
                post.ImageUrl             = model.ImageUrl;
                post.Title = model.Title;
                post.Url   = model.Url;

                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }


            model.OwnerName = post.ProjectOwner.FirstName + " " + post.ProjectOwner.LastName;
            return(View(model));
        }
Пример #8
0
 public void UpdateMappedPost(PostEditVM vm)
 {
     throw new NotImplementedException();
 }