C#
C#

help

Root Question Message

Azi
Azi10/15/2022
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 });
            }
        }


Controller:
[HttpPost]
        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;
        }
Pobiega
Pobiega10/15/2022
Use the debugger to inspect the exception being caught in the controller
Message Not Public

Sign In and Join Server To See

10/15/2022
Message Not Public

Sign In and Join Server To See

10/15/2022
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy