M220N Add User Ticket

I am looking at this lab and I am going through the lessons again and I need some clarification.

When I use the var user = new User and create the entry I get the message that the class User doesn’t have a constructor that accepts 3 arguments. One fix is to make a constructor but this would entail adding code to the class… Is this the intent of the lab?

Where I am confused is that the User class (Or model) doesn’t have a constructor…

namespace M220N.Models
{
    public class User
    {
        [BsonElement("_id")]
        [JsonProperty("_id")]
        [BsonId]
        [BsonRepresentation(BsonType.ObjectId)]
        public string Id { get; set; }

        [JsonProperty("auth_token")]
        [BsonIgnore]
        public string AuthToken { get; set; }

        public string Name { get; set; }

        public string Email { get; set; }

        public string Password { get; set; }

        [JsonIgnore]
        public string HashedPassword { get; set; }

        public bool IsAdmin { get; set; }

        public Dictionary<string, string> Preferences { get; set; }

What is the intent of the lab? Do I have to make changes to the class also?

No, you don’t need to make any changes to the class.

I guess this is happening because you might be passing the value in the wrong way.
Initially, the user variable is assigned to:

var user = new User()

But you have to pass the values in the following format:

var user = new User{
   Name = name,
   Email = email,
   HashedPassword = PasswordHashOMatic.Hash(password)
};

I hope it helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

1 Like