I have 3 classes for rules, queries, executions, and assertions.
I want to combine these three tables in the viewModel so that I can get the Requestid, description, statements, and execution status in one view. Here is my first rude attempt, which seems to work, but I believe this is a very wrong way to create a ViewModel. Please suggest a better approach.
public class Rules { [Required] public virtual int RulesId { get; set; } [Required] public virtual string RulesDescription { get; set; } [Required] public virtual int ApprovalLevels { get; set; } //if 0 then auto approved. [Required] public virtual string Requestor { get; set; } } public class Requests { [Required] public virtual int RequestsId { get; set; } [Required] public virtual DateTime RequestTime { get; set; } [Required] public virtual bool isCompleted { get; set; } [Required] public virtual string UserName { get; set; } [Required] public virtual int RulesId { get; set; } public virtual string Description { get; set; } } public class ExecutionStatus { [Required] public virtual int ExecutionStatusId { get; set; } [Required] public virtual int RequestId { get; set; } [Required] public virtual int CurrentApproverLevel { get; set; } [Required] public virtual string ApprovalStatus { get; set; } } public class Approvals { [Required] public virtual int ApprovalsId { get; set; } [Required] public virtual int RulesId { get; set; } [Required] public virtual int ApproverLevel { get; set; } [Required] public virtual string ApproverName { get; set; } } public class RequestExecutionViewModel { private RequestsContext db = new RequestsContext(); public RequestExecutionViewModel(string username) { this.Request = db.Requests.Where(a => a.UserName.Equals(username)).First();
Edit: Doing a database query inside a model seems wrong to me. There must be a better way to do things.
source share