add all change in now.
This commit is contained in:
@@ -38,34 +38,39 @@ public class ImportPersonRepository
|
||||
_httpContext = httpContext;
|
||||
}
|
||||
|
||||
public async Task<List<CodeDto<string>>> ImportPerson(FileStream fileStream, string sheetName)
|
||||
public async Task<List<CodeDto<string>>> ImportPerson(MemoryStream fileStream, string sheetName)
|
||||
{
|
||||
Dictionary<string, ImportRelation> relationDic = new();
|
||||
int id;
|
||||
string keypair = ""; //father and mother key
|
||||
List<CodeDto<string>> output = new();
|
||||
Dictionary<int,MappingFatherMother> updateperson = new();
|
||||
CodeDto<string> colums;
|
||||
List<int> ids = new();
|
||||
Person person;
|
||||
Person? uperson;
|
||||
ImportRelation iRelation;
|
||||
MappingFatherMother mitem,faitem,moitem;
|
||||
int fid, mid;
|
||||
MemoryStream msFirstPass = new MemoryStream();
|
||||
// MemoryStream msFirstPass = new MemoryStream();
|
||||
SLDocument sl = new SLDocument(fileStream, sheetName);
|
||||
// There is no way that I can see to get the Rows
|
||||
SLWorksheetStatistics stats = sl.GetWorksheetStatistics();
|
||||
for (int row = 1; row <= stats.NumberOfRows; row++)
|
||||
for (int row = 2; row <= stats.NumberOfRows; row++)
|
||||
{
|
||||
person = new Person();
|
||||
mitem = new();
|
||||
id = sl.GetCellValueAsInt32(row, (int) enumIdx.Id);
|
||||
mitem.IId = id;
|
||||
person.FirstName = sl.GetCellValueAsString(row, (int) enumIdx.FirstName);
|
||||
person.LastName = sl.GetCellValueAsString(row, (int) enumIdx.LastName);
|
||||
person.Email = sl.GetCellValueAsString(row, (int) enumIdx.Email);
|
||||
person.Phone = sl.GetCellValueAsString(row, (int) enumIdx.Phone);
|
||||
person.Image = sl.GetCellValueAsString(row, (int) enumIdx.Image);
|
||||
person.Alive = sl.GetCellValueAsBoolean(row, (int) enumIdx.Alive);
|
||||
person.dob = sl.GetCellValueAsDateTime(row, (int) enumIdx.Dob);
|
||||
person.FirstName = sl.GetCellValueAsString(row, (int) enumIdx.FirstName);
|
||||
person.LastName = sl.GetCellValueAsString(row, (int) enumIdx.LastName);
|
||||
person.Email = sl.GetCellValueAsString(row, (int) enumIdx.Email);
|
||||
person.Phone = sl.GetCellValueAsString(row, (int) enumIdx.Phone);
|
||||
person.Image = sl.GetCellValueAsString(row, (int) enumIdx.Image);
|
||||
person.Alive = sl.GetCellValueAsBoolean(row, (int) enumIdx.Alive);
|
||||
person.dob = sl.GetCellValueAsDateTime(row, (int) enumIdx.Dob);
|
||||
person.Sex = sl.GetCellValueAsString(row, (int) enumIdx.Sex);
|
||||
person.Address = sl.GetCellValueAsString(row, (int) enumIdx.Address);
|
||||
mitem.IFatherId = sl.GetCellValueAsInt32(row, (int) enumIdx.FatherId);
|
||||
mitem.IMotherId = sl.GetCellValueAsInt32(row, (int) enumIdx.MotherId);
|
||||
_context.Persons.Add(person);
|
||||
@@ -101,9 +106,33 @@ public class ImportPersonRepository
|
||||
if (uperson == null) continue;
|
||||
uperson.FatherId = mitem.TFatherId;
|
||||
uperson.MotherId = mitem.TMotherId;
|
||||
if (mitem.TFatherId > 0 && mitem.TMotherId > 0)
|
||||
{
|
||||
keypair = mitem.TFatherId + "," + mitem.TMotherId;
|
||||
if (!relationDic.ContainsKey(keypair))
|
||||
{
|
||||
iRelation = new();
|
||||
iRelation.FatherId = mitem.TFatherId;
|
||||
iRelation.MotherId = mitem.TMotherId;
|
||||
relationDic.Add(keypair, iRelation);
|
||||
}
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
}
|
||||
//finally add relation ship table
|
||||
RelationShip model;
|
||||
foreach (KeyValuePair<string, ImportRelation> item in relationDic)
|
||||
{
|
||||
model = new RelationShip();
|
||||
model.PersonId = item.Value.FatherId;
|
||||
model.RelatePersonId = item.Value.MotherId;
|
||||
_context.RelationShips.Add(model);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,9 @@ using FamilyTreeAPI.Interface;
|
||||
using FamilyTreeAPI.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
//using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -460,20 +461,28 @@ public partial class PersonRepository : IPerson
|
||||
extention = System.IO.Path.GetExtension(fileName);
|
||||
filename = familyId + "_" + sdate + extention;
|
||||
string fullpath = System.IO.Path.Combine(path, filename);
|
||||
/*
|
||||
using (var fileStream = new FileStream(fullpath, FileMode.Create))
|
||||
/*
|
||||
using (var fileStream = new FileStream(fullpath, FileMode.Create))
|
||||
{
|
||||
StreamWriter writer = new StreamWriter(fileStream);
|
||||
writer.Write(newBytes);
|
||||
//writer.BaseStream.Write(bytes, 0, bytes.Length);
|
||||
|
||||
}
|
||||
*/
|
||||
/*
|
||||
using (MemoryStream ms = new MemoryStream(newBytes))
|
||||
{
|
||||
StreamWriter writer = new StreamWriter(fileStream);
|
||||
writer.Write(newBytes);
|
||||
//writer.BaseStream.Write(bytes, 0, bytes.Length);
|
||||
|
||||
}
|
||||
*/
|
||||
using (MemoryStream ms = new MemoryStream(newBytes))
|
||||
{
|
||||
Image image = Image.FromStream(ms);
|
||||
image.Save(fullpath);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
using (FileStream fileStream = new FileStream(fullpath, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
{
|
||||
fileStream.Write(newBytes, 0, newBytes.Length);
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
public async Task<ResultModel<int>> SaveAsync(PersonForSave container)
|
||||
|
||||
@@ -10,9 +10,26 @@ public class Seed
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
public int InsertOneUser()
|
||||
|
||||
public int InsertOneUser()
|
||||
{
|
||||
int id = -1;
|
||||
string sptext = "CREATE OR REPLACE FUNCTION public.usp_search_user( " +
|
||||
" iemail character varying,ifirstname character varying,ilastname character varying) " +
|
||||
" RETURNS TABLE(id integer, fistname character varying, lastname character varying, email character varying," +
|
||||
" stype integer, sactive boolean, srole integer, spassword character varying) " +
|
||||
" AS $$ BEGIN " +
|
||||
" return query SELECT e.id, e.firstname, e.lastname, e.email, e.stype," +
|
||||
" e.sactive, e.srole, e.spassword " +
|
||||
" FROM public.staff e " +
|
||||
" WHERE (iemail = '' or e.email ilike iemail || '%') " +
|
||||
" and (ilastname = '' or e.lastname ilike ilastname || '%') " +
|
||||
" and (ifirstname = '' or e.firstname ilike ifirstname || '%'); "+
|
||||
"END; " +
|
||||
" $$ " +
|
||||
" LANGUAGE 'plpgsql'; ";
|
||||
|
||||
|
||||
int id = -1;
|
||||
//password = password
|
||||
string txt = " INSERT INTO staff ( " +
|
||||
"firstname, lastname, email, phone, stype, srole, spassword, sactive) " +
|
||||
@@ -20,8 +37,9 @@ public class Seed
|
||||
" ( 'kham', 'vilaythong', 'kham.vilaythong@gmail.com', '009', 1, 2, 'cGFzc3dvcmQ=', true), " +
|
||||
" ( 'sy', 'vilaythong', 'sy.vilaythong@gmail.com', '007', 1, 2, 'cGFzc3dvcmQ=', true), " +
|
||||
" ( 'Hung', 'Nguyen', 'hung.gnuyen@gmail.com', '008', 1, 2, 'cGFzc3dvcmQ=', true); ";
|
||||
string workertxt = "INSERT INTO person ( firstname, lastname,email,phone,address,dob ,alive, fatherId, image, sex)" +
|
||||
"VALUES " +
|
||||
|
||||
string workertxt = "INSERT INTO person ( firstname, lastname,email,phone,address,dob ,alive, fatherId, image, sex) " +
|
||||
" VALUES " +
|
||||
" ('Ho 1','Tran', 'Ho.Tran@hotmail.com', '002', '1 Cabramatta','1960-09-01', true, 0,'', 'M'), " +
|
||||
" ('Jimmy 2','Tran', 'Ho.Tran@hotmail.com', '003', '34 Cabramatta','1980-09-01', true, 1,'','M'), " +
|
||||
" ('Joe 3','Tran', 'Joe.Tran@hotmail.com', '006', '32 Cabramatta','1980-10-01', true, 1,'','M'), " +
|
||||
@@ -51,6 +69,11 @@ public class Seed
|
||||
|
||||
conn.Open();
|
||||
var command = conn.CreateCommand();
|
||||
command.CommandText = sptext;
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command = conn.CreateCommand();
|
||||
command.CommandText = txt;
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
command.ExecuteNonQuery();
|
||||
@@ -74,9 +97,10 @@ public class Seed
|
||||
id = 1;
|
||||
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
id = -10;
|
||||
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -11,12 +11,9 @@ CREATE OR REPLACE FUNCTION public.usp_search_user(
|
||||
iemail character varying,
|
||||
ifirstname character varying,
|
||||
ilastname character varying)
|
||||
RETURNS TABLE(id integer, fistname character varying, lastname character varying, email character varying, stype integer, sactive boolean, srole integer, spassword character varying)
|
||||
LANGUAGE 'plpgsql'
|
||||
COST 100
|
||||
VOLATILE PARALLEL UNSAFE
|
||||
ROWS 1000
|
||||
|
||||
RETURNS TABLE(id integer, fistname character varying, lastname character varying, email character varying,
|
||||
stype integer, sactive boolean, srole integer, spassword character varying)
|
||||
|
||||
AS $BODY$
|
||||
begin
|
||||
return query SELECT
|
||||
|
||||
Reference in New Issue
Block a user