public void Update(Venue venue) { if(venue.HasPendingEdits) { throw new ApiException( "Cannot edit venue pending approval: " + venue.PartnerVenueId); } var updateResource = RESOURCE + venue.Id; Save(venue, updateResource, Method.PUT); }
public void Create(Venue venue) { Save(venue, RESOURCE, Method.POST); }
void Save(Venue venue, string saveResource, Method method) { var restRequest = GetRestRequest(venue, saveResource, method); try { var response = restClient.Execute(restRequest); if (response.StatusCode != HttpStatusCode.Created && response.StatusCode != HttpStatusCode.OK) { throw new ApiException("Error saving venue: " + response.Content); } } catch (Exception ex) { throw new ApiException(ex.Message); } }
public VenueRequest(Venue venue, string saveResource, Method method) { if(venue.HasPendingEdits && method != Method.POST) { throw new ApiException( "Cannot edit venue pending approval: " + venue.PartnerVenueId); } Venue = venue; Resource = saveResource; Method = method; }
IRestRequest GetRestRequest(Venue venue, string getResource, Method method) { var restRequest = requestFactory.Create(getResource, method); restRequest.RequestFormat = DataFormat.Json; string data = restRequest.JsonSerializer.Serialize(venue.ToMessage()); data = Encoding.ASCII.GetString(Encoding.UTF8.GetBytes(data)); restRequest.AddParameter("application/json", data, ParameterType.RequestBody); restRequest.Timeout = 500; return restRequest; }