首页 > 解决方案 > 无法隐式转换类型 C# .Net Core 问题

问题描述

我想要做的是使用.NET Core 制作一个 api 服务,我在其中从数据库制作一个数组.... ]'。

我是否朝着正确的方向前进?我正在尝试制作我的 Angular 客户端可以使用的 api 服务。

动作控制器

    public class ActionsController : ControllerBase
{
    private IActionService _actionService;
    public ActionsController(IActionService actionService)
    {
        _actionService = actionService;
    }

    //GET: api/Actions
    [HttpGet]
    public IActionResult GetActions(string userId, string sessionId)
    {
        // TODO: Figure out when recurseOnMenus is true, pass it accordingly instead of forcing false.
        DbrAction[] dbrActions = _actionService.GetActions(userId, sessionId);
        return Ok(dbrActions);
    }

行动服务

public interface IActionService
{
    Action[] GetActions(string userId, string sessionId);

}

public class ActionService : IActionService
{
    private DataContext _context;

    public ActionService(DataContext context)
    {
        _context = context;
    }

    public DbrAction[] GetActions(string sessionId)
    {
        UserStateHelper ush = new UserStateHelper();
        UserState us = ush.CreateUserState(sessionId);
        XioTable xt = new XioTable(us, T.User);
        DbrUser user = (DbrUser)xt.LoadSingleRow(us.UserTag, C.User_DefaultActionTag);

        Actions[] actions = {};
        List<DbrAction> dbrActions = new List<DbrAction>();
        xt = new XioTable(us, T.Action);
        xt.SelectCols(C.Action_Description, C.Action_ActionName, C.Action_FolderTag, C.Action_ActionType, C.Action_PrimaryTable);
        xt.LoadData();
        foreach (DbrAction action in xt.GetAllRows(C.Action_FolderTag))
        {
            if (!DbrAction.IsTableDeprecated(action.PrimaryTable))
            {
                if (action.ActionType == ActionType.View || action.ActionType == ActionType.Dashboard)
                    dbrActions.Add(action);
            }
        }
        us.Completed(LogEntryType.GetStartupProfileData, null);
        return dbrActions.ToArray();
    }

    public Action[] GetActions(string userId, string sessionId)
    {
        throw new NotImplementedException();
    }

标签: c#.net-coreasp.net-core-webapi

解决方案


推荐阅读