v1.0.1
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
@@ -20,11 +21,50 @@ namespace CC.Yi.API.Controllers
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
||||
#region
|
||||
//下面,经典的 增删改查 即为简易--Yi意框架
|
||||
//注意:请确保你的数据库中存在合理的数据
|
||||
#endregion
|
||||
[HttpGet]
|
||||
public IActionResult Test()
|
||||
public IActionResult GetTest()//查
|
||||
{
|
||||
var data = _studentBll.GetAllEntities().ToList();
|
||||
return Content(Common.JsonFactory.JsonToString(data));
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult AddTest()//增
|
||||
{
|
||||
List<student> students = new List<student>() {new student { name = "学生a" } ,new student { name="学生d"} };
|
||||
_studentBll.Add(students);
|
||||
return Content("ok");
|
||||
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult RemoveTest()//删
|
||||
{
|
||||
|
||||
if (_studentBll.Delete(u=>u.name=="学生a"))
|
||||
{
|
||||
return Content("ok");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Content("no");
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult UpdateTest()//改
|
||||
{
|
||||
if (_studentBll.Update(new student { id=2, name = "学生a" }, "name"))
|
||||
{
|
||||
return Content("ok");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Content("no");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
40
CC.Yi.API/Migrations/20210320082935_yi2.Designer.cs
generated
Normal file
40
CC.Yi.API/Migrations/20210320082935_yi2.Designer.cs
generated
Normal file
@@ -0,0 +1,40 @@
|
||||
// <auto-generated />
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
[DbContext(typeof(DataContext))]
|
||||
[Migration("20210320082935_yi2")]
|
||||
partial class yi2
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.4")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("CC.Yi.Model.student", b =>
|
||||
{
|
||||
b.Property<int>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
b.ToTable("student");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
31
CC.Yi.API/Migrations/20210320082935_yi2.cs
Normal file
31
CC.Yi.API/Migrations/20210320082935_yi2.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace CC.Yi.API.Migrations
|
||||
{
|
||||
public partial class yi2 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "name",
|
||||
table: "student",
|
||||
type: "nvarchar(max)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "name",
|
||||
table: "student",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)",
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,8 @@ namespace CC.Yi.API.Migrations
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<int>("name")
|
||||
.HasColumnType("int");
|
||||
b.Property<string>("name")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("id");
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using CC.Yi.DAL;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
@@ -13,7 +15,22 @@ namespace CC.Yi.API
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
var host = CreateHostBuilder(args).Build();
|
||||
var scope = host.Services.CreateScope();
|
||||
{
|
||||
var services = scope.ServiceProvider;
|
||||
try
|
||||
{
|
||||
var context = services.GetRequiredService<Model.DataContext>();
|
||||
DbContentFactory.Initialize(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var logger = services.GetRequiredService<ILogger<Program>>();
|
||||
logger.LogError(ex, "An error occurred while seeding the database.");
|
||||
}
|
||||
}
|
||||
host.Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStringBySQL": "server=.;Database=cctest;UId=sa;PWD=Qz52013142020.",
|
||||
"ConnectionStringByMySQL": "Data Source=49.235.212.122;Database=GraduationProject;User ID=root;Password=Qz52013142020.;pooling=true;port=3306;sslmode=none;CharSet=utf8;"
|
||||
"ConnectionStringByMySQL": "Data Source=.;Database=cctest;User ID=root;Password=Qz52013142020.;pooling=true;port=3306;sslmode=none;CharSet=utf8;"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user