Beispiel #1
0
        public async Task <IActionResult> AddPost(MainPostViewModel mainPostVM, IFormFile file)
        {
            if (file != null)
            {
                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images", file.FileName);


                using (var fs = new FileStream(path, FileMode.Create))
                {
                    await file.CopyToAsync(fs);

                    mainPostVM.Post.ImageURL = file.FileName;
                }
            }


            var user = await userManager.FindByNameAsync(User.Identity.Name);

            if (user != null)
            {
                Post currPost = new Post()
                {
                    Description  = mainPostVM.Post.Description,
                    UserId       = user.Id,
                    UserName     = user.UserName,
                    UserFullName = user.Name + " " + user.Surname,
                    ImageURL     = mainPostVM.Post.ImageURL,
                    Title        = ""
                };

                uow.Posts.Add(currPost);
                uow.SaveChanges();
            }

            return(RedirectToAction("MainPage", "Management"));
        }
Beispiel #2
0
        public async Task <IActionResult> MainPage()
        {
            var posts = uow.Posts.GetAll();

            var currPost = new MainPostViewModel();

            currPost.Posts = new List <PostViewModel>();

            foreach (var post in posts)
            {
                currPost.Posts.Add(new PostViewModel()
                {
                    Id          = post.Id,
                    Title       = post.Title,
                    UserId      = post.UserId,
                    ImageURL    = post.ImageURL,
                    UserName    = post.UserName,
                    Description = post.Description,
                    Comments    = uow.Comments.GetCommentsByPostId(post.Id)
                });
            }

            return(View(currPost));
        }