简体   繁体   中英

ASP.NET Core MVC application for ticket management

I just started learning ASP.NET Core MVC and I have an assessment on it so the requirements are the following

Write ASP.NET Core MVC application for ticket management, the application should have two types of users - admin and employee.

The employee user should be able to create a ticket with the following data (title and description fields) and see list of his tickets in the table view, and the admin should be able to see the list of the received tickets and can either approve or reject the tickets:

Employee user pages:

  1. Main page: should have table UI (column: Ticket Title, ticket Description, ticket status ) and button ( create ticket).

  2. Create ticket page: it should have ticket title and description fields and submit button so once he fills the data and clicks on submit then he should be navigate to the main page and the new ticket should appear in the table and the value of the status should be "Sent".

Admin page:

  1. Main page: should have table UI (column: Ticket Title, ticket Description, Employee name, ticket status, actions), in the action column there are two icon buttons (approve and reject ) so once he clicks on approve button then the ticket status should be change to approve so if the employee log in so he should see the ticket status as "Approved" and same process happens if the admin clicks on reject button.

So for the models should I create 3 modules (ticket, employee and admin)?

Also I have made a small ER diagram for the database, is it correct?

Ticket Management ER Diagram

Help please

Yes at minimum you will want Ticket , Employee , and Admin model classes to match your ER Diagram.

Example:

public class Employee
{
   public int EmployeeId { get; set; }
   public string EmployeeName { get; set; }
   public string EmployeeUsername { get; set; }
   public string Password { get; set; }
}

I don't quite understand why you are doing so much work here,

There should be a user in your application who then has a user level. It is not quite clear to me whether you use Identity or not. If so, you can simply add the UserState in the ApplicationUser.

Example: ApplicationDbContext.cs

public class ApplicationDbContext {
...
    public DbSet<Ticket> Tickets {get;set;}
    public DbSet<TicketMessage> TicketMessages {get;set;}
...
}

UserState.cs

  • i use byte here to have less bytes in database. | 1 instead of 4 bytes
public enum UserState : byte {
    Employee,
    Admin
}

TicketState.cs

public enum TicketState: byte {
    open,
    withdrawn,
    Closed
}

ApplicationUser.cs

public class ApplicationUser {
    public UserState State {get;set;}
    public IEnumerable<Ticket> Tickets {get;set;}
    public IEnumerable<TicketMessages> Messages {get;set;}
}

Ticket.cs //Admins don't need to be referenced you check on the Controller/Razorpage what ever if the user that is view the page had rights..

public class Ticket {
    public Guid Id {get;set;}
    public String Title {get;set;}
    public String Description {get;set;}
    public TicketState State {get;set;}
    public String OwnerId {get;set;}
    public ApplicationUser Owner {get;set;}

    public IEnumerable<TicketMessages> Messages {get;set;}
}

TicketMessage.cs

public class TicketMessage {
    public Guid Id {get;set;}
    public String Message {get;set;}

    public Guid TicketId {get;set;}
    public Ticket Ticket {get;set;}
    public String OwnerId {get;set;}
    public ApplicationUser Owner {get;set;}
}

Via Identity you can then easily create policies which check whether you are allowed to carry out this action (Create, Update, Add, Delete, AddTicketMessage)

If you need more help with Identity or something else the MSDN is well documented, https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-5.0&tabs=visual-studio

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM