'occurred using the connection to database 'ESCRestaurantDB' on server '.\SQLEXPRESS' [closed]

[HttpPost("add/{userId}")]
public async Task<IActionResult> Add(int userId, CategoryDto categoryDto)
{
    if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
        return Unauthorized();

    categoryDto.UserId = userId;


    var category = _mapper.Map<Category>(categoryDto);

    _repo.Add(category);

    if (await _unitOfWork.Complete())
        return Ok("Added successfully");

    throw new Exception("Adding Category Falid To Save");
}

This is my Controller, I don't know what should I do, why this Error was shown.

using AutoMapper;
using QRmenu.API.Dtos;
using QRmenu.API.Models;

namespace QRmenu.API.Helpers
{
    public class AutoMapperProfiles : Profile
    {
        public AutoMapperProfiles()
        {
            CreateMap<User, UserForDetailedDto>();
            CreateMap<Item, ItemToReturnDto>()
               .ForMember(dest => dest.ItemImages, opt =>
               {
                   opt.MapFrom(src => src.ItemImages);
               });
                 
            CreateMap<Category, CategoryDto>();
        }
    }
}

This is my Automapper code.

I need help to resolve this problem.

i don't know why this error Showen][1]



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source