// GET: Committments by User public async Task <IActionResult> SearchByUser(int id) { var userId = _userManager.GetUserId(User); var userProfileId = await _context.UserProfile .Where(u => u.UserId == userId) .Select(u => u.UserProfileId).FirstOrDefaultAsync(); // check if searching for logged in user if (userProfileId == id) { // redirect to my commitments return(RedirectToAction("My")); } else { // return search results of other user var model = new ListCommitmentsViewModel(); model.Commitments = await _context.Commitment .Where(u => u.UserProfileId == id) .Include(u => u.UserProfile) .OrderByDescending(u => u.DateCreated) .ToListAsync(); model.SearchUserName = await _context.UserProfile .Where(u => u.UserProfileId == id) .Select(u => u.FullName) .FirstOrDefaultAsync(); return(View(model)); } }
// GET: Commitments public async Task <IActionResult> Index() { var model = new ListCommitmentsViewModel(); model.Commitments = await _context.Commitment .Include(u => u.UserProfile) .OrderByDescending(u => u.DateCreated).ToListAsync(); return(View(model)); }
// GET: My Commitments (Logged in User) public async Task <ActionResult> My() { var userId = _userManager.GetUserId(User); var model = new ListCommitmentsViewModel(); model.Commitments = await _context.Commitment .Where(u => u.UserProfile.UserId == userId) .Include(u => u.UserProfile) .OrderByDescending(u => u.DateCreated).ToListAsync(); var up = await _context.UserProfile.SingleOrDefaultAsync(u => u.UserId == userId); model.IsCRM = up.IsCRM; model.IsExpenses = up.IsExpenses; model.IsFRI = up.IsFRI; model.IsAscendNotes = up.IsAscendNotes; return(View(model)); }