Пример #1
0
        public ActionResult Edit(Guid id, PostViewModels model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var client  = new RestClient();
                    var request = new RestRequest("https://localhost:44386/api/posts/" + id, DataFormat.Json);

                    model.ImagePost = UploadFotoPost(model.Foto).Result;

                    request.AddJsonBody(model);
                    var key = HttpContext.Session.GetString("Token");

                    var response = client.Put <Post>(request.AddHeader("Authorization", "Bearer " + KeyValue(key)));

                    return(Redirect("/"));
                }

                return(Redirect("/"));
            }
            catch
            {
                return(View());
            }
        }
Пример #2
0
        public ActionResult Create(PostViewModels model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var client  = new RestClient();
                    var request = new RestRequest("https://localhost:44386/api/posts", DataFormat.Json);
                    var key     = HttpContext.Session.GetString("Token");

                    string value   = KeyValue(key);
                    var    jwt     = value;
                    var    handler = new JwtSecurityTokenHandler();
                    var    token   = handler.ReadJwtToken(jwt);

                    CancellationToken cancellationToken;

                    var account = _accountRepository.FindByIdAsync(token.Subject, cancellationToken);

                    model.ImagePost = UploadFotoPost(model.Foto).Result;

                    model.Account = account.Result;

                    request.AddJsonBody(model);
                    var response = client.Post <Post>(request.AddHeader("Authorization", "Bearer " + KeyValue(key)));

                    return(Redirect("/"));
                }
                return(View(model));
            }
            catch
            {
                return(View());
            }
        }
Пример #3
0
        public PostViewForUser CreatedPostsToViewModels(string id)
        {
            //Get all posts which the specific userId has.
            List <PostModel>      allPosts          = postRepository.GetAllPostsForUser(id);
            List <PostViewModels> allPostViewModels = new List <PostViewModels>();

            //For each PostModel, create a PostViewModel and add it to ^
            foreach (var post in allPosts)
            {
                PostViewModels postViewModel = new PostViewModels
                {
                    Id           = post.Id,
                    PostFrom     = userRepository.Get(post.PostFromId),
                    Message      = post.Message,
                    PostDateTime = post.PostDateTime,
                    PostTo       = userRepository.Get(id)
                };
                allPostViewModels.Add(postViewModel);
            }
            //Return the PostViewModels and get the CurrentProfile Id
            return(new PostViewForUser
            {
                ListOfPosts = allPostViewModels,
                CurrentProfile = userRepository.Get(id)
            });
        }
Пример #4
0
        public ActionResult ViewPost(int?id)
        {
            PostViewModels postViewModel = new PostViewModels();

            postViewModel.Posts    = db.Post.Find(id);
            postViewModel.Comments = db.Comment.Where(c => c.Id_Post == postViewModel.Posts.Id);

            if (postViewModel.Posts == null)
            {
                return(this.HttpNotFound());
            }
            else
            {
                ViewBag.Title = postViewModel.Posts.Title;

                RelatedArticles(postViewModel.Posts.Id);

                ViewBag.Tags = db.Post_Tags
                               .Where(t => t.Id_Post == id).ToList();

                ViewBag.Prev = db.Post.Where(p => p.Id < id && p.Deleted == false)
                               .OrderByDescending(o => o.Id).FirstOrDefault();

                ViewBag.Next = db.Post.Where(p => p.Id > id && p.Deleted == false)
                               .OrderBy(o => o.Id).FirstOrDefault();
            }

            return(View(postViewModel));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("Id,Title,CategoryId,Description,PostTime,MusicPaths,ImagePath")] PostViewModels model)
        {
            var currentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            model.UserId = currentUserId;

            if (ModelState.IsValid)
            {
                string fileName = null;
                if (model.ImagePath != null)
                {
                    string uploadDir = Path.Combine(_webHostEnvironment.WebRootPath, "images");
                    fileName = Guid.NewGuid().ToString() + "-" + model.ImagePath.FileName;
                    string filePath = Path.Combine(uploadDir, fileName);
                    model.ImagePath.CopyTo(new FileStream(filePath, FileMode.Create));
                }
                Post post = new Post()
                {
                    Title       = model.Title,
                    Description = model.Description,
                    PostTime    = model.PostTime,
                    CategoryId  = model.CategoryId,
                    UserId      = model.UserId,
                    ImagePath   = fileName
                };
                _context.Add(post);
                await _context.SaveChangesAsync();

                fileName = null;
                if (model.MusicPaths != null && model.MusicPaths.Count > 0)
                {
                    foreach (IFormFile music in model.MusicPaths)
                    {
                        string uploadDir = Path.Combine(_webHostEnvironment.WebRootPath, "musics");
                        fileName = Guid.NewGuid().ToString() + "-" + music.FileName;
                        string filePath = Path.Combine(uploadDir, fileName);
                        music.CopyTo(new FileStream(filePath, FileMode.Create));
                        Music ms = new Music()
                        {
                            PostId    = post.Id,
                            MusicName = music.FileName.Replace(".mp3", ""),
                            MusicURL  = fileName,
                        };
                        _context.Add(ms);
                        await _context.SaveChangesAsync();
                    }
                }
                return(RedirectToAction(nameof(YourPosts)));
            }
            return(View());
        }
Пример #6
0
        public ActionResult Create(PostViewModels pmm, HttpPostedFileBase file)
        {
            Post p = new Post
            {
                Content = pmm.Content,
                DatePub = DateTime.Now,
                Dislike = 0,
                Like    = 0,
                Picture = pmm.Picture
            };

            ps.Add(p);
            ps.Commit();
            return(RedirectToAction("Details"));
        }
