健管師API
This commit is contained in:
parent
f198f55935
commit
d32d9175eb
@ -38,7 +38,8 @@ public class JwtUtils : IJwtUtils
|
||||
new Claim("id", user.id.ToString()),
|
||||
new Claim("firstname", user.firstname ?? ""), // 加入 firstname
|
||||
new Claim("lastname", user.lastname ?? ""), // 加入 lastname
|
||||
new Claim("level", user.level ?? "") // 加入 lastname
|
||||
new Claim("level", user.level ?? ""), // 加入 lastname
|
||||
new Claim("guid", user.guid ?? "") // 加入 lastname
|
||||
}),
|
||||
Expires = DateTime.UtcNow.AddDays(7),
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||
|
@ -36,7 +36,7 @@ namespace TCM_API.Controllers.lamiter
|
||||
var data = await(from c in _context.company_detail_table
|
||||
select new
|
||||
{
|
||||
campant_name = c.campant_name,
|
||||
company_name = c.company_name,
|
||||
guid = c.guid
|
||||
|
||||
}).ToListAsync();
|
||||
@ -73,7 +73,7 @@ namespace TCM_API.Controllers.lamiter
|
||||
Company_detail_table company_detail_table = new Company_detail_table();
|
||||
company_detail_table.guid = new_guid.ToString();
|
||||
company_detail_table.data_create_time = DateTime.Now;
|
||||
company_detail_table.campant_name = add_company.lastname;
|
||||
company_detail_table.company_name = add_company.username;
|
||||
|
||||
//創建 公司帳號
|
||||
User user = new User();
|
||||
@ -85,6 +85,7 @@ namespace TCM_API.Controllers.lamiter
|
||||
user.level = "8";
|
||||
user.guid = new_guid.ToString();
|
||||
|
||||
//儲存
|
||||
_context.company_detail_table.Add(company_detail_table);
|
||||
_context.user_table.Add(user);
|
||||
try
|
||||
|
106
TCM_API/Controllers/manage/Health_detail_tableController.cs
Normal file
106
TCM_API/Controllers/manage/Health_detail_tableController.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TCM_API.Entities;
|
||||
using TCM_API.Models;
|
||||
using TCM_API.Models.manage;
|
||||
using TCM_API.Services;
|
||||
using TCM_API.ViewModels;
|
||||
|
||||
namespace TCM_API.Controllers.manage
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class Health_detail_tableController : Controller
|
||||
{
|
||||
private readonly SqlContext _context;
|
||||
|
||||
public Health_detail_tableController(SqlContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
#region 獲取所有健管師
|
||||
/// <summary>
|
||||
/// 獲取所有健管師
|
||||
/// </summary>
|
||||
[HttpGet("get_all_health-")]
|
||||
public async Task<ActionResult<object>> GetHealth_all_deatil()
|
||||
{
|
||||
|
||||
var data = await (from c in _context.health_detail_table
|
||||
select new
|
||||
{
|
||||
health_name = c.health_name,
|
||||
guid = c.guid
|
||||
|
||||
}).ToListAsync();
|
||||
return Ok(data);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 新增健管師
|
||||
/// <summary>
|
||||
/// 新增健管師
|
||||
/// </summary>
|
||||
[HttpPost("Add_health")]
|
||||
public async Task<ActionResult<Health_detail_table>> PostHealth_detail_table_1(Add_health add_health)
|
||||
{
|
||||
// 創建Guid
|
||||
Guid new_guid = Guid.NewGuid();
|
||||
|
||||
// 創建 健管師詳細
|
||||
Health_detail_table health_detail_table = new Health_detail_table();
|
||||
health_detail_table.guid = new_guid.ToString();
|
||||
health_detail_table.company_guid = add_health.company_guid;
|
||||
health_detail_table.data_create_time = DateTime.Now;
|
||||
health_detail_table.health_name = add_health.username;
|
||||
|
||||
//創建健管師帳號
|
||||
User user = new User();
|
||||
user.firstname = "healther";
|
||||
user.lastname = add_health.lastname;
|
||||
user.email = add_health.email;
|
||||
user.password = add_health.password;
|
||||
user.username = add_health.username;
|
||||
user.level = "6";
|
||||
user.guid = new_guid.ToString();
|
||||
|
||||
//儲存
|
||||
_context.health_detail_table.Add(health_detail_table);
|
||||
_context.user_table.Add(user);
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (Health_detail_tableExists(health_detail_table.guid))
|
||||
{
|
||||
return Conflict();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private bool Health_detail_tableExists(string id)
|
||||
{
|
||||
return _context.health_detail_table.Any(e => e.guid == id);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ namespace TCM_API.Models
|
||||
{
|
||||
public class Company_detail_table
|
||||
{
|
||||
public string? campant_name { get; set; }
|
||||
public string? company_name { get; set; }
|
||||
public string? guid { get; set; }
|
||||
public DateTime? data_create_time { get; set; }
|
||||
|
||||
|
15
TCM_API/Models/manage/Health_detail_table.cs
Normal file
15
TCM_API/Models/manage/Health_detail_table.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace TCM_API.Models.manage
|
||||
{
|
||||
public class Health_detail_table
|
||||
{
|
||||
public string? health_name { get; set; }
|
||||
public string? guid { get; set; }
|
||||
public string? company_guid { get; set; }
|
||||
public DateTime? data_create_time { get; set; }
|
||||
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int id { get; set; }
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TCM_API.Models;
|
||||
using TCM_API.Entities;
|
||||
using TCM_API.Models.manage;
|
||||
|
||||
|
||||
namespace TCM_API.Services
|
||||
@ -25,6 +26,7 @@ namespace TCM_API.Services
|
||||
//public DbSet<Test_0525> test_0525 { get; set; } = null!; //<Test_0330> Model名稱 test_0330 SQL名稱
|
||||
public DbSet<User> user_table { get; set; } = null!;
|
||||
public DbSet<Company_detail_table> company_detail_table { get; set; } = null!;
|
||||
public DbSet<Health_detail_table> health_detail_table { get; set; } = null!;
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
|
||||
@ -32,6 +34,7 @@ namespace TCM_API.Services
|
||||
//builder.Entity<Test_0525>().HasKey(o => new { o.user_id }); //Primary Key
|
||||
builder.Entity<User>().HasKey(o => new { o.id }); //Primary Key
|
||||
builder.Entity<Company_detail_table>().HasKey(o => new { o.guid });
|
||||
builder.Entity<Health_detail_table>().HasKey(o => new { o.guid });
|
||||
|
||||
}
|
||||
|
||||
|
14
TCM_API/ViewModels/Add_health.cs
Normal file
14
TCM_API/ViewModels/Add_health.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace TCM_API.ViewModels
|
||||
{
|
||||
public class Add_health
|
||||
{
|
||||
public string? guid { get; set; }
|
||||
public string? firstname { get; set; }
|
||||
public string? lastname { get; set; }
|
||||
public string? email { get; set; }
|
||||
public string? username { get; set; }
|
||||
public string? password { get; set; }
|
||||
public string? level { get; set; }
|
||||
public string? company_guid { get; set; }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user