コード例 #1
0
 public void Update(Student item)
 {
     var theStudentElement = this.GetStudentElementById(item.Id);
     theStudentElement.SetAttributeValue("fname", item.FirstName);
     theStudentElement.SetAttributeValue("lname", item.LastName);
     this.SaveChanges();
 }
コード例 #2
0
 public HttpResponseMessage PostStudent(Student newStudent)
 {
     var student = this.repository.Add(newStudent);
     var response = Request.CreateResponse<Student>(HttpStatusCode.Created, student);
     response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = student.Id }));
     return response;
 }
コード例 #3
0
 private Student ParseXmlElementToStudent(XElement element)
 {
     var student = new Student()
     {
         Id = int.Parse(element.Attribute("id").Value),
         FirstName = element.Attribute("fname").Value,
         LastName = element.Attribute("lname").Value
     };
     return student;
 }
コード例 #4
0
        public Student Add(Student item)
        {
            var id = int.Parse(this.DocumentRoot.Attribute("last-id").Value) + 1;
            this.DocumentRoot.SetAttributeValue("last-id", id);
            var newStudentElement = new XElement("student",
                new XAttribute("id", id),
                new XAttribute("fname", item.FirstName),
                new XAttribute("lname", item.LastName));
            this.DocumentRoot.Add(newStudentElement);
            this.SaveChanges();

            return new Student()
            {
                Id = id,
                FirstName = item.FirstName,
                LastName = item.LastName
            };
        }
コード例 #5
0
 public void Delete(Student item)
 {
     var theStudentElement = this.GetStudentElementById(item.Id);
     theStudentElement.Remove();
     this.SaveChanges();
 }