mysql - ASP.NETCore - Friends System -


i`m building application try make friend system.

now, work 2 tables that. 1st: default aspnetusers store user information.

2nd: friends table below:

    public class aspnetfriends {     public int id { get; set; }     public string friendfrom { get; set; }     public string friendto { get; set; }     public bool isconfirmed { get; set; } } 

in table both "friendfrom" , "friendto" string type, , receiving registered users id.

what want achieve when display table on view, want show username of same userid thats either in "friendfrom" or "friendto" column.

you need change class followed (i didn't test this):

default application user of asp.net core

using microsoft.aspnetcore.identity.entityframeworkcore;  namespace project.models {     // add profile data application users adding properties applicationuser class     public class applicationuser : identityuser     {      } } 

model

public class aspnetfriends {     public int id { get; set; }     public bool isconfirmed { get; set; }     public virtual applicationuser friendfrom { get; set; }     public virtual applicationuser friendto { get; set; } } 

now can getters , setters of aspnet user

controller

public async task<iactionresult> details(int id) {     var query = m in _dbcontext.aspnetfriends                     join ff in _dbcontext.users on                         new { m.friendfrom.id } equals new { id = cu.id }                     join ft in _dbcontext.users on                         new { m.friendto.id } equals new { id = cu.id }                         m.id == id                         select m;      return view(query.single());  } 

view

@model project.aspnetfriends  <p> @model.friendfrom.username </p> 

@item.creationuser.username


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -