Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Can someone share code to retrieve user details along with thumbnail image to be displayed basis the input username. This has to be accomplished using asp.net core and react. I am pretty new to this technology, please help.

What I have tried:

in controller:
C#
public Image ourTeam()
{
    var userDetails = db.users.Where(x=>x.saMAccountName == "someUsername").FirstOrDefault();
    
    Image image = GetImage(userDetails.CN); //I get image data

    var stream = new System.IO.MemoryStream();

    if (image != null)
        image.Save(stream, ImageFormat.Jpeg);
    
    return image;
}

Component code:
JavaScript
import * as React from 'react';
import { RouteComponentProps } from 'react-router';

interface FetchImageDataState {
    imageList: ImageData[];
    loading: boolean;
}

export class OurTeam extends React.Component<routecomponentprops<{}>, FetchImageDataState> {
    constructor() {
        super();
        this.state = { imageList: [], loading: true }; //initialize to default

        fetch('api/Home/ourTeam')
            .then(response => response.json() as Promise<imagedata[]>)
            .then(data => {
                this.setState({ imageList: data, loading: false });
            });
    }

    public render() {        
        let contents = this.state.loading
            ? <p>Loading...</p>
            : this.renderImageTable(this.state.imageList);
        return <div>
            <h1>Team</h1>
            {contents}
        </div>;
    }

    private renderImageTable(imageList: ImageData[]) {
        return <div>{
            imageList.map(x =>
                )
        }</div>;        
    }
}

export class ImageData {
    CN: string = "";
    byteData: string = "";
}
Posted
Updated 28-May-20 10:40am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900