I'm trying to get TPH model database inheritance from ApplicationUser
:
public class Customer:ApplicationUser
{
public DateTime? AddeDateTime { get; set; }
public int? DietLenght { get; set; }
public int? ConsultationCount { get; set; }
public int? PlannedWeight { get; set; }
public int? Age { get; set; }
public int? Height { get; set; }
How to access those properties ? I tried:
var customerUser = await _context.Users.FirstOrDefaultAsync(x => x.Id == user.Id);
but i got ApplicationUser
. And ApplicationUser
doesn't have the properties to set up, so i can't make it like that.
customerUser .ConsultationCount = model.ConsultationCount;
customerUser .DietLenght = model.DietLenght;
customerUser .Height = model.Height;
customerUser .Age = model.Age;
I also tried:
var dataUser = user as Customer;
but it didn't work either.
Need it to create new User in my app
if (ModelState.IsValid)
{
var currentlyLogInUser = _userManager.GetUserAsync(HttpContext.User).Result;
var currentlyLogInUserId = currentlyLogInUser.Id;
var user = new ApplicationUser
{
UserName = model.Email,
Email = model.Email,
Name = model.Name,
Surname = model.Surname
};
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
var resultRole = await _userManager.AddToRoleAsync(user, "Customers");
if (resultRole.Succeeded)
{
_logger.LogInformation("User created a new account with password.");
var customer = (Customer) user;
customer.DieticianId = currentlyLogInUserId;
customer.AddeDateTime = DateTime.Today;
customer.ConsultationCount = model.ConsultationCount;
customer.DietLenght = model.DietLenght;
customer.Height = model.Height;
customer.Age = model.Age;
_context.Users.Update(customer);
await _context.SaveChangesAsync();
}
return RedirectToLocal(returnUrl);
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View();
}