C
C#3y ago
Azi

Help! How to fix this?

Error CS0815 Cannot assign void to an implicitly-typed variable
23 Replies
SG97
SG973y ago
What does CreateCategory return
Azi
AziOP3y 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
SG973y ago
well, what do you expect _categoryService.CreateCategory to return
Azi
AziOP3y ago
the created route maybe?
SG97
SG973y ago
? the service class method
Azi
AziOP3y ago
Oh thats what I thought now this is the problem
Azi
AziOP3y ago
Azi
AziOP3y ago
says that it will return the id of newly created category
SG97
SG973y ago
what's the signature of that method
Azi
AziOP3y ago
these suggestions but I dont know if this will work but I think not
Azi
AziOP3y ago
so yea this was given yesterday without discussion and I dont't even know what that is
SG97
SG973y ago
do you understand method parameters and return value
Azi
AziOP3y ago
yes
SG97
SG973y ago
what are the parameters of _categoryService.CreateCategory and whad does it return
Azi
AziOP3y ago
NEW CATEGORY shet ohsht newcategory
SG97
SG973y ago
show the signature of CreateCategory the code assumes it's returning an id
Azi
AziOP3y ago
this??? CreateCategory(int WorkspaceId, [FromBody] CategoryCreationDto newCategory)
SG97
SG973y ago
no, the service method _categoryService.CreateCategory
Azi
AziOP3y ago
Task<Category> CreateCategory(CategoryCreationDto categoryToCreate);
SG97
SG973y ago
ok, then why are you providing 2 parameters
Azi
AziOP3y ago
yea my bad that's why
SG97
SG973y ago
WorkspaceId and newCategory
Azi
AziOP3y ago
yea yea
Want results from more Discord servers?
Add your server