Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net mvc 4 - Multiple Users class Diagram
    primarykey
    data
    text
    <p>I've been searching about this subject, but not found exactly what I want. Basically I started to plan a project with all UML stuff, Use Cases, class diagram bla bla. Then we decided to use ASP.NET MVC. The application is a kind of O-Desk or Elance</p> <p>I have User, Contractor, Company, Moderator and Administrator.</p> <p>I'm a bit confused how the Model should represent this Users and how to set privileges and roles with asp.net mvc features.</p> <p>In a normal application I would have a class for each of them, and they would probably extend User, which would had username, password and email.</p> <p>In the Contractor class I have all information regarding the contractor, like jobs he applied, his CV, etc.</p> <p>In the Company class I have the posted Offers, Company name, etc.</p> <p>So what is the best practice to have this? I have here a piece of code</p> <pre><code> public class User { [Key] public string UserID { get; set; } [Required(ErrorMessage = "Email is required")] [DataType(DataType.EmailAddress, ErrorMessage="Email Format is wrong. Example: user@user.com")] [Remote("doesEmailExist", "Contractors", HttpMethod = "POST", ErrorMessage = "Email already exists. Please enter a different one.")] public string Email { get; set; } [Required] [Remote("doesUserNameExist", "Contractors", HttpMethod = "POST", ErrorMessage = "User name already exists. Please enter a different user name.")] public string Username { get; set; } [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] public string Password { get; set; } } </code></pre> <p>Small doubt also, should I have ContractorID? or I grab the UserID? just asking as I don't know how the DB will look like after generated. Anyway I'm going to try this now.</p> <pre><code>public class Contractor extends User { [Key] public int ContractorID { get; set; } [Required(ErrorMessage = "First Name is required")] [StringLength(20, ErrorMessage = "First Name max length is 20 characters")] [Display(Name = "First Name")] public string FirstName { get; set; } [Required(ErrorMessage = "Last Name is required")] [StringLength(20, ErrorMessage = "First Name max length is 20 characters")] [Display(Name = "Last Name")] public string LastName { get; set; } } public class Company extends User { [Key] public int CompanyID { get; set; } [Required(ErrorMessage = "Name of the Company required")] public string CompanyName { get; set; } private List&lt;Offer&gt; Offers; public void AddOffer (Offer offer) { Offers.Add(offer); } public void RemoveOffer(Offer offer) { Offers.Remove(offer); } </code></pre> <p>}</p> <p>Thanks for any help or hint provided! Regards.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload