Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# id为{0}的用户不存在,_C#_Sql Server_Visual Studio_Asp.net Web Api - Fatal编程技术网

C# id为{0}的用户不存在,

C# id为{0}的用户不存在,,c#,sql-server,visual-studio,asp.net-web-api,C#,Sql Server,Visual Studio,Asp.net Web Api,我正在开发一个使用WebAPI和IntegrationApI提供商项目的学习管理系统。运行解决方案时,会出现以下错误 这是出现的例外情况。我无法理解这个例外,尼瑟无法通过互联网找到解决方案。请帮忙 代码: 命名空间集成提供程序 { 公共类测试集成提供程序2:IPplatform { 公共ID2LAppContext valenceAppContext{get;set;} 公共HostSpec ValeneHost{get;set;} 公共ID2LUserContext valenceUserCo

我正在开发一个使用WebAPI和IntegrationApI提供商项目的学习管理系统。运行解决方案时,会出现以下错误 这是出现的例外情况。我无法理解这个例外,尼瑟无法通过互联网找到解决方案。请帮忙

代码: 命名空间集成提供程序 { 公共类测试集成提供程序2:IPplatform {

公共ID2LAppContext valenceAppContext{get;set;} 公共HostSpec ValeneHost{get;set;} 公共ID2LUserContext valenceUserContext{get;set;} 公共ID2LUserContext ValuedMinContext{get;set;} 私有int_CurrentUserId; public int GetCurrentUserId() { 如果(_CurrentUserId==0) { var allUsers=UserRepository.GetAllUsers(); 如果(allUsers!=null&&allUsers.Count>0) _CurrentUserId=allUsers.First().UserId; 其他的 _CurrentUserId=1; } 返回_CurrentUserId; } public void SetCurrentUserId(int userId) { _CurrentUserId=用户ID; } 公共平台用户GetUserName(int userId) { var user=UserRepository.GetUserById(userId); if(user==null) 抛出新异常(string.Format(“id为{0}的用户不存在,请先添加用户”,userId)); 返回new PlatformUser(){UserName=user.Name,Id=userId}; //创建web服务的代理对象 //调用网络服务 //rteurn值 //连接到数据库 //执行sql //t返回结果 //返回AllUsersList.Single(x=>x.Id==userId); //返回新平台用户(){Id=userId,FirstName=“Student”,LastName=“0”,ExternalEmail=”bsuser1@brightscribe.com" }; } 公共列表GetUserIdsForCourse(int courseId) { var users=UserRepository.GetAllUsersByCourseId(courseId); 返回users.Select(x=>newplatformuser(){Id=x.UserId,FirstName=x.Name,UserName=x.Name}).ToList(); //var userList=AllUsersList.Where(x=>x.LastName.Contains(courseId.ToString()).ToList(); //AddRange(AllUsersList.Where(x=>x.LastName.Equals(“ALL”,StringComparison.CurrentCultureIgnoreCase)); //返回用户列表; } 列出ipplatform.GetAllUsers(int-courseId) { 回归冲积层; } 公开名单 { 收到 { var users=UserRepository.GetAllUsers(); 返回users.Select(x=>newplatformuser(){Id=x.UserId,FirstName=x.Name,UserName=x.Name}).ToList(); //返回新列表() //{ //new PlatformUser(){Id=0,FirstName=“学生00”,LastName=“1,2”,ExternalEmail=”bsuser0@brightscribe.com" }, //new PlatformUser(){Id=1,FirstName=“Student 01”,LastName=“1,2,3”,ExternalEmail=”bsuser1@brightscribe.com" }, //新平台用户(){Id=2,FirstName=“学生02”,LastName=“2,3”,ExternalEmail=”bsuser2@brightscribe.com" }, //新平台用户(){Id=3,FirstName=“学生03”,LastName=“1,3”,ExternalEmail=”bsuser3@brightscribe.com" }, //新平台用户(){Id=4,FirstName=“学生04”,LastName=“3”,ExternalEmail=”bsuser12@brightscribe.com" }, //新平台用户(){Id=5,FirstName=“学生05”,LastName=“2”,ExternalEmail=”bsuser13@brightscribe.com" }, //new PlatformUser(){Id=6,FirstName=“学生06”,LastName=“1”,ExternalEmail=”bsuser14@brightscribe.com" }, //新平台用户(){Id=7,FirstName=“学生07”,LastName=“1,3”,ExternalEmail=”bsuser15@brightscribe.com" }, //new PlatformUser(){Id=8,FirstName=“Developer 08”,LastName=“ALL”,ExternalEmail=”bsuser4@brightscribe.com" }, //new PlatformUser(){Id=9,FirstName=“Developer 09”,LastName=“ALL”,ExternalEmail=”bsuser5@brightscribe.com" }, //new PlatformUser(){Id=10,FirstName=“Developer 10”,LastName=“ALL”,ExternalEmail=”bsuser6@brightscribe.com" }, //new PlatformUser(){Id=11,FirstName=“讲师11”,LastName=“所有”,ExternalEmail=”bsuser7@brightscribe.com" }, //new PlatformUser(){Id=12,FirstName=“讲师12”,LastName=“所有”,ExternalEmail=”bsuser8@brightscribe.com" }, //new PlatformUser(){Id=13,FirstName=“讲师13”,LastName=“所有”,ExternalEmail=”bsuser9@brightscribe.com" }, //new PlatformUser(){Id=14,FirstName=“Admin 14”,LastName=“ALL”,ExternalEmail=”bsuser10@brightscribe.com" }, //new PlatformUser(){Id=15,FirstName=“Manager 15”,LastName=“ALL”,ExternalEmail=”bsuser11@brightscribe.com" } //}; } } 公开列出所有课程 { 收到 { var courses=CourseManager.GetAllCourse(); 返回课程。选择(x=>newplatformcourse(){Id=x.CourseId,CourseName=x.Name}); //返回新列表() //{ //新平台课程(){Id=1,CourseName=“Course1”}, //新平台课程(){Id=2,CourseName=“Course2”}, //新平台课程(){Id=3,CourseName=“Course3”}, //}; } } 公共列表GetCoursesForUser(int userId) { //TODO:需要一个过滤器,以便只获取用户的课程。 var courses=CourseManager.GetAllCourse(); 返回课程。选择(x=>newplatformcourse(){Id=x.CourseId,CourseName=x.Name}); //var user=AllUsersList.Where(x=>x.Id==userId.Single(); //if(user.LastName.StartsWith(“全部”)) //把这个还给我。所有课程; //List courseIds=user.LastName.Split(新字符[]{',},StringSplitOptions.RemoveEmptyEntries.ToList(); //List userCourseList=新列表();
    public ID2LAppContext valenceAppContext { get; set; }
    public HostSpec valenceHost { get; set; }
    public ID2LUserContext valenceUserContext { get; set; }
    public ID2LUserContext valenceAdminContext { get; set; }

    private int _CurrentUserId;
    public int GetCurrentUserId()
    {
        if (_CurrentUserId == 0)
        {
            var allUsers = UserRepository.GetAllUsers();

            if (allUsers != null && allUsers.Count>0)
                _CurrentUserId = allUsers.First().UserId;
            else
                _CurrentUserId = 1;
        }

        return _CurrentUserId;
    }

    public void SetCurrentUserId(int userId)

    {
        _CurrentUserId = userId;
    }

    public PlatformUser GetUserName(int userId)
    {
        var user = UserRepository.GetUserById(userId);
        if (user == null)
            throw new Exception(string.Format("user with id:{0} does not exist, please add the user first", userId));

        return new PlatformUser() { UserName = user.Name, Id = userId };

        // create a proxy object of web service 
        // invoke that web serice
        // rteurn value

        // coonect to db
        // execute the sql
        // rteurn the result

        //return AllUsersList.Single(x => x.Id == userId);

        //return new PlatformUser() { Id = userId, FirstName = "Student", LastName = "0", ExternalEmail = "bsuser1@brightscribe.com" };
    }

    public List<PlatformUser> GetUserIdsForCourse(int courseId)
    {
        var users = UserRepository.GetAllUsersByCourseId(courseId);

        return users.Select(x => new PlatformUser() { Id = x.UserId, FirstName = x.Name, UserName = x.Name }).ToList();

        //var userList = AllUsersList.Where(x => x.LastName.Contains(courseId.ToString())).ToList();
        //userList.AddRange(AllUsersList.Where(x => x.LastName.Equals("ALL", StringComparison.CurrentCultureIgnoreCase)));
        //return userList;
    }

    List<PlatformUser> IPlatform.GetAllUsers(int courseId)
    {
        return AllUsersList;
    }

    public List<PlatformUser> AllUsersList
    {
        get
        {
            var users = UserRepository.GetAllUsers();
            return users.Select(x => new PlatformUser() { Id = x.UserId, FirstName = x.Name, UserName = x.Name }).ToList();

            //return new List<PlatformUser>()
            //{
            //new PlatformUser() {Id=0, FirstName = "Student 00", LastName = "1,2", ExternalEmail = "bsuser0@brightscribe.com" },
            //new PlatformUser() {Id=1, FirstName = "Student 01", LastName = "1,2,3", ExternalEmail = "bsuser1@brightscribe.com" },
            //new PlatformUser() {Id=2, FirstName = "Student 02", LastName = "2,3", ExternalEmail = "bsuser2@brightscribe.com" },
            //new PlatformUser() {Id=3, FirstName = "Student 03", LastName = "1,3", ExternalEmail = "bsuser3@brightscribe.com" },
            //new PlatformUser() {Id=4, FirstName = "Student 04", LastName = "3", ExternalEmail = "bsuser12@brightscribe.com" },
            //new PlatformUser() {Id=5, FirstName = "Student 05", LastName = "2", ExternalEmail = "bsuser13@brightscribe.com" },
            //new PlatformUser() {Id=6, FirstName = "Student 06", LastName = "1", ExternalEmail = "bsuser14@brightscribe.com" },
            //new PlatformUser() {Id=7, FirstName = "Student 07", LastName = "1,3", ExternalEmail = "bsuser15@brightscribe.com" },
            //new PlatformUser() {Id=8, FirstName = "Developer 08", LastName = "ALL", ExternalEmail = "bsuser4@brightscribe.com" },
            //new PlatformUser() {Id=9, FirstName = "Developer 09", LastName = "ALL", ExternalEmail = "bsuser5@brightscribe.com" },
            //new PlatformUser() {Id=10, FirstName = "Developer 10", LastName = "ALL", ExternalEmail = "bsuser6@brightscribe.com" },
            //new PlatformUser() {Id=11, FirstName = "Instructor 11", LastName = "ALL", ExternalEmail = "bsuser7@brightscribe.com" },
            //new PlatformUser() {Id=12, FirstName = "Instructor 12", LastName = "ALL", ExternalEmail = "bsuser8@brightscribe.com" },
            //new PlatformUser() {Id=13, FirstName = "Instructor 13", LastName = "ALL", ExternalEmail = "bsuser9@brightscribe.com" },
            //new PlatformUser() {Id=14, FirstName = "Admin 14", LastName = "ALL", ExternalEmail = "bsuser10@brightscribe.com" },
            //new PlatformUser() {Id=15, FirstName = "Manager 15", LastName = "ALL", ExternalEmail = "bsuser11@brightscribe.com" }
            //};
        }
    }

    public List<PlatformCourse> AllCourses
    {
        get
        {
            var courses = CourseManager.GetAllCourse();

            return courses.Select(x => new PlatformCourse() { Id = x.CourseId, CourseName = x.Name }).ToList();
            //return new List<PlatformCourse>()
            //{
            //    new PlatformCourse(){ Id = 1, CourseName = "Course1"},
            //    new PlatformCourse(){ Id = 2, CourseName = "Course2"},
            //    new PlatformCourse(){ Id = 3, CourseName = "Course3"},
            //};
        }
    }

    public List<PlatformCourse> GetCoursesForUser(int userId)
    {
        //TODO: need a filter so that only the courses for the users are obtained.
        var courses = CourseManager.GetAllCourse();
        return courses.Select(x => new PlatformCourse() { Id = x.CourseId, CourseName = x.Name }).ToList();

        //var user = AllUsersList.Where(x => x.Id == userId).Single();
        //if (user.LastName.StartsWith("ALL"))
        //    return this.AllCourses;

        //List<string> courseIds = user.LastName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();

        //List<PlatformCourse> userCourseList = new List<PlatformCourse>();
        //foreach (var requiredCourseId in courseIds)
        //{
        //    userCourseList.Add(AllCourses.Where(x => x.Id.ToString().Equals(requiredCourseId)).Single());
        //}

        //return userCourseList;
    }

    public PlatformUserRole GetUserRole(int courseId, int userId)
    {
        //UserEnrollment userEnrolled = UserRepository.GetUserEnrollmentById(userId, courseId);
        //return (userEnrolled == null) ? PlatformUserRole.None : (PlatformUserRole)userEnrolled.UserRole;


        var user = UserRepository.GetUserById(userId);
        if (user == null)
            return PlatformUserRole.Admin;

        if (!string.IsNullOrEmpty(user.Phone))
        {
            if (user.Phone.Contains("StudentServices"))
                return PlatformUserRole.StudentServices;

            if (user.Phone.Contains("Student"))
                return PlatformUserRole.Student;

            if (user.Phone.Contains("Developer"))
                return PlatformUserRole.Developer;

            if (user.Phone.Contains("Instructor"))
                return PlatformUserRole.Instructor;

            if (user.Phone.Contains("Manager"))
                return PlatformUserRole.Manager;

            if (user.Phone.Contains("Admin"))
                return PlatformUserRole.Admin;

            if (user.Phone.Contains("Employer"))
                return PlatformUserRole.Employer;
        }

        if (user.Name.Contains("StudentServices"))
            return PlatformUserRole.StudentServices;
        else if (user.Name.Contains("Student"))
            return PlatformUserRole.Student;
        else if (user.Name.Contains("Admin"))
            return PlatformUserRole.Admin;
        else if (user.Name.Contains("Applicant"))
            return PlatformUserRole.Applicant;
        else if (user.Name.Contains("Developer"))
            return PlatformUserRole.Developer;
        else if (user.Name.Contains("Employer"))
            return PlatformUserRole.Employer;
        else if (user.Name.Contains("Instructor"))
            return PlatformUserRole.Instructor;
        else if (user.Name.Contains("Manager"))
            return PlatformUserRole.Manager;

        else if (user.Name.Contains("Instructor"))
            return PlatformUserRole.Instructor;
        else if (user.Name.Contains("Instructor"))
            return PlatformUserRole.Instructor;
        else
        {
            return PlatformUserRole.Admin;
        }

        //switch (userId)
        //{
        //    case 0:
        //    case 1:
        //    case 2:
        //    case 3:
        //    case 4:
        //    case 5:
        //    case 6:
        //    case 7:
        //        role = PlatformUserRole.Student;
        //        break;
        //    case 8:
        //    case 9:
        //    case 10:
        //        role = PlatformUserRole.Developer;
        //        break;
        //    case 11:
        //    case 12:
        //    case 13:
        //        role = PlatformUserRole.Instructor;
        //        break;
        //    case 14:
        //        role = PlatformUserRole.Admin;
        //        break;
        //    case 15:
        //        role = PlatformUserRole.Manager;
        //        break;
        //    default:
        //        break;
        //}
        //return role;
    }

    public bool UpdateGradeData(int courseId, int userId, decimal grade, int d2lGradeId)
    {
        Trace.WriteLine(string.Format("UpdateGradeData invoked for , UserId:{0}, Grade:{1}, d2l:{2}", userId, grade, d2lGradeId));
        return true;
    }

    public List<PlatformTrigger> GetTriggers(int courseId)
    {
        return new List<PlatformTrigger>()
        {
            new PlatformTrigger(){ Id=0, ModuleId="TriggerModule0"},
            new PlatformTrigger(){ Id=1, ModuleId="TriggerModule1"},
            new PlatformTrigger(){ Id=2, ModuleId="TriggerModule2"},
            new PlatformTrigger(){ Id=3, ModuleId="TriggerModule3"},
            new PlatformTrigger(){ Id=4, ModuleId="TriggerModule4"},
            new PlatformTrigger(){ Id=5, ModuleId="TriggerModule5"}
        };
    }


    public bool CheckTriggers(int courseId, int userid, int d2LTriggerId)
    {
        return true;
    }


    public List<PlatformUser> GetAllInstructors(int courseId)
    {
        var courseUsers = GetUserIdsForCourse(courseId);
        return courseUsers.Where(x => GetUserRole(courseId, x.Id) == PlatformUserRole.Instructor).ToList();
        //List<PlatformUser> alUsers = PlatformFactory.CreateProvider().GetUserIdsForCourse(courseId);
        //List<PlatformUser> instructorsList = new List<PlatformUser>();
        //foreach (var user in alUsers)
        //{
        //    PlatformUserRole userRole = PlatformFactory.CreateProvider().GetUserRole(courseId, user.Id);
        //    if (userRole == PlatformUserRole.Instructor)
        //        instructorsList.Add(user);
        //}

        //return instructorsList;
    }

    public bool TranscriptionsCompleted(int courseId, int userId, int d2lNextChapterId)
    {
        Trace.WriteLine(string.Format("TranscriptionsCompleted invoked for , CourseId:{0}, UserId:{1}, d2lNextChapterId:{2}", courseId, userId, d2lNextChapterId));
        return true;
    }

    public bool TranscriptionsIncomplete(int courseId, int userId, int d2LNextChapterId)
    {
        throw new NotImplementedException("only available in brightspace API");
    }

    public EnrollmentData API_GetUserEnrollmentById(int userId, int orgUnitId)
    {
        throw new NotImplementedException("only available in brightspace API");
    }

    public List<TestDetail> GetTestCompletionDates(int courseId, int userId)
    {
        return new List<TestDetail>()
        {
            new TestDetail(){ Grade = 1.1m, GradeWeight = 1.11m, TestId = 1, TestName = "Test1", TestPassed = false },
            new TestDetail(){ Grade = 2.2m, GradeWeight = 2.22m, TestId = 2, TestName = "Test2", TestPassed = false}
        };
    }

    public GradeValue GetGradeValue(int courseId, int userId, int gradeId)
    {
        throw new NotImplementedException("only available in brightspace API");
    }


    public List<DropboxFolder> GetDropboxFolders(int courseId)
    {
        throw new NotImplementedException("only available in brightspace API");
    }

    public List<EntityDropbox> GetDropboxFolderSubmissions(int courseId, int id)
    {
        throw new NotImplementedException("only available in brightspace API");
    }

    public GradeValue GetFinalGradeValue(int courseId, int userId, int gradeId)
    {
        throw new NotImplementedException("only available in brightspace API");
    }

    public MemoryStream GetDropboxFolderSubmissionFile(int courseId, int folderId, int submissionId, int fileId)
    {
        throw new NotImplementedException("only available in brightspace API");
    }


}