public async Task <IHttpActionResult> PostTutorialClass(TutorialClass tutorialClass)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TutorialClasses.Add(tutorialClass);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (TutorialClassExists(tutorialClass.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = tutorialClass.id }, tutorialClass));
        }
        public async Task <IHttpActionResult> PutTutorialClass(Guid id, TutorialClass tutorialClass)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tutorialClass.id)
            {
                return(BadRequest());
            }

            db.Entry(tutorialClass).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TutorialClassExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> GetTutorialClass(Guid id)
        {
            TutorialClass tutorialClass = await db.TutorialClasses.FindAsync(id);

            if (tutorialClass == null)
            {
                return(NotFound());
            }

            return(Ok(tutorialClass));
        }
        public async Task <IHttpActionResult> DeleteTutorialClass(Guid id)
        {
            TutorialClass tutorialClass = await db.TutorialClasses.FindAsync(id);

            if (tutorialClass == null)
            {
                return(NotFound());
            }

            db.TutorialClasses.Remove(tutorialClass);
            await db.SaveChangesAsync();

            return(Ok(tutorialClass));
        }
Example #5
0
    IEnumerator AddNewStudent()
    {
        matricNum = inputField.GetComponent <Text>().text;
        inputField.GetComponent <Text>().text = " ";


        //creating instance of class
        TutorialClass studentAdd = new TutorialClass();

        studentAdd.matricNo = matricNum;

        //use the JsonUtility.ToJson method to serialize it (convert it) to the JSON format
        string json_remove_student = JsonUtility.ToJson(studentAdd);

        // json now contains: '{"matricNo":<student_matric_number>}'

        //To convert the JSON back into an object, use JsonUtility.FromJson:
        // myObject = JsonUtility.FromJson<MyClass>(json);

        //Convert the json format to byte form to prepare to pass to put api
        byte[] bytes_add_student = System.Text.Encoding.UTF8.GetBytes(json_remove_student);

        //Using UnityWebRequest to do a put request to the database
        using (UnityWebRequest studentAddRequest = UnityWebRequest.Put(baseAddStudentURL, bytes_add_student))
        {
            studentAddRequest.SetRequestHeader("Content-Type", "application/json");

            yield return(studentAddRequest.SendWebRequest());

            if (studentAddRequest.isNetworkError)
            {
                Debug.Log(studentAddRequest.error);
            }
            else
            {
                Debug.Log(studentAddRequest.downloadHandler.text);
            }
        }

        AddedPanel.gameObject.SetActive(true);
    }
Example #6
0
    IEnumerator AddNewStudent()
    {
        string tutorialId = inputField.GetComponent <Text>().text;

        List <string> studentsList = new List <string>();

        studentsList = Student_Creator_List_Script.matricNumberTextArray;
        Debug.Log(studentsList.Count);


        //string json_add_tutorial = JsonUtility.ToJson(studentsList);
        //Debug.Log(json_add_tutorial);


        //creating instance of class
        TutorialClass tutorialAdd = new TutorialClass();

        tutorialAdd.tutorialGroupId = tutorialId;
        tutorialAdd.student         = studentsList;

        //use the JsonUtility.ToJson method to serialize it (convert it) to the JSON format
        string json_add_tutorial = JsonUtility.ToJson(tutorialAdd);

        Debug.Log(json_add_tutorial);
        // json now contains: '{"matricNo":<student_matric_number>}'

        //To convert the JSON back into an object, use JsonUtility.FromJson:
        // myObject = JsonUtility.FromJson<MyClass>(json);

        //Convert the json format to byte form to prepare to pass to put api
        //byte[] bytes_add_tutorial = System.Text.Encoding.UTF8.GetBytes(json_add_tutorial);

        //WWWForm form = new WWWForm();
        //form.AddField("tutorialGroupId", tutorialId);
        //form.AddField("student", json_add_tutorial);

        //Using UnityWebRequest to do a put request to the database
        var tutorialAddRequest = new  UnityWebRequest(baseAddTutorialURL, "POST");

        byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(json_add_tutorial);
        tutorialAddRequest.SetRequestHeader("Content-Type", "application/json");
        tutorialAddRequest.uploadHandler   = (UploadHandler) new UploadHandlerRaw(bodyRaw);
        tutorialAddRequest.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();

        Debug.Log("Status Code: " + tutorialAddRequest.responseCode);

        yield return(tutorialAddRequest.SendWebRequest());

        if (tutorialAddRequest.isNetworkError)
        {
            Debug.Log(tutorialAddRequest.error);
        }
        else
        {
            Debug.Log(tutorialAddRequest.downloadHandler.text);
        }

/*
 *      using (UnityWebRequest tutorialAddRequest = UnityWebRequest.Put(baseAddTutorialURL, json_add_tutorial))
 *      {
 *          tutorialAddRequest.SetRequestHeader("Content-Type", "application/json");
 *
 *          yield return tutorialAddRequest.SendWebRequest();
 *
 *          if (tutorialAddRequest.isNetworkError)
 *          {
 *              Debug.Log(tutorialAddRequest.error);
 *          }
 *          else
 *          {
 *              Debug.Log(tutorialAddRequest.downloadHandler.text);
 *          }
 *      }
 */
        SubmitPanel.gameObject.SetActive(true);
    }