ASP.NET Core Web API 我应该选择什么项目类型?

ASP.NET Core Web API What project type should i choose?

我很困惑我应该使用什么类型的项目,因为我是 ASP.NET 和整个编程的新手。

我得到了创建网页来管理员工的说明。

指令是:

员工必须在服务器上,数据必须保存在 SQL 数据库中(永远只有一个客户端)。

我应该使用的技术:

客户端

服务器

我尝试使用 ASP.NET Core Web App 在 ASP.NET Core 5.0 中构建应用程序,但我不确定它是否是正确的项目类型,因为说明中的服务器技术是 ASP.NET 核心网站 API.

在说明中,我学习了 ASP.NET Web API 2,但只有没有界面的 Web api 项目示例。

我真的不知道该怎么办。项目我乱删了好几次

有人可以帮助我吗?谢谢!

"I'm confused what type of project should I use because I'm newbie to ASP.NET and programing as a whole?"

Based on your description and requirement you should have one client-side (frontend) project and one server-side (backend project) within the same solution. You could follow the steps below.

Client: Frondtend Project:

For client-side vue.js project you could take the project like below. Please see the screen shot.

Note: For more details steps you could check our official document here

Server: Backend Project:

For dealing with client-side vue.js request you should have one server-side backend project which should be kind of asp.net core web API project. You could take this like below.

Note: For more details steps you could check our official document here

Project Request Architecture:

Your vue.js client-side which we call front-end application will sent request to your asp.net core web API application controller. For example your employees controller then you should return required data from your controller which you will bind to your client-side project eventually. Your project architecture should look like below:

For details you could check official document here

Your Domain Class:

根据您的描述,您应该有 employee domain class 例如一个假想的 employee class,如下所示:

public class Employee 
    {
        public Guid Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
    }

ApplicationDbContext:

public class ApplicationDbContext: DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }
        public DbSet<Employee> Employee { get; set; }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //  base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Employee>().ToTable("Employee");
        }
       
    }

Note:

You should similar SQL Table on your database, to make is easier here I am providing the Database script as well.

SQL Script:

CREATE TABLE [Employee]
(
    Id UNIQUEIDENTIFIER PRIMARY KEY default NEWID(),
    [FirstName] [varchar](50) NULL,
    [LastName] [varchar](50) NULL,
    [Email] [varchar](50) NULL,
 
)

Controller:

    [Route("api/[controller]")]
    [ApiController]
    public class UnitOfWorkEmployeeController : ControllerBase
    {
        private readonly ILogger<UnitOfWorkEmployeeController> _logger;
        private readonly IUnitOfWork _unitOfWork;

        public UnitOfWorkEmployeeController(
            ILogger<UnitOfWorkEmployeeController> logger,
            IUnitOfWork unitOfWork)
        {
            _logger = logger;
            _unitOfWork = unitOfWork;
        }

        [HttpGet]
        public async Task<IActionResult> Get()
        {

            var employees = await _unitOfWork.Employee.All();
            return Ok(employees);
        }
        
    }
}

Note: If you need more details steps reagrding the best practice and implementation you

希望以上步骤能指导您相应地实现您的要求。