Пример #7
0
        public ActionResult Edit(int id, PostViewModels PostModel)
        {
            Post an = ps.GetById(id);

            an.Content  = PostModel.Content;
            an.DatePub  = DateTime.Now;
            an.Dislike  = 0;
            an.Picture  = PostModel.Picture;
            an.Like     = 0;
            an.MemberID = "6";
            ps.Update(an);
            ps.Commit();

            return(RedirectToAction("Details"));
        }
Пример #8
0
        // GET: Post/Edit/5
        public ActionResult Edit(int id)
        {
            Post p = ps.GetById(id);

            var PostModel = new PostViewModels
            {
                PostID   = p.PostID,
                Content  = p.Content,
                DatePub  = p.DatePub,
                Dislike  = p.Dislike,
                Like     = p.Like,
                Picture  = p.Picture,
                MemberID = p.MemberID
            };

            return(View(PostModel));
        }
Пример #9
0
        public IActionResult Detail(string id)
        {
            string usersPost  = string.Empty;
            var    postDetail = _postRepository.GetPost(id);

            usersPost = _userManager.Users.SingleOrDefault(x => x.Id == postDetail.UserId).UserName.ToString();

            var PostVM = new PostViewModels
            {
                Id       = postDetail.Id,
                Content  = postDetail.Content,
                LinkVia  = postDetail.LinkVia,
                Name     = postDetail.Name,
                TimePost = ConvertToTimeSpan.Convert(postDetail.CreatedDate),
                Via      = postDetail.Via,
                UserName = usersPost
            };

            return(View(PostVM));
        }
Пример #10
0
        // To get Comments and Blog posts
        public ActionResult Post(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Post post = pdb.Posts.Find(id);
            IQueryable <Comment> IComment = cdb.Comments.Where(i => i.Pid == id);
            Comment        comment        = new Comment();
            PostViewModels viewmodel      = new PostViewModels();

            viewmodel.Post     = post;
            viewmodel.IComment = IComment;
            viewmodel.Comment  = comment;
            if (post == null)
            {
                return(HttpNotFound());
            }
            return(View(viewmodel));
        }
        public ActionResult Index()
        {
            if (DLSInterface.loggedEmail == null)
            {
                return(RedirectToAction("Login", "Person"));
            }
            SE_ProjectEntities    db    = new SE_ProjectEntities();
            List <PostViewModels> Posts = new List <PostViewModels>();

            foreach (Post p in db.Posts)
            {
                if (p.class_id == DLSInterface.ClassEntered)
                {
                    PostViewModels each_post = new PostViewModels();
                    each_post.Email   = p.email;
                    each_post.id      = p.id;
                    each_post.Summary = p.Summary;
                    each_post.details = p.Details;
                    each_post.image   = p.Picture;
                    Posts.Add(each_post);
                }
            }
            return(View(Posts));
        }
Пример #12
0
        public ActionResult Index(int?id, int[] filtrering)
        {
            ViewBag.Categories = DbContext.Categories.ToList();



            var tempComments = new List <Comment>();

            if (!id.HasValue)
            {
                return(View("Show"));
            }


            var forum = DbContext.Forums.Where(i => i.Id == id).Include(p => p.Posts).Include("Posts.Category").Include("Posts.SenderId").FirstOrDefault();

            var specifikaPosts = DbContext.Posts.Where(i => i.PostedForum.Id == id).ToList();

            foreach (var p in specifikaPosts)
            {
                var tempList = DbContext.Comments.Where(c => c.Post.Id == p.Id).ToList();

                foreach (var c in tempList)
                {
                    tempComments.Add(c);
                }
            }
            if (forum == null)
            {
                return(View("Show"));
            }


            var listaAttSkicka = new List <CategoryModels>();

            if (filtrering == null)
            {
                listaAttSkicka = DbContext.Categories.ToList();
            }
            else
            {
                foreach (var i in filtrering)
                {
                    listaAttSkicka.Add(DbContext.Categories.SingleOrDefault(c => c.Id == i));
                }
            }

            var categoryList = new Dictionary <CategoryModels, bool>();
            var postLista    = new List <PostModels>();


            foreach (var post in forum.Posts)
            {
                foreach (var c in listaAttSkicka)
                {
                    if (post.Category != null && post.Category.Id == c.Id)
                    {
                        postLista.Add(post);
                    }
                }
            }
            postLista.AddRange(forum.Posts.Where(m => m.Category == null));

            foreach (var category in DbContext.Categories)
            {
                bool DoesContain = listaAttSkicka.Any(i => i.Id == category.Id);
                if (DoesContain)
                {
                    categoryList.Add(category, true);
                }
                else
                {
                    categoryList.Add(category, false);
                }
            }
            var userid = User.Identity.GetUserId();
            var user   = DbContext.Users.Where(p => p.Id == userid).Include(p => p.Subscriptions).FirstOrDefault();

            var model = new PostViewModels
            {
                Posts       = postLista,
                Forum       = forum,
                Categories  = categoryList,
                ForumId     = id,
                CommentList = tempComments,
                User        = user
            };

            ViewBag.Id = id;


            return(View("Index", model));
        }
Пример #13
0
        public ActionResult CreatePost()
        {
            PostViewModels postViewModel = new PostViewModels();

            return(View(postViewModel));
        }