public int Update(Widgets widgets) { int response = _widgetProvider.UpdateWidgets(widgets); return(response); }
public override Response Post(IList <IDataObject> dataObjects) { Response response = new Response(); string objectType = String.Empty; if (dataObjects == null || dataObjects.Count == 0) { Status status = new Status(); status.Level = StatusLevel.Warning; status.Messages.Add("Data object list provided was empty."); response.Append(status); return(response); } try { objectType = ((GenericDataObject)dataObjects.FirstOrDefault()).ObjectType; switch (objectType.ToUpper()) { case "WIDGET": foreach (IDataObject dataObject in dataObjects) { Status status = new Status(); Widget widget = FormWidget(dataObject); string identifier = widget.Id.ToString(); status.Identifier = identifier; int result = _widgetProvider.UpdateWidgets(new Widgets { widget }); string message = String.Empty; if (result == 0) { message = String.Format( "Data object [{0}] posted successfully.", identifier ); } else { message = String.Format( "Error while posting data object [{0}].", identifier ); } status.Messages.Add(message); response.Append(status); } break; default: throw new Exception("Invalid object type provided"); } } 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); }