public ActionResult Posts_Destroy([DataSourceRequest]DataSourceRequest request, Post post)
        {
            this.posts.Delete(post.Id);
            this.posts.SaveChanges();

            return Json(new[] { post }.ToDataSourceResult(request, ModelState));
        }
예제 #2
0
        public ActionResult Posts_Destroy([DataSourceRequest]DataSourceRequest request, Post post)
        {
            if (this.ModelState.IsValid)
            {
                this.posts.Delete(post.Id);
            }

            return this.Json(new[] { post }.ToDataSourceResult(request, this.ModelState));
        }
예제 #3
0
        public HttpRequestMessage Create(CreatePostModel model)
        {
            var post = new Post();
            post.DeliverLater = model.SendLater;
            post.Content = model.Content;
            post.Account_Id = 1;
            post.IsKnown = true;

            var service = DependencyResolver.GetPostService();
            service.AddPost(post);

            return new HttpRequestMessage();
        }
        public ActionResult Posts_Create([DataSourceRequest]DataSourceRequest request, AdministerPostViewModel post)
        {
            var newId = 0;          

            if (ModelState.IsValid)
            {
                var entity = new Post
                {
                    Title = post.Title,
                    Content = post.Content,
                    AuthorId = this.User.Identity.GetUserId()
                };

                this.posts.Add(entity);
                this.posts.SaveChanges();
                newId = entity.Id;
            }
            var postToDisplay = this.posts
                .All()
                .To<AdministerPostViewModel>()
                .FirstOrDefault(x => x.Id == newId);

            return Json(new[] { postToDisplay }.ToDataSourceResult(request, ModelState));
        }
        public ActionResult Ask(AskInputModel input)
        {
            if (ModelState.IsValid)
            {
                var userId = this.User.Identity.GetUserId();

                var post = new Post
                {
                    Title = input.Title,
                    Content = this.sanitizer.Sanitize(input.Content),
                    AuthorId = userId,

                    // TODO: Tags
                    // TODO: Author
                };

                this.posts.Add(post);
                this.posts.SaveChanges();
                return this.RedirectToAction("Display", new { id = post.Id, url = "new" });
            }

            return this.View(input);
        }
예제 #6
0
 public void AddPost(Post post)
 {
     this._repository.Insert(post);
 }
예제 #7
0
        public ActionResult Create(PostViewModel post, HttpPostedFileBase upload)
        {
            if (this.ModelState.IsValid)
            {
                var postToAdd = new Post
                {
                    Title = post.Title,
                    Content = post.Content,
                    CreatorId = this.User.Identity.GetUserId()
                };

                if (upload != null && upload.ContentLength > 0)
                {
                    var photo = new Data.Models.File
                    {
                        FileName = Path.GetFileName(upload.FileName),
                        FileType = FileType.Photo,
                        ContentType = upload.ContentType
                    };

                    using (var reader = new BinaryReader(upload.InputStream))
                    {
                        photo.Content = reader.ReadBytes(upload.ContentLength);
                    }

                    postToAdd.Photo = photo;
                }

                this.posts.Add(postToAdd);
            }

            return this.Redirect(this.Request.UrlReferrer.ToString());
        }
예제 #8
0
        public ActionResult Create(PostViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            var categoryPostToAdd = this.postCategory.EnsureCategory(model.Category);
               var post = new Post()
            {
                IsVideo = model.IsVideo,
                SharedUrl = model.SharedUrl,
                Title = model.Title,
                Category = categoryPostToAdd,
                AuthorId = this.User.Identity.GetUserId()
             };
            if (post.IsVideo)
            {
                var videoId = post.SharedUrl.Split('=');
                post.SharedUrl = @"https://www.youtube.com/embed/" + videoId[videoId.Count() - 1];
            }

            categoryPostToAdd.Posts.Add(post);
            this.posts.Create(post);
            this.TempData["Notification"] = "Post Created!";
            return this.Redirect("/");
        }
        public ActionResult CreatePost(InputPostViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                var categories = this.categories.GetAllCategories().To<CategoriesViewModel>().ToList();

                model.Categories = categories;

                return this.View(model);
            }

            var tags = this.tags.CheckExist(model.Tags).ToList();

            var userId = this.User.Identity.GetUserId();

            var post = new Post
            {
                CategoryId = model.CategoryId,
                Content = model.Content,
                Tags = tags,
                Title = model.Title,
                UserId = userId
            };

            this.posts.CreatePost(post);
            this.TempData["Notification"] = "You successfully add your post.";
            return this.RedirectToAction("Index");
        }