Azi
Azi
CC#
Created by Azi on 2/26/2023 in #help
❔ Can't fix this error code, please help
6 replies
CC#
Created by Azi on 10/15/2022 in #help
Help me again!
I got this error where it says
Error: response status is 500 Here's my code Repository:
public async Task<int> CreateCategory(Category category)
{
var sql = "INSERT INTO Category (Name, WorkspaceId) VALUES (@Name, @WorkspaceId)" +
"SELECT SCOPE_IDENTITY()";
using (var connection = _context.CreateConnection())
{
return await connection.ExecuteScalarAsync<int>(sql, new { category.Name, WorkspaceId = category.Workspace?.Id });
}
}
public async Task<int> CreateCategory(Category category)
{
var sql = "INSERT INTO Category (Name, WorkspaceId) VALUES (@Name, @WorkspaceId)" +
"SELECT SCOPE_IDENTITY()";
using (var connection = _context.CreateConnection())
{
return await connection.ExecuteScalarAsync<int>(sql, new { category.Name, WorkspaceId = category.Workspace?.Id });
}
}
Controller:
public async Task<IActionResult> CreateCategory([FromBody] CategoryCreationDto categoryDto)
{
try
{
var newCategory = await _categoryService.CreateCategory(categoryDto);
return CreatedAtRoute("GetWorkspace", new { id = newCategory.Id }, newCategory);
}
catch (Exception)
{
return StatusCode(500, "Something went wrong");
}
}
public async Task<IActionResult> CreateCategory([FromBody] CategoryCreationDto categoryDto)
{
try
{
var newCategory = await _categoryService.CreateCategory(categoryDto);
return CreatedAtRoute("GetWorkspace", new { id = newCategory.Id }, newCategory);
}
catch (Exception)
{
return StatusCode(500, "Something went wrong");
}
}
Service:
public async Task<Category> CreateCategory(CategoryCreationDto categoryToCreate)
{
var categoryModel = new Category
{
Name = categoryToCreate.Name,
};
categoryModel.Id = await _repository.CreateCategory(categoryModel);
return categoryModel;
}
public async Task<Category> CreateCategory(CategoryCreationDto categoryToCreate)
{
var categoryModel = new Category
{
Name = categoryToCreate.Name,
};
categoryModel.Id = await _repository.CreateCategory(categoryModel);
return categoryModel;
}
4 replies
CC#
Created by Azi on 10/15/2022 in #help
Help! How to fix this?
34 replies