コード例 #1
0
ファイル: PostsController.cs プロジェクト: SamZCoder/Corezine
        public async Task <IActionResult> Create(CreateUpdatePostViewModel model)
        {
            if (ModelState.IsValid)
            {
                AppUser CurrentUser = await this.UserManager.GetUserAsync(HttpContext.User);

                //Upload File
                String UploadPath = Path.Combine(HostingEnvironment.WebRootPath, "Uploads");
                if (!Directory.Exists(UploadPath))
                {
                    Directory.CreateDirectory(UploadPath);
                }
                String ThumbnailName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + "-" + model.Thumbnail.FileName;
                String FullPath      = Path.Combine(UploadPath, ThumbnailName);
                using (FileStream stream = new FileStream(FullPath, FileMode.Create, FileAccess.Write))
                { model.Thumbnail.CopyTo(stream); }
                Post post = new Post()
                {
                    CategoryId    = model.CategoryId,
                    Status        = model.Status,
                    Content       = model.Content,
                    ThumbnailPath = ThumbnailName,
                    Title         = model.Title,
                    UserId        = CurrentUser.Id,
                };
                PostsRepository.Add(post);
                await PostsRepository.CommitAsync();

                return(RedirectToAction("Index"));
            }
            model.Categories = CategoriesRepository.GetAll();
            return(View(model));
        }
コード例 #2
0
ファイル: AddPost.cs プロジェクト: constantinescuv/SmartTour
 public PostEntity Add(PostEntity post)
 {
     post.dt_created = DateTime.Now;
     _posts.Add(post);
     _posts.SaveChanges();
     return(post);
 }
コード例 #3
0
ファイル: PostController.cs プロジェクト: alpha-dog/SG
        public ActionResult Create(CreatePostViewModel model)
        {
            //var repo = new PostsRepository();

            var hashArray = model.HashtagString.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries).Where(h => !String.IsNullOrWhiteSpace(h)).Select(h => h.Trim());

            model.Post = _repo.Add(model.Post);
            _hepo.AssociateHashtagsWithPost(hashArray, model.Post);
            return(RedirectToAction("Create"));
        }
コード例 #4
0
        public void AddPostsService(PostsDTO entity)
        {
            Posts posts = new Posts
            {
                PostCategoryId  = entity.PostCategoryId,
                PostTitle       = entity.PostTitle,
                PostDiscription = entity.PostDiscription,
                PostPhoto       = entity.PostPhoto
            };

            postsRepository.Add(posts);
        }
コード例 #5
0
        public Post Post([FromBody] NewPostRequest post)
        {
            var sub = User.FindFirst(ClaimTypes.GivenName); //.Claims.Where(x => x.Type == ClaimTypes.NameIdentifier).FirstOrDefault();

            if (sub != null)
            {
                post.PostedBy = sub.Value.ToString();
            }
            else
            {
                post.PostedBy = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            }
            return(_repo.Add(post));
        }
コード例 #6
0
        public IHttpActionResult CreatePost(IncomingPostDto IncomingPostDto)
        {
            if (ModelState.IsValid)
            {
                Post post = MapToDto(IncomingPostDto);
                Repository.Add(post);

                unitOfWork.Save();

                OutgoingPostDto outcomingPostDto = Mapper.Map <OutgoingPostDto>(post);

                return(Ok(outcomingPostDto));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
コード例 #7
0
        public PostsModule()
        {
            var postsRepository   = new PostsRepository();
            var authorsRepository = new AuthorsRepository();
            var blogsRepository   = new BlogsRepository();

            Get["/Posts"] = p =>
            {
                var posts = postsRepository.GetAll();

                return(View["Posts/index", new { Posts = posts, Title = "Nancy Blog", Description = "A simple blog demo built with Nancy" }]);
            };

            Get["/Posts/{id}"] = p =>
            {
                var post = postsRepository.Find(p.id);

                return(View["Posts/show", new { Post = post, Title = "Nancy Blog", Description = "A simple blog demo built with Nancy" }]);
            };

            Get["/Posts/New"] = p =>
            {
                var post = new Post();

                var author = authorsRepository.Find(1);

                var blog = blogsRepository.Find(1);

                return(View["Posts/new", new { Post = post, Author = author, Blog = blog, Title = "Nancy Blog", Description = "A simple blog demo built with Nancy", Action = "Create" }]);
            };

            Post["/Posts/Create"] = p =>
            {
                Post post = this.Bind();

                var addedPost = postsRepository.Add(post);

                if (post.PostId != addedPost.PostId)
                {
                    return(Response.AsRedirect("/Posts"));
                }

                return(View[""]);
            };

            Get["/Posts/{id}/Edit"] = p =>
            {
                var post = postsRepository.Find(p.id);

                var author = authorsRepository.Find(1);

                var blog = blogsRepository.Find(1);

                return(View["Posts/edit", new { Post = post, Author = author, Blog = blog, Title = "Nancy Blog", Description = "A simple blog demo built with Nancy", Action = p.id + "/Update" }]);
            };

            Post["/Posts/Update"] = p =>
            {
                Post post = this.Bind();

                var modifiedPost = postsRepository.Update(post);

                if (true)
                {
                    return(Response.AsRedirect("/Posts"));
                }

                return(View[""]);
            };
        }