static LocationModelBinder() { LocationsCache["bottom-left"] = new Location { X = 0, Y = 0 }; LocationsCache["bottom-right"] = new Location { X = 100, Y = 0 }; LocationsCache["top-left"] = new Location { X = 0, Y = 100 }; LocationsCache["top-right"] = new Location { X = 100, Y = 100 }; }
public static bool TryParse(string input, out Location location) { location = new Location(); var parts = input.Split(','); if (parts.Length != 2) return false; int x, y; if (Int32.TryParse(parts[0], out x) && Int32.TryParse(parts[1], out y)) { location.X = x; location.Y = y; return true; } return false; }
// PUT: api/Locations/5/1,2 public void Put(int id, Location value) { Locations[id - 1].X = value.X; Locations[id - 1].Y = value.Y; }
public void Post(Location value) // No need for [FromUri] with converter/binder { Locations.Add(new LocationInfo { X = value.X, Y = value.Y }); }