jeudi 21 janvier 2016

edit user profile image with usermanager

I'm following this tutorial to add profile picture once account create.

that edit has following snippet,

Student student = db.Students.Include(s => s.Files).SingleOrDefault(s => s.ID == id);

In above example it applied to table call Student in my case I want to go with AspNetUser table , but then I have to go with UserManger feature , Once I try to Include a file then it popping that error in compile time.

But in my scenario I'm trying to include in AspNetUser or UserManager

So to populate uploaded picture. I need include following code in user manager

var user = await UserManager.Include(s => s.Files).FindByIdAsync(userid);

but then getting following error

'ApplicationUserManager' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'ApplicationUserManager'

How to ignore and include files

EDIT:

These are the changes I've done in Model classes

File

public class File
{
    public int FileId { get; set; }
    ..

    public virtual ApplicationUser UserManager { get; set; }
}

FilePath

    public class FilePath
{
    public int FilePathId { get; set; }
    ..

    public virtual ApplicationUser UserManager { get; set; }
}

ApplicationUser

public class ApplicationUser : IdentityUser
{
        ....

        public virtual ICollection<File> Files { get; set; }
        public virtual ICollection<FilePath> FilePaths { get; set; }

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
       ....
    }
}

AspNetUser

public partial class AspNetUser
{

    public AspNetUser()
    {
       ..
    }
    ....

    public virtual ICollection<File> Files { get; set; }
    public virtual ICollection<FilePath> FilePaths { get; set; }
}

then try to add migration to the project by typing the following into the PMC:

add-migration File

add-migration FilePaths

then getting following error in console

No migrations configuration type was found in the assembly 'Project_Name'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).

Aucun commentaire:

Enregistrer un commentaire