public override Response Delete(string objectType, IList<string> identifiers) { Response response = new Response(); if (identifiers == null || identifiers.Count == 0) { Status status = new Status(); status.Level = StatusLevel.Warning; status.Messages.Add("Nothing to delete."); response.Append(status); return response; } try { foreach (string identifier in identifiers) { Status status = new Status(); status.Identifier = identifier; string message = String.Empty; try { if (String.IsNullOrWhiteSpace(identifier)) throw new ApplicationException("Identifier can not be blank or null."); string url = GenerateUrl(objectType, identifier); _webClient.MakeDeleteRequest(url); message = String.Format("DataObject [{0}] deleted successfully.", identifier); status.Messages.Add(message); response.Append(status); } catch { message = String.Format("Error while deleting dataObject [{0}].", identifier); status.Messages.Add(message); response.Append(status); } } } catch (Exception ex) { _logger.ErrorFormat("Error while deleting a list of data objects of type [{0}]: {1}", objectType, ex); throw new Exception("Error while deleting a list of data objects of type [" + objectType + "].", ex); } return response; }
public override Response Post(IList<IDataObject> dataObjects) { Response response = new Response(); string objectType = String.Empty; bool isNew = false; string identifier = String.Empty; objectType = ((GenericDataObject)dataObjects.FirstOrDefault()).ObjectType; DataObject objDef = _dataDictionary.dataObjects.Find(p => p.objectName.ToUpper() == objectType.ToUpper()); if (dataObjects == null || dataObjects.Count == 0) { Status status = new Status(); status.Level = StatusLevel.Warning; status.Messages.Add("Data object list provided is empty."); response.Append(status); return response; } try { foreach (IDataObject dataObject in dataObjects) { identifier = String.Empty; Status status = new Status(); string message = String.Empty; try { String objectString = FormJsonObjectString(dataObject); foreach (KeyProperty dataProperty in objDef.keyProperties) { string value = Convert.ToString(dataObject.GetPropertyValue(dataProperty.keyPropertyName)); if (String.IsNullOrEmpty(value)) isNew = true; else identifier = value; break; } if (!String.IsNullOrEmpty(identifier)) { int count = Get(objectType, new List<string>() { identifier }).Count; if (count > 0) isNew = false; else isNew = true; } string url = GenerateUrl(objectType); if (isNew) ///Post data { _webClient.MakePostRequest(url, objectString); } else ///put data { _webClient.MakePutRequest(url, objectString); } message = String.Format("Data object [{0}] posted successfully.", identifier); status.Messages.Add(message); response.Append(status); } catch (Exception ex) { message = String.Format("Error while posting data object [{0}].", identifier); status.Messages.Add(message); response.Append(status); } } } catch (Exception ex) { _logger.ErrorFormat("Error while processing a list of data objects of type [{0}]: {1}", objectType, ex); throw new Exception("Error while processing a list of data objects of type [" + objectType + "].", ex); } return response; }