Beispiel #1
0
 public Post SaveNewPost(Post dataPost)
 {
     _ncEntities.Posts.Add(dataPost);
     _ncEntities.SaveChanges();
     return dataPost;
 }
        public JsonResult CreatePost(CreatePost post)
        {
            if (!ModelState.IsValid)
            {
                return Json(new { success = false, result = "Validation Error" }, JsonRequestBehavior.AllowGet);
            }

            Post postModel = new Post
            {
                Needed = post.Needed == "1",
                CategoryId = post.CategoryID,
                Title = post.Title,
                Description = post.Description,
                PostDate = DateTime.Now,
                ShowEmailInPost = post.ShowEmailInPost,
                ContactPhone = post.ContactPhone,
                LocationId = SaveAddress(post),
                CreatorName = post.PostCreatorName,
                ContactEmail = post.PostCreatorEmail
            };
            postModel = Mapper.Map<Post>(_postRepository.SaveNewPost(postModel));
            UrlHelper redirectUrl = new UrlHelper(ControllerContext.RequestContext);
            string url = redirectUrl.Action("SinglePost", "Post", new { postId = postModel.Id });
            return Json(new { success = true, redirectToUrl = url }, JsonRequestBehavior.AllowGet);
        }