/// <summary> /// Add one car to db by turning JSON into XML, /// looping through each node in XML document to check for values /// to assign to Car object properties. /// </summary> /// <returns>A number representing the id of the newly created car object.</returns> public int AddCar() { Car car = new Car(); string xmlString = OperationContext.Current.RequestContext.RequestMessage.ToString(); XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlString); foreach (XmlNode node in doc.DocumentElement.ChildNodes) { switch (node.Name) { case (nameof(Car.Model)): car.Model = node.InnerText; break; case (nameof(Car.ManufacturingYear)): car.ManufacturingYear = Convert.ToInt32(node.Value); break; case (nameof(Car.RegistrationNo)): car.RegistrationNo = node.InnerText; break; case (nameof(Car.Brand)): car.Brand = node.InnerText; break; default: break; } } return(api.AddCar(car)); }
public int AddCar(Car car) { return(api.AddCar(car)); }