// Post api/courses
        public IEnumerable <CourseInfo> Post([FromUri] int coursesType, [FromBody] KeyContainer keyContainer)
        {
            if (!Enum.IsDefined(typeof(CoursesTakenType), coursesType))
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Course Taken Type must be 0, 1 or 2"));
            }

            string key = keyContainer.GetNormalizedKey();

            SusiParser.Parser parser;
            if (GlobalHost.Instance.TryGetValue(key, out parser))
            {
                try
                {
                    IEnumerable <CourseInfo> info = parser.GetCourses((CoursesTakenType)coursesType);
                    GlobalHost.Instance.Logger.LogCoursesRequest(this.GetClientIp(), (CoursesTakenType)coursesType);
                    return(info);
                }
                catch (WebException)
                {
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadGateway, "Can't load data from susi"));
                }
            }

            // If the key was not found
            throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "No such key / key expired "));
        }
        // I know, I know post should not be used for getting stuff but f**k it
        // POST api/roles
        public IEnumerable <StudentRole> Post([FromBody] KeyContainer key)
        {
            Parser parser;

            if (GlobalHost.Instance.TryGetValue(key.GetNormalizedKey(), out parser))
            {
                return(parser.Roles);
            }

            // If the key was not found
            throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "No such key / key expired "));
        }
        // PUT api/roles
        public void Put([FromUri] int roleIndex, [FromBody] KeyContainer key)
        {
            Parser parser;

            if (GlobalHost.Instance.TryGetValue(key.GetNormalizedKey(), out parser))
            {
                parser.ChangeRole(parser.Roles[roleIndex]);
                return;
            }

            // If the key was not found
            throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "No such key / key expired "));
        }
Example #4
0
        // POST api/student
        public StudentInfo Post([FromBody] KeyContainer keyContainer)
        {
            string key = keyContainer.GetNormalizedKey();

            SusiParser.Parser parser;
            if (GlobalHost.Instance.TryGetValue(key, out parser))
            {
                try
                {
                    StudentInfo info = parser.GetStudentInfo();
                    GlobalHost.Instance.Logger.LogStudentRequest(this.GetClientIp());
                    return(info);
                }
                catch (WebException)
                {
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadGateway, "Can't load data from susi"));
                }
            }

            // If the key was not found
            throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "No such key / key expired "));
        }