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; }
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 }; }
public void Update(Student item) { var theStudentElement = this.GetStudentElementById(item.Id); theStudentElement.SetAttributeValue("fname", item.FirstName); theStudentElement.SetAttributeValue("lname", item.LastName); this.SaveChanges(); }
public void Delete(Student item) { var theStudentElement = this.GetStudentElementById(item.Id); theStudentElement.Remove(); this.SaveChanges(); }
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; }