//public async Task UpdateUser(int id, string userName , string Email, string password) //{ // _tableName = "User"; // //get the current object with the id // var currentUser = await _getItem.GetUserItems(_tableName, id); // //get the sort keys of the previous one // var currentUserName = currentUser.User.Select(p => p.UserName).FirstOrDefault(); // //delete the current event with id // var response = await _deleteItem.Delete(_tableName, id); // //create a new object with the id and sort key // await _putItem.AddNewUser(id, currentUserName, Email, password); //} public async Task UpdateEvent(int id, string eventType, string eventName, string location, string occurrance, string startTime, string endTime, string notes, bool status) { _tableName = "Event"; //get the current object with the id var currentEvent = await _getItem.GetEventByID(id); //get the sort keys of the previous one var userName = currentEvent.UserName; //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.AddNewEvent(id, userName, eventType, eventName, location, occurrance, startTime, endTime, notes, status); }
public async Task <IActionResult> GetEventByID(int id) { var response = await _getItem.GetEventByID(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); } }