public async Task UpdateNotification(int id, string senderName, string notificationMsg, bool status) { _tableName = "Notification"; //get the current object with the id var currentNotification = await _getItem.GetNotificationByID(id); //get the sort keys of the previous one var receiverName = currentNotification.ReceiverName; //delete the current event with id var response = await _deleteItem.Delete(_tableName, id.ToString()); //create a new object with the id and sort key await _putItem.AddNewNotification(id, senderName, receiverName, notificationMsg, status); }
public async Task <IActionResult> GetNotificationByID(int id) { var response = await _getItem.GetNotificationByID(id); return(Ok(response)); }
//delete item with primary key "id" public async Task <DeleteItemResponse> Delete(String tableName, string id) { _tableName = tableName; //get the item by id //var deleteItem = await _getItem.GetItems(_tableName, id); //var currentID = deleteItem.Items.Select(p => p.Id); if (_tableName == "User") { var deleteItem = await _getItem.GetUserByName(id); _hashKeyName = "UserName"; _hashKey = id; return(await DeleteUserRequest()); } else { if (_tableName == "Event") { _hashKeyName = "EventID"; _hashKey = id; int eventID = Convert.ToInt32(id); var deleteItem = await _getItem.GetEventByID(eventID); _sortKeyName = "UserName"; _sortKey = deleteItem.UserName; } else if (_tableName == "Notification") //notification { _hashKeyName = "NotificationID"; _hashKey = id; int notificationID = Convert.ToInt32(id); var deleteItem = await _getItem.GetNotificationByID(notificationID); _sortKeyName = "SenderName"; _sortKey = deleteItem.ReceiverName; } else { return(null); } var request = new DeleteItemRequest { TableName = _tableName, Key = new Dictionary <string, AttributeValue> { { _hashKeyName, new AttributeValue { N = _hashKey } }, { _sortKeyName, new AttributeValue { S = _sortKey } } } }; var response = await _dynamoDbClient.DeleteItemAsync(request); return(response); } }