put in new ui and backend store image to table
This commit is contained in:
@@ -3,6 +3,7 @@ using FamilyTreeAPI.Repository;
|
||||
|
||||
namespace FamilyTreeAPI.Controllers;
|
||||
|
||||
using DocumentFormat.OpenXml.Drawing.Charts;
|
||||
using FamilyTreeAPI.Interface;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
@@ -115,9 +116,30 @@ public class FileUploadController : ControllerBase
|
||||
public async Task<IActionResult> DownloadPersonPhoto(DownloadFileCriteria criteria)
|
||||
{
|
||||
|
||||
var result = await _personPhoto.DownloadPersonPhoto(criteria.Id, criteria.FileName);
|
||||
var result = await _personPhoto.DownloadPersonPhoto(criteria.Id,criteria.PhotoType ,criteria.FileName);
|
||||
if (result.StatusCode > 0)
|
||||
return File(result.Data.Content, result.Data.ContentType, result.Data.FileName);
|
||||
else
|
||||
return NotFound("not found image");
|
||||
}
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> DownloadPersonPhoto64(DownloadFileCriteria criteria)
|
||||
{
|
||||
|
||||
return File(result.Data.Content, result.Data.ContentType, result.Data.FileName);
|
||||
var result = await _personPhoto.DownloadPersonPhoto(criteria.Id,criteria.PhotoType ,criteria.FileName);
|
||||
if (result.StatusCode > 0)
|
||||
{
|
||||
byte[] file64 = result.Data.Content;
|
||||
string rval = Convert.ToBase64String(file64);
|
||||
ResultModel<string> retval = new() {
|
||||
Data = rval,
|
||||
StatusCode = 1,
|
||||
Message = ""
|
||||
};
|
||||
return Ok(retval);
|
||||
}
|
||||
else
|
||||
return NotFound("not found image");
|
||||
}
|
||||
[HttpPost("[action]")]
|
||||
public async Task<ActionResult> DeletePersonPhoto(DeleteFileCriteria criteria)
|
||||
@@ -127,8 +149,18 @@ public class FileUploadController : ControllerBase
|
||||
if ( criteria.Id > 0)
|
||||
{
|
||||
|
||||
ret = await _personPhoto.DeletePersonPhoto(criteria.Id);
|
||||
ret = await _personPhoto.DeletePersonPhoto(criteria.Id, criteria.PhotoType);
|
||||
}
|
||||
return Ok(ret);
|
||||
}
|
||||
[HttpPost("[action]")]
|
||||
public async Task<ActionResult> DeletePersonPhotoById(DeleteCriteria<int> criteria)
|
||||
{
|
||||
|
||||
ResultModel<int> ret = new();
|
||||
|
||||
ret = await _personPhoto.DeletePersonPhotoById(criteria.Id);
|
||||
|
||||
return Ok(ret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace FamilyTreeAPI.Controllers
|
||||
{
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> UploadImage(IFormFile file)
|
||||
{
|
||||
|
||||
@@ -15,16 +15,19 @@ public class DownloadFileCriteria
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public int PhotoType {get; set;}
|
||||
}
|
||||
public class UploadCriteria
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public int PersonId { get; set; }
|
||||
public int? PhotoType {get; set;}
|
||||
public int PhotoType {get; set;}
|
||||
public IFormFile File { get; set; }
|
||||
}
|
||||
public class DeleteFileCriteria
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Filename { get; set; }
|
||||
public int PhotoType {get; set;}
|
||||
}
|
||||
@@ -2,6 +2,12 @@
|
||||
{
|
||||
public class Helpers
|
||||
{
|
||||
public static string GetFileExtension(string fileName)
|
||||
{
|
||||
string result = System.IO.Path.GetExtension(fileName);
|
||||
|
||||
return result;
|
||||
}
|
||||
public static string GetFileContent(string extension)
|
||||
{
|
||||
string contentType = "";
|
||||
|
||||
@@ -5,8 +5,9 @@ namespace FamilyTreeAPI.Interface;
|
||||
public interface IPersonPhoto
|
||||
{
|
||||
Task<ResultModel<int>> SaveAsync(UploadCriteria criteria);
|
||||
Task<ResultModel<FileContent>> DownloadPersonPhoto(int id, string? filename);
|
||||
Task<ResultModel<FileContent>> DownloadPersonPhoto(int id, int photoType, string filename);
|
||||
|
||||
Task<ResultModel<int>> DeletePersonPhoto(int id);
|
||||
Task<ResultModel<int>> DeletePersonPhoto(int id, int photoType);
|
||||
Task<ResultModel<int>> DeletePersonPhotoById(int id);
|
||||
Task<ResultModel<List<PersonPhotoDto>>> LoadPersonPhoto(int personId);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using FamilyTreeAPI.Entities;
|
||||
using FamilyTreeAPI.Helper;
|
||||
using FamilyTreeAPI.Interface;
|
||||
using FamilyTreeAPI.Models;
|
||||
using HotChocolate.CostAnalysis.Types;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FamilyTreeAPI.Repository
|
||||
@@ -31,12 +32,12 @@ namespace FamilyTreeAPI.Repository
|
||||
dto.PhotoType = model.PhotoType;
|
||||
return dto;
|
||||
}
|
||||
private PersonPhoto FillModel(PersonPhoto model, int personId, string filename)
|
||||
private PersonPhoto FillModel(PersonPhoto model, int personId, int photoType, string filename)
|
||||
{
|
||||
|
||||
model.PersonId = personId;
|
||||
model.Photo = filename;
|
||||
model.PhotoType = System.IO.Path.GetExtension(filename);
|
||||
model.PhotoType = photoType.ToString(); //System.IO.Path.GetExtension(filename);
|
||||
|
||||
return model;
|
||||
}
|
||||
@@ -46,8 +47,8 @@ namespace FamilyTreeAPI.Repository
|
||||
int statuscode = 0;
|
||||
string error = "";//Other
|
||||
string photoType = "2"; //
|
||||
if (criteria.PhotoType.HasValue)
|
||||
photoType = criteria.PhotoType.Value.ToString();
|
||||
if (criteria.PhotoType > 0)
|
||||
photoType = criteria.PhotoType.ToString();
|
||||
HttpContext? httpContext = _httpContext.HttpContext;
|
||||
string loginName = "";
|
||||
if (httpContext != null)
|
||||
@@ -64,8 +65,8 @@ namespace FamilyTreeAPI.Repository
|
||||
PersonPhoto model;
|
||||
|
||||
model = new();
|
||||
model.PhotoType = photoType;
|
||||
model = FillModel(model,criteria.PersonId, formfile.FileName);
|
||||
|
||||
model = FillModel(model,criteria.PersonId, criteria.PhotoType,formfile.FileName);
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
@@ -93,14 +94,15 @@ namespace FamilyTreeAPI.Repository
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<FileContent>> DownloadPersonPhoto(int id, string? filename)
|
||||
public async Task<ResultModel<FileContent>> DownloadPersonPhoto(int personId, int photoType, string filename)
|
||||
{
|
||||
|
||||
int statusCode = -1;
|
||||
string error = "";
|
||||
string extension = "";
|
||||
PersonPhoto? model = null;
|
||||
FileContent fileContent = new();
|
||||
if (id < 1)
|
||||
if (personId < 1)
|
||||
{
|
||||
var rlist = await _context.PersonPhotos.Where(x => x.Photo == filename).ToListAsync();
|
||||
if (rlist != null)
|
||||
@@ -111,19 +113,26 @@ namespace FamilyTreeAPI.Repository
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
model = await _context.PersonPhotos.FindAsync(id);
|
||||
var rlist = await _context.PersonPhotos.Where (x => x.PersonId == personId && photoType.ToString() == x.PhotoType).ToListAsync();
|
||||
for ( int i = 0; i < rlist.Count; i++)
|
||||
{
|
||||
model = rlist[i];
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
fileContent.ContentType = Helpers.GetFileContent(model.PhotoType);
|
||||
extension = Helpers.GetFileExtension(model.Photo);
|
||||
fileContent.ContentType = Helpers.GetFileContent(extension);
|
||||
fileContent.Content = (byte[])model.ImagePhoto;
|
||||
fileContent.FileName = model.Photo;
|
||||
statusCode = 1;
|
||||
}
|
||||
|
||||
return new ResultModel<FileContent>()
|
||||
{
|
||||
Data = fileContent,
|
||||
@@ -132,20 +141,69 @@ namespace FamilyTreeAPI.Repository
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<int>> DeletePersonPhoto(int id)
|
||||
public async Task<ResultModel<int>> DeletePersonPhoto(int personId, int photoType)
|
||||
{
|
||||
int result = default(int);
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
PersonPhoto? model;
|
||||
try
|
||||
{
|
||||
PersonPhoto? model = await _context.PersonPhotos.FindAsync(id);
|
||||
if (model != null)
|
||||
if (photoType < 1)
|
||||
{
|
||||
_context.PersonPhotos.Remove(model);
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
List<PersonPhoto> list = await _context.PersonPhotos.Where ( x => x.PersonId == personId).ToListAsync();
|
||||
for (int i = 0; i< list.Count; i++)
|
||||
{
|
||||
model = list[i];
|
||||
_context.PersonPhotos.Remove(model);
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
List<PersonPhoto> list = await _context.PersonPhotos.Where ( x => x.PersonId == personId && x.PhotoType == photoType.ToString()).ToListAsync();
|
||||
for (int i = 0; i< list.Count; i++)
|
||||
{
|
||||
model = list[i];
|
||||
_context.PersonPhotos.Remove(model);
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
}
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<int>> DeletePersonPhotoById(int id)
|
||||
{
|
||||
int result = default(int);
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
PersonPhoto? model = await _context.PersonPhotos.FindAsync(id);
|
||||
if (model != null)
|
||||
{
|
||||
|
||||
_context.PersonPhotos.Remove(model);
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -283,7 +283,7 @@ public partial class PersonRepository : IPerson
|
||||
node.Key = item.Id.ToString();
|
||||
node.Type = type;
|
||||
if (item.Image != null)
|
||||
node.Data.Image = await LoadPersonImage(item.Id,item.Image);
|
||||
node.Data.Image = await LoadPersonImage(item.Id, (int) enumPhotoType.Profile, item.Image);
|
||||
|
||||
node.Icon = "T";
|
||||
node.StyleClass = getStyleClass(node.Icon);
|
||||
@@ -392,7 +392,7 @@ public partial class PersonRepository : IPerson
|
||||
citem.Data = new();
|
||||
citem.Label = pName;
|
||||
if (image != null)
|
||||
citem.Data.Image = await LoadPersonImage(personId,image);
|
||||
citem.Data.Image = await LoadPersonImage(personId, (int) enumPhotoType.Profile, image);
|
||||
|
||||
citem.Icon = "P";
|
||||
|
||||
@@ -413,7 +413,7 @@ public partial class PersonRepository : IPerson
|
||||
child.Type = type;
|
||||
image = dto.Image;
|
||||
if (image != null)
|
||||
child.Data.Image = await LoadPersonImage(dto.Id,image);
|
||||
child.Data.Image = await LoadPersonImage(dto.Id,(int) enumPhotoType.Profile, image);
|
||||
child.Icon = "C";
|
||||
child.StyleClass = getStyleClass(child.Icon);
|
||||
child.Label = dto.FirstName;
|
||||
@@ -750,13 +750,13 @@ public partial class PersonRepository : IPerson
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<string> LoadPersonImage(int personId,string filename)
|
||||
private async Task<string> LoadPersonImage(int personId, int photoType, string filename)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
// DownloadFileCriteria criteria = new() { FileName = filename };
|
||||
|
||||
var resultModel = await _personPhoto.DownloadPersonPhoto(personId, filename);
|
||||
var resultModel = await _personPhoto.DownloadPersonPhoto(personId, photoType , filename);
|
||||
//if (resultModel.Data.Content)
|
||||
string base64String = Convert.ToBase64String(resultModel.Data.Content);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<th>Id</th>
|
||||
<th pSortableColumn="description">Description<p-sortIcon field="description"></p-sortIcon>
|
||||
</th>
|
||||
|
||||
<th>Photo Type</th>
|
||||
<th>Action</th>
|
||||
|
||||
</tr>
|
||||
@@ -25,6 +25,7 @@
|
||||
<tr>
|
||||
<td>{{item.id}}</td>
|
||||
<td >{{item.photo}}</td>
|
||||
<td>{{item.photoType}}</td>
|
||||
<td>
|
||||
|
||||
<button pButton type="button" icon="pi pi-times"
|
||||
|
||||
@@ -128,7 +128,7 @@ doRemove(id: number): void {
|
||||
}
|
||||
else
|
||||
{
|
||||
const deletepersonPhoto$ = this.personService.deletePersonPhotoFile(id);
|
||||
const deletepersonPhoto$ = this.personService.deletePersonPhotoFileById(id);
|
||||
this.subscription.add(deletepersonPhoto$.subscribe(
|
||||
{
|
||||
next: x => {
|
||||
|
||||
@@ -15,7 +15,10 @@ export enum mState {
|
||||
Modified = 1,
|
||||
New =2,
|
||||
};
|
||||
|
||||
export enum enumPhoto {
|
||||
Profile = 1,
|
||||
Other = 2
|
||||
}
|
||||
export enum userRole {
|
||||
Normal = 1,
|
||||
Admin = 2,
|
||||
|
||||
@@ -6,7 +6,7 @@ import { FormControl, ReactiveFormsModule, UntypedFormBuilder, Validators } from
|
||||
import { Subject, Subscription} from 'rxjs';
|
||||
import { ConfirmationService, MessageService } from 'primeng/api';
|
||||
import { DatePickerModule } from 'primeng/datepicker';
|
||||
import { Code, RelationShipView, Person, mState, RelationShip, PersonPhotoDto} from '../models';
|
||||
import { Code, RelationShipView, Person, mState, RelationShip, PersonPhotoDto, enumPhoto } from '../models';
|
||||
import { AppSettingService, LookupService, Utils } from '../shares';
|
||||
import { PersonService } from './person.service';
|
||||
import { ButtonModule } from 'primeng/button';
|
||||
@@ -22,6 +22,7 @@ import { TooltipModule } from 'primeng/tooltip';
|
||||
import { AutoFocusModule } from 'primeng/autofocus';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { PhotoList } from '../attachphoto/photolist';
|
||||
import { InputNumberDesignTokens } from '@primeuix/themes/types/inputnumber';
|
||||
|
||||
export interface FileUploadEvent {
|
||||
originalEvent: HttpEvent<any>;
|
||||
@@ -190,9 +191,9 @@ doDeleteFile(): void {
|
||||
this.profileFile = null;
|
||||
}
|
||||
doDeleteImage(fileName:string) : void {
|
||||
const familyId = this.adminuserForm.value.id;
|
||||
const data = { fileName, familyId };
|
||||
const delete$ = this.personService.deleteUploadFile(data);
|
||||
const personId = this.adminuserForm.value.id;
|
||||
const photoType = enumPhoto.Profile;
|
||||
const delete$ = this.personService.deletePersonPhotoFile(personId, photoType);
|
||||
this.subscription.add(delete$.subscribe(
|
||||
{
|
||||
next: x => {
|
||||
@@ -358,7 +359,7 @@ assignValue(item:Person): void {
|
||||
}
|
||||
if (item.image && item.image.length > 0)
|
||||
{
|
||||
this.loadImage(item.image);
|
||||
this.loadImage(item.image, item.id, enumPhoto.Profile);
|
||||
}
|
||||
// disable use false//true for not disable.
|
||||
this.subChanged$.next(true);
|
||||
@@ -367,8 +368,10 @@ assignValue(item:Person): void {
|
||||
// convenience getter for easy access in form fields
|
||||
get f() { return this.adminuserForm.controls;}
|
||||
|
||||
loadImage(fileName: string| null): void {
|
||||
const download = this.personService.downloadFile(fileName!);
|
||||
loadImage(fileName: string | null,
|
||||
personId: number, photoType: number): void {
|
||||
if (fileName) {
|
||||
const download = this.personService.downloadPersonPhoto64(fileName, personId, photoType);
|
||||
this.subscription.add(download.subscribe({
|
||||
next: x => {
|
||||
if (x.statusCode == 1)
|
||||
@@ -384,8 +387,10 @@ assignValue(item:Person): void {
|
||||
},
|
||||
error: e => console.error("error in download image", e)
|
||||
}));
|
||||
}
|
||||
displayIamge64(baseImage: string): void
|
||||
}
|
||||
}
|
||||
|
||||
displayIamge64(baseImage: string): void
|
||||
{
|
||||
const changeUrl = (this.sanitizer.bypassSecurityTrustResourceUrl(baseImage) as any).changingThisBreaksApplicationSecurity;
|
||||
console.log('this is bypassSecurityTrustResourceUrl', changeUrl);
|
||||
|
||||
@@ -77,33 +77,60 @@ export class PersonService {
|
||||
const baseUrl = this.appSetting.appSetting.baseUrl + "/" + ConfigureUrl.personUrl + "/UploadImage";
|
||||
return this.http.post<ResultModel<string>>(baseUrl, data);
|
||||
}
|
||||
downloadFile(imageName: string): Observable<ResultModel<string>> {
|
||||
downloadFile_dontusethis(imageName: string, personId: number,
|
||||
photoType: number): Observable<ResultModel<string>> {
|
||||
const baseUrl = this.appSetting.appSetting.baseUrl + "/" + ConfigureUrl.FileUploadUrl + "/DownloadFile";
|
||||
const data = {
|
||||
fileName: imageName
|
||||
fileName: imageName,
|
||||
id: personId,
|
||||
photoType
|
||||
};
|
||||
return this.http.post<ResultModel<string>>(baseUrl, data);
|
||||
}
|
||||
deleteUploadFile(data: any): Observable<ResultModel<number>> {
|
||||
deleteUploadFile_dotnotuse(data: any): Observable<ResultModel<number>> {
|
||||
//data ={filename};
|
||||
const baseUrl = this.appSetting.appSetting.baseUrl + "/" + ConfigureUrl.personUrl + "/DeleteUploadFile";
|
||||
return this.http.post<ResultModel<number>>(baseUrl, data);
|
||||
}
|
||||
deletePersonPhotoFile(id: number): Observable<ResultModel<number>> {
|
||||
const data ={id, fileName:''};
|
||||
deletePersonPhotoFile(personId: number, photoType: number): Observable<ResultModel<number>> {
|
||||
const data = {
|
||||
id: personId,
|
||||
fileName: '',
|
||||
photoType
|
||||
};
|
||||
const baseUrl = this.appSetting.appSetting.baseUrl + "/" + ConfigureUrl.FileUploadUrl + "/DeletePersonPhoto";
|
||||
return this.http.post<ResultModel<number>>(baseUrl, data);
|
||||
}
|
||||
deletePersonPhotoFileById(id: number): Observable<ResultModel<number>> {
|
||||
const data = {
|
||||
id
|
||||
};
|
||||
const baseUrl = this.appSetting.appSetting.baseUrl + "/" + ConfigureUrl.FileUploadUrl + "/DeletePersonPhotoById";
|
||||
return this.http.post<ResultModel<number>>(baseUrl, data);
|
||||
}
|
||||
savePersonPhotoList(data:FormData): Observable<ResultModel<number>> {
|
||||
const baseUrl = this.appSetting.appSetting.baseUrl + "/" + ConfigureUrl.FileUploadUrl + "/SavePersonPhoto";
|
||||
return this.http.post<ResultModel<number>>(baseUrl, data);
|
||||
}
|
||||
downloadPersonPhoto(id: number): Observable<ResultModel<string>> {
|
||||
const baseUrl = this.appSetting.appSetting.baseUrl + "/" + ConfigureUrl.FileUploadUrl + "/DownloadPersonPhoto";
|
||||
|
||||
downloadPersonPhoto64(imageName: string, personId: number,
|
||||
photoType: number): Observable<ResultModel<string>> {
|
||||
const baseUrl = this.appSetting.appSetting.baseUrl + "/" + ConfigureUrl.FileUploadUrl + "/DownloadPersonPhoto64";
|
||||
const data = {
|
||||
id,
|
||||
fileName: ''
|
||||
id: personId,
|
||||
photoType,
|
||||
fileName: imageName
|
||||
};
|
||||
return this.http.post<ResultModel<string>>(baseUrl, data);
|
||||
}
|
||||
downloadPersonPhoto(imageName: string, personId: number,
|
||||
photoType: number): Observable<any> {
|
||||
const baseUrl = this.appSetting.appSetting.baseUrl + "/" + ConfigureUrl.FileUploadUrl + "/DownloadPersonPhoto";
|
||||
const data = {
|
||||
id: personId,
|
||||
photoType,
|
||||
fileName: imageName
|
||||
};
|
||||
return this.http.post<any>(baseUrl, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,12 +27,14 @@ export class ImageDisplayComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
const imageName = this.config.data.imageName;
|
||||
this.loadImage(imageName);
|
||||
const imageName = this.config.data.imageName;
|
||||
const personId = this.config.data.personId;
|
||||
const photoType = this.config.data.photyType;
|
||||
this.loadImage(imageName, personId, photoType);
|
||||
|
||||
}
|
||||
loadImage(fileName: string| null): void {
|
||||
const download = this.personService.downloadFile(fileName!);
|
||||
loadImage(fileName: string | null, personId: number, photoType: number): void {
|
||||
const download = this.personService.downloadPersonPhoto(fileName!, personId, photoType);
|
||||
this.subscription.add(download.subscribe({
|
||||
next: x => {
|
||||
if (x.statusCode == 1)
|
||||
|
||||
Reference in New Issue
Block a user