first time include all file
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using System.Linq;
|
||||
using CarParkValidationAPI.Datas;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace CarParkValidationAPI.Repository;
|
||||
|
||||
public class Seed
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
public Seed(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public int InsertOneUser()
|
||||
{
|
||||
int id = -1;
|
||||
//password = password
|
||||
string txt = " INSERT INTO \"AdminUser\" ( " +
|
||||
" \"StafflinkNo\", \"FirstName\",\"LastName\", \"Email\", \"AddedOn\", \"RoleType\",\"Active\") " +
|
||||
"VALUES" +
|
||||
" ( '60249360','kham', 'vilaythong', 'kham.vilaythong@gmail.com','2025-09-01', 1, TRUE), " +
|
||||
" ( '60249362', 'Sy', 'vilaythong','sy.vilaythong@gmail.com','2025-09-01', 1, TRUE), " +
|
||||
" ( '60249363', 'Hung', 'Nguyen', 'hung.nguyen@gmail.com', '2025-09-01', 1, TRUE); ";
|
||||
string validationPoint = "INSERT INTO \"ValidationPoint\" (" +
|
||||
"\"DisplayName\", \"Description\",\"Active\" )" +
|
||||
"VALUES" +
|
||||
"('Y', 'MAIN Gate', TRUE), " +
|
||||
"('Y', 'NORTH Gate', TRUE), " +
|
||||
"('Y', 'SOUTH Gate', TRUE) ";
|
||||
|
||||
string concessType = "INSERT INTO \"ConcessionType\" (" +
|
||||
"\"ConcessionDesc\", \"ConcessionDisplay\", \"Active\")" +
|
||||
"VALUES ('Senior Card', 'Y', TRUE)," +
|
||||
"('Student Card', 'Y', TRUE)," +
|
||||
"('Pensioners Card', 'Y', TRUE)," +
|
||||
"('Yunior Card', 'Y', TRUE)";
|
||||
try
|
||||
{
|
||||
int count = _context.AdminUsers.Count();
|
||||
if (count < 1)
|
||||
{
|
||||
var conn = _context.Database.GetDbConnection();
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
var command = conn.CreateCommand();
|
||||
command.CommandText = txt;
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
command.ExecuteNonQuery();
|
||||
command.CommandText = validationPoint;
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
command.ExecuteNonQuery();
|
||||
command.CommandText = concessType;
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
command.ExecuteNonQuery();
|
||||
id = 9;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
id = -1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
id = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
id = -10;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user