C
C#2y ago
Azi

Help! How to fix this?

Error CS0815 Cannot assign void to an implicitly-typed variable
23 Replies
SG97
SG972y ago
What does CreateCategory return
Azi
Azi2y ago
[HttpPost("AddExpenseToUser/{userId}/{classificationId}/{accountId}", Name = "AddExpenseToUser")]
public async Task<IActionResult> AddExpense(int userId, int classificationId, int accountId, [FromBody] ExpenseCreationDto newExpense)
{
try
{
// Check if account exists
var user = await _userServices.GetUser(userId);
if (user == null)
return NotFound($"User with id {userId} does not exist.");

var newExpenseId = await _expensesServices.AddExpense(userId, classificationId, accountId, newExpense);

return CreatedAtRoute("GetExpenseById", new { id = newExpenseId },
$"The newly added Id is {newExpenseId}");
}
catch (Exception e)
{
_logger.LogError(e.Message);
return StatusCode(500, "Something went wrong");
}
}
[HttpPost("AddExpenseToUser/{userId}/{classificationId}/{accountId}", Name = "AddExpenseToUser")]
public async Task<IActionResult> AddExpense(int userId, int classificationId, int accountId, [FromBody] ExpenseCreationDto newExpense)
{
try
{
// Check if account exists
var user = await _userServices.GetUser(userId);
if (user == null)
return NotFound($"User with id {userId} does not exist.");

var newExpenseId = await _expensesServices.AddExpense(userId, classificationId, accountId, newExpense);

return CreatedAtRoute("GetExpenseById", new { id = newExpenseId },
$"The newly added Id is {newExpenseId}");
}
catch (Exception e)
{
_logger.LogError(e.Message);
return StatusCode(500, "Something went wrong");
}
}
this is the code from my prof I just followed his I dont know what's wrong with my code I have the same as him
SG97
SG972y ago
well, what do you expect _categoryService.CreateCategory to return
Azi
Azi2y ago
the created route maybe?
SG97
SG972y ago
? the service class method
Azi
Azi2y ago
Oh thats what I thought now this is the problem
Azi
Azi2y ago
Azi
Azi2y ago
says that it will return the id of newly created category
SG97
SG972y ago
what's the signature of that method
Azi
Azi2y ago
these suggestions but I dont know if this will work but I think not
Azi
Azi2y ago
so yea this was given yesterday without discussion and I dont't even know what that is
SG97
SG972y ago
do you understand method parameters and return value
Azi
Azi2y ago
yes
SG97
SG972y ago
what are the parameters of _categoryService.CreateCategory and whad does it return
Azi
Azi2y ago
NEW CATEGORY shet ohsht newcategory
SG97
SG972y ago
show the signature of CreateCategory the code assumes it's returning an id
Azi
Azi2y ago
this??? CreateCategory(int WorkspaceId, [FromBody] CategoryCreationDto newCategory)
SG97
SG972y ago
no, the service method _categoryService.CreateCategory
Azi
Azi2y ago
Task<Category> CreateCategory(CategoryCreationDto categoryToCreate);
SG97
SG972y ago
ok, then why are you providing 2 parameters
Azi
Azi2y ago
yea my bad that's why
SG97
SG972y ago
WorkspaceId and newCategory
Azi
Azi2y ago
yea yea