public List <BaseUserViewModel> GetLikes(Guid postId) { var likes = _context.Likes .Where(p => p.Post.PostId == postId).ToList(); var users = new List <ApplicationUser>(); foreach (var like in likes) { var user = _context.Users .SingleOrDefault(p => p.Likes.Contains(like)); users.Add(user); } var usersViewModel = new List <BaseUserViewModel>(); foreach (var user in users) { var userViewModel = new BaseUserViewModel() { UserId = user.Id, MainPhotoPath = user.MainPhotoPath, UserName = user.UserName, }; usersViewModel.Add(userViewModel); } return(usersViewModel); }
public async Task <ApiResult <BaseUserViewModel> > CreateOrUpdateUser(BaseUserViewModel model) { return(await ApiRequestHelper.HandlApiRequest(async() => { var user = await _api.CreateOrUpdateUser(Mapper.Map <User>(model)); return new ApiResult <BaseUserViewModel>(string.Empty, true, new BaseUserViewModel(user)); })); }
// GET: BaseUsers public IActionResult Index() { var student = _context.users.Where(c => c.UserType.Contains("Teacher") || c.UserType.Contains("Admin")); var studentViewModel = new BaseUserViewModel() { ListUsers = student.ToList() }; return(View(studentViewModel)); }
public override void Prepare(LoginViewModel parameter) { if (parameter != null) { _exitToMain = true; _navigationService.Close(parameter); User = new BaseUserViewModel { BirthDate = default(DateTimeOffset) }; } }
//Display for all students public IActionResult Student(int?id) { var student = _context.students.Where(c => c.UserType.Contains("Student")); var teacher = _context.users.Where(c => c.UserType.Contains("Teacher")); var course = _context.courses.ToList(); var baseViewModel = new BaseUserViewModel() { ListStudents = student.ToList(), ListUsers = teacher.ToList(), Course = course }; return(View(baseViewModel)); }
public IActionResult Update([FromBody] BaseUserViewModel user) { var id = User.GetId(); if (!user.Id.Equals(id)) { return(BadRequest("You can only update your own account")); } if (!_userService.TryFind(id, out var currentUser)) { return(NotFound("There isn't a user with that id")); } _mapper.Map(user, currentUser); _userService.Update(currentUser); _unitOfWork.SaveChanges(); return(Ok(user)); }
public async Task <IActionResult> Index(BaseUserViewModel User) { if (ModelState.IsValid) { if (User.BaseUser2 != null) { _context.Add(User.BaseUser2); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { _context.Add(User.Student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Student))); } } else { if (User.BaseUser2 != null) { var student = _context.users.Where(c => c.UserType.Contains("Teacher") || c.UserType.Contains("Admin")); var studentViewModel = new BaseUserViewModel() { ListUsers = student.ToList() }; return(View(studentViewModel)); } else { var student = _context.students.OrderBy(c => c.UserId); var studentViewModel = new BaseUserViewModel() { ListUsers = student.ToList() }; return(RedirectToAction(nameof(Student))); } } }
public List <BaseUserViewModel> GetFollowers(ApplicationUser user) { var userFollowings = (from f in _context.Followers where f.FollowerUser == user select f.FollowingUser).ToList(); var followings = new List <BaseUserViewModel>(); foreach (var following in userFollowings) { var viewModel = new BaseUserViewModel { UserId = following.Id, MainPhotoPath = following.MainPhotoPath, UserName = following.UserName }; followings.Add(viewModel); } return(followings); }
public AdminUserItemViewModel(BaseUserViewModel u, IMvxNavigationService navigationService) { User = u; _navigationService = navigationService; }
public NewMessageItemViewModel(BaseUserViewModel user, bool itemAdded) { _itemAdded = itemAdded; User = user; }
public List <EventViewModel> GetEvents(ApplicationUser user) { var allPosts = _context.Posts .Where(p => p.Creator == user) .Include(p => p.Likes) .ToList(); var likes = new List <Like>(); foreach (var post in allPosts) { var likesToAdd = post.Likes; likes.AddRange(likesToAdd); } var followers = (from f in _context.Followers where f.FollowingUser == user select new { f.FollowerUser, f.DateOfFollowing }).ToList(); var events = new List <EventViewModel>(); foreach (var like in likes) { var userViewModel = new BaseUserViewModel { UserId = like.User.Id, UserName = like.User.UserName, MainPhotoPath = like.User.MainPhotoPath }; var postViewModel = new PostViewModel { PostId = like.Post.PostId, PhotoPath = like.Post.PicturePath }; var eventViewModel = new EventViewModel { User = userViewModel, EventDate = like.Date, Message = "liked your post", Post = postViewModel }; events.Add(eventViewModel); } foreach (var follower in followers) { var userViewModel = new BaseUserViewModel { UserId = follower.FollowerUser.Id, UserName = follower.FollowerUser.UserName, MainPhotoPath = follower.FollowerUser.MainPhotoPath }; var eventViewModel = new EventViewModel { User = userViewModel, EventDate = follower.DateOfFollowing, Message = "followed you" }; events.Add(eventViewModel); } var eventsToReturn = events.OrderByDescending(p => p.EventDate).ToList(); return(eventsToReturn); }
public SearchItemUserViewModel(BaseUserViewModel u, IMvxNavigationService navigationService) { User = u; _navigationService = navigationService; }