public IActionResult MyProfile() { var username = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value; var userModel = _userBll.GetByUsername(username); var userProfileViewModel = userModel.ToUserProfileViewModel(); return(View(userProfileViewModel)); }
public void Add(PostModel post) { var user = _userBll.GetByUsername(post.User.Username); if (user == null) { throw new ExceptionResourceNotFound($"User {post.User.Username} not found."); } _postRepository.Add(post.ToPost(user.Id)); _postRepository.SaveChanges(); }