To set up the project, I simply selected a New Project, selected ASP MVC 3 from the Web templates, renamed, and clicked OK. That brought up the ASP MVC3 Dialog, where I selected an Internet Application, Razor view syntax, and did not choose to enable HTML 5 semantics.
That got me this:
A basic Website Set up. If I run it, it says, essentially, “Hello World.”
Right-click the solution and select “Add Solution to Source Control” and it’s even on CodePlex for me.
That done, it’s time to move onto the models. As I said before, we’ll have 3 table entities- Issues, Work Notes, and Users, and an enum value for Role. So, first off, an Issue class…
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel.DataAnnotations;
4: using System.Data.Entity;
5: using System.Linq;
6: using System.Web;
7:
8: namespace MvcIssueTracker.Models
9: {
10: public class Issue
11: {
12: public int IssueId { get; set; }
13:
14: [Required(ErrorMessage="A Title is required.")]
15: [StringLength(100, MinimumLength=15)]
16: public string Title { get; set; }
17:
18: [Required(ErrorMessage="A Detailed Description is required.")]
19: public string Description { get; set; }
20:
21: public int CreatedBy { get; set; }
22: public DateTime CreatedDate { get; set; }
23:
24: public int AssignedTo { get; set; }
25: public DateTime? LastUpdatedDate { get; set; }
26:
27: public int ClosedBy { get; set; }
28: public DateTime? ClosedDate { get; set; }
29:
30: public virtual User AssignedUser { get; set; }
31: public virtual ICollection<WorkNote> WorkNotes { get; set; }
32: }
33: }
Note that I dispensed with the convention of calling it “IssueModel.” It’s in the Model folder (and, therefore, the MvcIssueTracker.Models namespace). I went ahead and added my data notations as well, since I’ll need them eventually anyway.
One down, two (and a half?) to go.
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Web;
5: using System.ComponentModel.DataAnnotations;
6:
7: namespace MvcIssueTracker.Models
8: {
9: public class WorkNote
10: {
11: public int WorkNoteId { get; set; }
12:
13: [Required(ErrorMessage = "Details are required.")]
14: public string Detail { get; set; }
15: public DateTime LoggedDate { get; set; }
16:
17: public int IssueId { get; set; }
18:
19: public virtual Issue AttachedIssue { get; set; }
20: }
21: }
1: using System;
2: using System.Collections.Generic;
3: using System.ComponentModel.DataAnnotations;
4: using System.Data.Entity;
5: using System.Linq;
6: using System.Web;
7:
8: namespace MvcIssueTracker.Models
9: {
10: public class User
11: {
12: public int UserId { get; set; }
13:
14: [Required(ErrorMessage = "UserName is required.")]
15: public string UserName { get; set; }
16:
17: public string LastName { get; set; }
18: public string FirstName { get; set; }
19: public string Location { get; set; }
20: public string Password { get; set; }
21: public Role Role { get; set; }
22:
23: public virtual ICollection<Issue> AssignedIssues { get; set; }
24: }
25: }
And, finally, the Roles enum:
1: namespace MvcIssueTracker.Models
2: {
3: public enum Role
4: {
5: User, //The base user- able only to create issues and add worknotes
6: Developer, //User functionality + close issues
7: Manager, //Same functionality as Developer- listed differently for audit type purposes
8: Administrator, //Developer + Delete issues
9: }
10: }
So, a quick Save All, and a Build to make sure nothing obvious is immediately broken… And we’re done. A set of classes for our data model.
In the next installment, we’ll look at getting the DataContext set up, and begin building controllers and views.
No comments:
Post a Comment