forked from MDCPS/DamageAssessment_Backend
		
	Added Azure sql setup for User access micro service
This commit is contained in:
		| @ -0,0 +1,21 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using System.ComponentModel.DataAnnotations.Schema; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
| namespace DamageAssesment.Api.UsersAccess.Db | ||||
| { | ||||
|     public class Role | ||||
|     { | ||||
|         [Key] | ||||
|         public int Id { get; set; } | ||||
|  | ||||
|         [StringLength(100)] | ||||
|         [Required] | ||||
|         public string Name { get; set; } | ||||
|  | ||||
|         // add a status field | ||||
|  | ||||
|         [StringLength(100)] | ||||
|         public string? Description { get; set; } | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,17 @@ | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using System.ComponentModel.DataAnnotations.Schema; | ||||
|  | ||||
| namespace DamageAssesment.Api.UsersAccess.Db | ||||
| { | ||||
|     public  class Token | ||||
|     { | ||||
|         [Key] | ||||
|         public int Id { get; set; } | ||||
|         [Required] | ||||
|         [ForeignKey("User")] | ||||
|         public int UserId { get; set; } | ||||
|         public string? RefreshToken { get; set; } | ||||
|         public bool? IsActive { get; set; } | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,31 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using System.ComponentModel.DataAnnotations.Schema; | ||||
| using System.Text.Json.Serialization; | ||||
|  | ||||
| namespace DamageAssesment.Api.UsersAccess.Db | ||||
| { | ||||
|     public class User | ||||
|     { | ||||
|         [Key] | ||||
|         public int Id { get; set; } | ||||
|  | ||||
|         [ForeignKey("Employee")] | ||||
|         public int EmployeeId { get; set; } | ||||
|  | ||||
|         [Required] | ||||
|         [StringLength(50)] | ||||
|         public string EmployeeCode { get; set; } | ||||
|  | ||||
|         [ForeignKey("Role")] | ||||
|         [Required] | ||||
|         public int RoleId { get; set; } | ||||
|         [Required] | ||||
|         public bool IsActive { get; set; } = true; | ||||
|  | ||||
|         [Required] | ||||
|         public DateTime CreateDate { get; set; } = DateTime.Now; | ||||
|  | ||||
|         public DateTime? UpdateDate { get; set; } | ||||
|  | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,39 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.Extensions.Configuration; | ||||
|  | ||||
| namespace DamageAssesment.Api.UsersAccess.Db | ||||
| { | ||||
|     public class UsersAccessDbContext : DbContext | ||||
|     { | ||||
|         public DbSet<Db.User> Users { get; set; } | ||||
|         public DbSet<Db.Role> Roles { get; set; } | ||||
|         public DbSet<Db.Token> Tokens { get; set; } | ||||
|         private IConfiguration _Configuration { get; set; } | ||||
|         public UsersAccessDbContext(DbContextOptions options, IConfiguration configuration) : base(options) | ||||
|         { | ||||
|             _Configuration = configuration; | ||||
|         } | ||||
|         protected override void OnConfiguring(DbContextOptionsBuilder options) | ||||
|         { | ||||
|             // connect to sql server with connection string from app settings | ||||
|             options.UseSqlServer(_Configuration.GetConnectionString("UsersAccessConnection")); | ||||
|         } | ||||
|  | ||||
|         protected override void OnModelCreating(ModelBuilder modelBuilder) | ||||
|         { | ||||
|             base.OnModelCreating(modelBuilder); | ||||
|  | ||||
|             modelBuilder.Entity<User>() | ||||
|                 .Property(item => item.Id) | ||||
|                 .ValueGeneratedOnAdd(); | ||||
|  | ||||
|             modelBuilder.Entity<Role>() | ||||
|             .Property(item => item.Id) | ||||
|             .ValueGeneratedOnAdd(); | ||||
|  | ||||
|             modelBuilder.Entity<Token>() | ||||
|             .Property(item => item.Id) | ||||
|             .ValueGeneratedOnAdd(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user