예제 #1
0
        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);
        }
예제 #2
0
 private int SaveAddress(CreatePost post)
 {
     //Create address object and save it to table and assign its id to the postmodel's locationid
     Address address = new Address
     {
         CityId = Int32.Parse(post.City),
         StateId = Int32.Parse(post.State),
         CountryId = Int32.Parse(post.Country),
         ZipCode = Int32.Parse(post.ZipCode ?? NcConstants.DefaultZipCodeId)
     };
     return _addressRepository.SaveAddress(address);
 }