/// <summary> /// Write multiple cache operations to data source /// </summary> /// <param name="operations">Collection of <see cref="WriteOperation"/></param> /// <returns>Collection of <see cref="OperationResult"/> to cache</returns> public ICollection <OperationResult> WriteToDataSource(ICollection <WriteOperation> operations) { // initialize collection of results to return to cache ICollection <OperationResult> operationResults = new List <OperationResult>(); // iterate over each operation sent by cache foreach (var item in operations) { // initialize operation result with failure OperationResult operationResult = new OperationResult(item, OperationResult.Status.Failure); // get object from provider cache item FraudRequest value = item.ProviderItem.GetValue <FraudRequest>(); // check if the type is what you need if (value.GetType().Equals(typeof(FraudRequest))) { // initialize variable for confirmation of write operation // perform write command and get confirmation from data source bool result = sqlDatasource.SaveTransaction(value); // if write operation is successful, change status of operationResult if (result) { operationResult.OperationStatus = OperationResult.Status.Success; } } // insert result operation to collect of results operationResults.Add(operationResult); } // send result to cache return(operationResults); }
/// <summary> /// write an operation to data source /// </summary> /// <param name="operation"></param> /// <returns></returns> public OperationResult WriteToDataSource(WriteOperation operation) { // initialize variable for confirmation of write operation bool result = false; // initialize operation result with failure OperationResult operationResult = new OperationResult(operation, OperationResult.Status.Failure); // get value of object FraudRequest value = operation.ProviderItem.GetValue <FraudRequest>(); // check if value is the type you need if (value.GetType().Equals(typeof(FraudRequest))) { // send data to cache for writing result = sqlDatasource.SaveTransaction((FraudRequest)value); // if write operatio is success, change status of operation result if (result) { operationResult.OperationStatus = OperationResult.Status.Success; } } // return result to cache return(operationResult); }