//Hämtar den inloggade användarens profil, med tillhörande inlägg och vänlista. public IActionResult MyProfile() { string email = User.Identity.Name; int id = personRepository.GetIdByUserIdentityEmail((string)email); Person user = personRepository.GetPersonById((int)id); List <Post> posts = postRepository.GetAllPostsByPersonId((int)id); List <FriendRequest> friends = requestRepository.GetFriendsByPersonId((int)id); PostUserViewModel postUserViewModel = CreatePostUserViewModel(posts, (int)id); FriendUserViewModel friendUserViewModel = CreateFriendUserViewModel(friends, (int)id); if (ModelState.IsValid) { ProfileViewModel profileViewModel = new ProfileViewModel { PersonId = user.PersonId, FirstName = user.FirstName, LastName = user.LastName, Description = user.Description, Picture = user.Picture, Email = user.Email, AccountHidden = user.AccountHidden, Posts = postUserViewModel, Friends = friendUserViewModel }; return(View(profileViewModel)); } //Om vi kommer hit är något fel och vi återgår till startsidan return(RedirectToAction("Index", "Home")); }
// GET: Post public ActionResult Index(string nameOfPostCategory = null) { var postCategory = context.CategoryPosts.Where(a => a.Name.ToLower() == nameOfPostCategory.ToLower()).FirstOrDefault(); var posts = postCategory != null?context.Posts.Where(a => a.CategoryPostId == postCategory.CategoryPostId).ToList() : context.Posts.ToList(); ApplicationUser user = null; string id = GetUserId(); if (id != string.Empty && id != null) { user = context.Users.Where(a => a.Id == id).First(); } PostUserViewModel vm = new PostUserViewModel { LoggedUser = user, Posts = posts }; return(View(vm)); }
public PartialViewResult UpdatePostWall(int id) { List <Post> posts = postRepository.GetAllPostsByPersonId(id); PostUserViewModel postUserViewModel = CreatePostUserViewModel(posts, id); return(PartialView("/Views/Post/_Post.cshtml", postUserViewModel)); }
// GET: Posts public IActionResult Index(int id) { PostUserViewModel postUserViewModel = new PostUserViewModel { TeamID = id, Team = postService.GetTeamByID(id), Posts = postService.GetPostsByTeamID(id) }; return(View(postUserViewModel)); }
public ActionResult <User> Post([FromBody] PostUserViewModel model) { try { var user = UserApplicationService.Create(model.email, model.password); return(user); } catch (Exception ex) { return(UnprocessableEntity(ex)); } }
public IActionResult GetFollowers(FollowDto dto) { var user = _userService.GetUserByUsername(dto.Username); var followers = _followService .GetUserFollows(user.Id) .Select(f => (_userService.GetUserById(f.FollowingId))); var viewmodel = new PostUserViewModel() { UserId = user.Id, Users = followers }; return(PartialView("_UserList", viewmodel)); }
public ActionResult AuthorCreatedPosts(long UserId) { logginghelper.Log(LoggingLevels.Info, "Class: " + classname + " :: AuthorCreatedPosts - Begin"); PostUserViewModel objpostuserviewmodel = null; try { objpostuserviewmodel = new PostUserViewModel(dataaccess, UserId); ViewBag.Title = "Posts"; } catch (Exception ex) { logginghelper.Log(LoggingLevels.Error, "Class: " + classname + " :: AuthorCreatedPosts" + ex); } logginghelper.Log(LoggingLevels.Info, "Class: " + classname + " :: AuthorCreatedPosts - Begin"); return(View("AuthorPosts", objpostuserviewmodel)); }
public ActionResult GetLikers(PostDto dto) { var post = _postService.GetById(dto.PostId); var user = _userService.GetUserByUsername(post.User.UserName); var likers = post.Likes .Select(r => _userService.GetUserById(r.UserId)) .ToList(); var viewModel = new PostUserViewModel() { UserId = user.Id, Users = likers }; return(PartialView("_UserList", viewModel)); }
//Skapar vymodell - PostUserViewModel, som innehåller de inlägg som gjorts på en användares vägg. public PostUserViewModel CreatePostUserViewModel(List <Post> posts, int personId) { IEnumerable <PostViewModel> postsViewModel = posts.Select((p) => new PostViewModel() { PostId = p.PostId, Author = personRepository.GetPersonById(p.AuthorId), PostText = p.PostText, Timestamp = p.Timestamp }); PostUserViewModel postUserViewModel = new PostUserViewModel { PersonId = personId, Posts = postsViewModel.ToList() }; return(postUserViewModel); }
public void IndexData() { HttpContext.Current = AbstractHttpContext.FakeHttpContext( new Dictionary <string, object> { { "UserExpandedState", 5 }, { "MaxId", 1000 } }, "http://localhost:55024/api/v1/"); PostController postController = new PostController() { GetUserId = () => "14a66224-b316-407a-a1bc-507ea56fa8eb" }; ViewResult result = postController.Index() as ViewResult; PostUserViewModel posts = result.ViewData.Model as PostUserViewModel; Assert.AreEqual(db.Posts.Count(), posts.Posts.Count); }
public IActionResult Profile(int id) { if (id > 0) { Person user = personRepository.GetPersonById((int)id); List <Post> posts = postRepository.GetAllPostsByPersonId((int)id); PostUserViewModel postUserViewModel = CreatePostUserViewModel(posts, (int)id); ProfileViewModel profileViewModel = new ProfileViewModel { PersonId = user.PersonId, FirstName = user.FirstName, LastName = user.LastName, Description = user.Description, Picture = user.Picture, Posts = postUserViewModel }; ViewBag.PersonRelation = GetPersonRelation(id); return(View(profileViewModel)); } //Om vi kommer hit är något fel och vi återgår till startsidan return(RedirectToAction("Index", "Home")); }
public Guid Post(PostUserViewModel postUserViewModel) { if (string.IsNullOrEmpty(postUserViewModel.Name)) { throw new Exception("Name não pode ser em branco"); } if (string.IsNullOrEmpty(postUserViewModel.Email)) { throw new Exception("E-mail não pode ser em branco"); } if (string.IsNullOrEmpty(postUserViewModel.Password)) { throw new Exception("Password não pode ser em branco"); } if (this.userRepository.Find(x => x.Email == postUserViewModel.Email & !x.IsDeleted) != null) { throw new Exception("Já existe usuário cadastrado para esse email"); } Guid response = userRepository.Create(new User { Id = Guid.NewGuid(), Name = postUserViewModel.Name, Email = postUserViewModel.Email, Password = postUserViewModel.Password }).Id; userRoleRepository.Create(new UserRole { Id = Guid.NewGuid(), UserId = response, RoleId = roleRepository.Find(x => x.Name == "User" & !x.IsDeleted).Id }); return(response); }