public static User ToModel(this DataContract.User user) { return(new User { _id = user._id, Email = user.Email, Password = user.Password }); }
public IActionResult Index(string userId) { string currentUserId = GetCurrentUserId(); userId = userId ?? currentUserId; DataContract.User user = _userMethods.GetById(userId); if (user == null) { return(NotFound()); } bool isDifferentUser = user.Id != currentUserId; DataContract.User currentUser = isDifferentUser ? _userMethods.GetById(currentUserId) : user; ProfileViewModel model = new ProfileViewModel() { User = user, HasSupervisorLog = _userMethods.HasSupervisorLog(userId), HasTimeSheets = _userMethods.HasTimeSheets(userId), CurrentUserId = currentUserId, IsSupervisingUser = isDifferentUser ? _userMethods.IsSupervisorOf(currentUserId, user.Id) : false }; // user is not the current user // only admins and supervising users can access other profiles ViewData["SecureMode"] = isDifferentUser && !model.IsSupervisingUser && currentUser.Role != ApplicationUserRole.Admin; return(View(model)); }