B
BlinkDrink
Guest
In my case I have a Dogsitter platform that has appointments for both Owners and Dogsitters. But since I am using Individual users authentication I have the AspNetCoreUsers and AspNetCoreRoles tables and one Application user.
public class ApplicationUser : IdentityUser, IAuditInfo, IDeletableEntity
{
public ApplicationUser()
{
// Application user
this.Id = Guid.NewGuid().ToString();
this.Roles = new HashSet<IdentityUserRole<string>>();
this.Claims = new HashSet<IdentityUserClaim<string>>();
this.Logins = new HashSet<IdentityUserLogin<string>>();
// Owner/Dogsitter info
this.Comments = new HashSet<Comment>();
this.Dogs = new HashSet<Dog>();
this.Appointments = new HashSet<Appointment>();
}
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string FullName => this.FirstName + this.MiddleName + this.LastName;
public string ImageUrl { get; set; }
public decimal Rating { get; set; }
public string Address { get; set; }
public string SelfDescription { get; set; }
public string DogsDescription { get; set; }
public decimal WageRate { get; set; }
public Gender Gender { get; set; }
public DateTime DateOfBirth { get; set; }
public UserType UserType { get; set; }
public ICollection<Comment> Comments { get; set; }
public ICollection<Dog> Dogs { get; set; }
public ICollection<Appointment> Appointments { get; set; }
// Audit info
public DateTime CreatedOn { get; set; }
public DateTime? ModifiedOn { get; set; }
// Deletable entity
public bool IsDeleted { get; set; }
public DateTime? DeletedOn { get; set; }
public virtual ICollection<IdentityUserRole<string>> Roles { get; set; }
public virtual ICollection<IdentityUserClaim<string>> Claims { get; set; }
public virtual ICollection<IdentityUserLogin<string>> Logins { get; set; }
}
I want to map the same Application user twice in the appointment class like that:
public class Appointment : BaseDeletableModel<int>
{
public bool IsHappening { get; set; }
public int Timer { get; set; }
public decimal TaxSoFar { get; set; }
public DateTime Date { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string OwnerId { get; set; }
[ForeignKey("Id")]
public virtual ApplicationUser Owner { get; set; }
public string DogsitterId { get; set; }
[ForeignKey("Id")]
public virtual ApplicationUser Dogsitter { get; set; }
}
What I am asking is: Is it possible to do it this way or Is it logically incorrect? Should I create seperate classes Dogsitter and Owner and if yes how can I link them to being ApplicationUsers(How to link both of them to the ApplicationDbContext). Really struggling to wrap my head around this one. Thanks in advance.
Continue reading...
public class ApplicationUser : IdentityUser, IAuditInfo, IDeletableEntity
{
public ApplicationUser()
{
// Application user
this.Id = Guid.NewGuid().ToString();
this.Roles = new HashSet<IdentityUserRole<string>>();
this.Claims = new HashSet<IdentityUserClaim<string>>();
this.Logins = new HashSet<IdentityUserLogin<string>>();
// Owner/Dogsitter info
this.Comments = new HashSet<Comment>();
this.Dogs = new HashSet<Dog>();
this.Appointments = new HashSet<Appointment>();
}
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string FullName => this.FirstName + this.MiddleName + this.LastName;
public string ImageUrl { get; set; }
public decimal Rating { get; set; }
public string Address { get; set; }
public string SelfDescription { get; set; }
public string DogsDescription { get; set; }
public decimal WageRate { get; set; }
public Gender Gender { get; set; }
public DateTime DateOfBirth { get; set; }
public UserType UserType { get; set; }
public ICollection<Comment> Comments { get; set; }
public ICollection<Dog> Dogs { get; set; }
public ICollection<Appointment> Appointments { get; set; }
// Audit info
public DateTime CreatedOn { get; set; }
public DateTime? ModifiedOn { get; set; }
// Deletable entity
public bool IsDeleted { get; set; }
public DateTime? DeletedOn { get; set; }
public virtual ICollection<IdentityUserRole<string>> Roles { get; set; }
public virtual ICollection<IdentityUserClaim<string>> Claims { get; set; }
public virtual ICollection<IdentityUserLogin<string>> Logins { get; set; }
}
I want to map the same Application user twice in the appointment class like that:
public class Appointment : BaseDeletableModel<int>
{
public bool IsHappening { get; set; }
public int Timer { get; set; }
public decimal TaxSoFar { get; set; }
public DateTime Date { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string OwnerId { get; set; }
[ForeignKey("Id")]
public virtual ApplicationUser Owner { get; set; }
public string DogsitterId { get; set; }
[ForeignKey("Id")]
public virtual ApplicationUser Dogsitter { get; set; }
}
What I am asking is: Is it possible to do it this way or Is it logically incorrect? Should I create seperate classes Dogsitter and Owner and if yes how can I link them to being ApplicationUsers(How to link both of them to the ApplicationDbContext). Really struggling to wrap my head around this one. Thanks in advance.
Continue reading...