Beispiel #1
0
        // POST: api/Student
        public async Task <HttpResponseMessage> PostAsync([FromBody] Student.Data.Models.Student newStudent)
        {
            var data = await studentsRepo.AddStudentAsync(newStudent);

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ObjectContent <object>(new
                {
                    Message = "new student created"
                }, Configuration.Formatters.JsonFormatter)
            });
        }
Beispiel #2
0
        // PUT: api/Student/5
        public async Task <HttpResponseMessage> PutAsync(Guid id, [FromBody] Student.Data.Models.Student student)
        {
            student.ID = id;
            var data = await studentsRepo.UpdateStudentAsync(student);

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ObjectContent <object>(new
                {
                    Message = "the student updated successfully"
                }, Configuration.Formatters.JsonFormatter)
            });
        }
Beispiel #3
0
        public async Task <bool> UpdateStudent(Student.Data.Models.Student student)
        {
            bool                updated    = false;
            string              strPayload = JsonConvert.SerializeObject(student);
            HttpContent         c          = new StringContent(strPayload, Encoding.UTF8, "application/json");
            HttpResponseMessage response   = await _httpclient.PutAsync("api/student/" + student.ID, c).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                var contents = await response.Content.ReadAsStringAsync();

                updated = true;
            }
            return(updated);
        }
Beispiel #4
0
        public async Task <Student.Data.Models.Student> AddStudent(Student.Data.Models.Student student)
        {
            student.ID = Guid.NewGuid();
            string              strPayload = JsonConvert.SerializeObject(student);
            HttpContent         c          = new StringContent(strPayload, Encoding.UTF8, "application/json");
            HttpResponseMessage response   = await _httpclient.PostAsync("api/student/", c).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                var contents = await response.Content.ReadAsStringAsync();

                return(student);
            }
            return(new Student.Data.Models.Student());
        }
Beispiel #5
0
        public async Task <Student.Data.Models.Student> AddStudent(Student.Data.Models.Student student)
        {
            student.ID = Guid.NewGuid();
            _workerQueueProducer.SendMessage(student, "add");

            /*string strPayload = JsonConvert.SerializeObject(student);
             * HttpContent c = new StringContent(strPayload, Encoding.UTF8, "application/json");
             * HttpResponseMessage response = await _httpclient.PostAsync("api/student/", c).ConfigureAwait(false);
             * if (response.IsSuccessStatusCode)
             * {
             *  var contents = await response.Content.ReadAsStringAsync();
             *  return student;
             * }*/
            return(student);
        }