public async Task <OperationResult> Delete(ChangeQueueItem queueItem) { try { using (var client = _httpClientProvider.GetClient()) { var response = await client.DeleteAsync(string.Format(_endPointFormatString, queueItem.ChangedItemId)); if (response.IsSuccessStatusCode) { return(OperationResult.CreateSuccessResult($"Successfully Deleted item {queueItem.ChangedItemId}")); } else { return(OperationResult.CreateFailure(response.ReasonPhrase)); } } } catch (Exception ex) { return(OperationResult.CreateFailure(ex)); } }
async Task ProcessDelete(ChangeQueueItem queueItem) { try { var deleteHandler = _serviceLocator.ResolveDeleteHandler(queueItem.ChangedItemType, queueItem.ChangedItemIdentifierType); var result = await deleteHandler.Delete(queueItem); UpdateQueueItem(queueItem, result.Success); if (result.Success) { var respository = _repositoryServiceLocator.ResolveRepository(queueItem.ChangedItemType, queueItem.ChangedItemIdentifierType); var itemJson = JsonConvert.DeserializeObject(queueItem.ChangedItemId, queueItem.ChangedItemType); respository.Delete(itemJson); } } catch (Exception ex) { //handle exceptions todo. } }
async Task ProcessCreate(ChangeQueueItem queueItem) { try { var createHandler = _serviceLocator.ResolveCreateHandler(queueItem.ChangedItemType, queueItem.ChangedItemIdentifierType); var result = await createHandler.Create(queueItem); UpdateQueueItem(queueItem, result.Success); //should these be to functions? and or have thier own try catches? if (result.Success) { var respository = _repositoryServiceLocator.ResolveRepository(queueItem.ChangedItemType, queueItem.ChangedItemIdentifierType); var newItem = JsonConvert.DeserializeObject(result.Result, queueItem.ChangedItemType); respository.Upsert(newItem); } } catch (Exception ex) { //handle exceptions todo. } }
KeyValuePair <Type, Type> GetQueueItemTypes(ChangeQueueItem queueItem) { var valuePair = QueueItemTypes.FirstOrDefault(x => x.Key.FullName == queueItem.ChangeItemTypeString); return(valuePair); }