diff --git a/TicketingSystem.Database/Data/TicketSystemDbContext.cs b/TicketingSystem.Database/Data/TicketSystemDbContext.cs new file mode 100644 index 0000000000000000000000000000000000000000..42a2f7c0932fc8fbb0d76ee7cea954ff99b21cd2 --- /dev/null +++ b/TicketingSystem.Database/Data/TicketSystemDbContext.cs @@ -0,0 +1,108 @@ +using Microsoft.EntityFrameworkCore; +using TicketingSystem.Database.Entities; + +namespace TicketingSystem.Database.Data; + +public class TicketSystemDbContext : DbContext +{ + public TicketSystemDbContext(DbContextOptions<TicketSystemDbContext> options) : base(options) + { + } + + public DbSet<User> Users { get; set; } + public DbSet<Ticket> Tickets { get; set; } + public DbSet<TicketCategory> TicketCategories { get; set; } + public DbSet<Status> Statuses { get; set; } + public DbSet<Priority> Priorities { get; set; } + public DbSet<Faq> Faqs { get; set; } + public DbSet<Role> Roles { get; set; } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + // One to Many relation between User and Ticket + modelBuilder.Entity<Ticket>() + .HasOne(t => t.User) + .WithMany(c => c.Tickets) + .HasForeignKey(t => t.UserId); + + modelBuilder.Entity<User>() + .HasMany(s => s.Roles) + .WithMany(p => p.Users) + .UsingEntity(junction => junction.ToTable("UserRole")); + + + modelBuilder.Entity<Role>().HasData( + new Role { RoleId = 1, RoleName = "User" }, + new Role { RoleId = 2, RoleName = "Admin" } + ); + + modelBuilder.Entity<TicketCategory>() + .HasMany(c => c.Ticket) + .WithOne(t => t.Category) + .HasForeignKey(t => t.CategoryId); + + modelBuilder.Entity<Priority>() + .HasMany(p => p.Tickets) + .WithOne(t => t.Priority) + .HasForeignKey(t => t.PriorityId); + + // Seed data + modelBuilder.Entity<Priority>().HasData( + new Priority { PriorityId = 1, PriorityName = "High" }, + new Priority { PriorityId = 2, PriorityName = "Medium" }, + new Priority { PriorityId = 3, PriorityName = "Low" } + ); + + modelBuilder.Entity<Status>() + .HasMany(s => s.Tickets) + .WithOne(t => t.Status) + .HasForeignKey(t => t.StatusId); + + modelBuilder.Entity<Status>().HasData( + new Status { StatusId = 1, StatusName = "New" }, + new Status { StatusId = 2, StatusName = "Pending" }, + new Status { StatusId = 3, StatusName = "Resolved" } + ); + + modelBuilder.Entity<TicketCategory>().HasData( + + new TicketCategory { CategoryId = 1, Name = "Hardware", Description = "Server Failures,Insufficient Resources etc" }, + new TicketCategory { CategoryId = 2, Name = "Software", Description = "coding errors, design flaws, integration problems, and user experience challenges" }, + new TicketCategory { CategoryId = 3, Name = "Network", Description = "hardware failures, configuration errors, and external factors" }, + new TicketCategory { CategoryId = 4, Name = "Security", Description = "data breaches, loss of sensitive information" } + + + ); + + modelBuilder.Entity<Faq>().HasData( + + new Faq { FaqId = 1, Question = "How do I create a new ticket?", Answer = "Go to the ticketing system, click on 'Raise Ticket', fill in the required fields, and submit." }, + new Faq { FaqId = 2, Question = "What are the different status options?", Answer = "New, Pending, Resolved." }, + new Faq { FaqId = 3, Question = "How can I update a ticket status?", Answer = "Go to the ticket details page, click on 'Update Ticket', select the desired status, and click 'Save Changes'." }, + new Faq + { + FaqId = 4, + Question = "Where can I find my ticket history?", + Answer = "You can find your ticket history by navigating to the 'My Tickets' section in your profile.", + }, + new Faq + { + FaqId = 5, + Question = "Is there a mobile app for ticket submission?", + Answer = "Currently, we do not have a mobile app. However, our website is mobile-friendly, and you can submit tickets directly from your mobile browser.", + }, + new Faq + { + FaqId = 6, + Question = "What is the response time for tickets?", + Answer = "Our typical response time for tickets is within 24 hours. However, response times may vary based on the volume of requests.", + }, + new Faq + { + FaqId = 7, + Question = "What should I do if I encounter a bug?", + Answer = "If you encounter a bug, please submit a ticket with detailed information about the issue. Include steps to reproduce it if possible.", + } + ); + } +} \ No newline at end of file diff --git a/TicketingSystem.Database/Entities/Faq.cs b/TicketingSystem.Database/Entities/Faq.cs new file mode 100644 index 0000000000000000000000000000000000000000..bdd9e0b6487a9a96e8351fc0c33e57f1ac415a75 --- /dev/null +++ b/TicketingSystem.Database/Entities/Faq.cs @@ -0,0 +1,6 @@ +namespace TicketingSystem.Database.Entities; +public class Faq{ + public int FaqId { get; set; } + public string? Question { get; set; } + public string? Answer { get; set; } +} \ No newline at end of file diff --git a/TicketingSystem.Database/Entities/Priority.cs b/TicketingSystem.Database/Entities/Priority.cs new file mode 100644 index 0000000000000000000000000000000000000000..ad109238c4f9604580d14b30eebdfb5556abba34 --- /dev/null +++ b/TicketingSystem.Database/Entities/Priority.cs @@ -0,0 +1,16 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; +using Microsoft.Identity.Client; + +namespace TicketingSystem.Database.Entities; + +public class Priority +{ + [Key] + public int PriorityId{get;set;} + public string? PriorityName{get;set;} + [JsonIgnore] + public List<Ticket>? Tickets { get; set; } + +} diff --git a/TicketingSystem.Database/Entities/Role.cs b/TicketingSystem.Database/Entities/Role.cs new file mode 100644 index 0000000000000000000000000000000000000000..7e2b9af733069f42c51c8dbe6f5fa006546edae8 --- /dev/null +++ b/TicketingSystem.Database/Entities/Role.cs @@ -0,0 +1,9 @@ +using TicketingSystem.Database.Entities; + +public class Role{ + public int RoleId{get;set;} + public string? RoleName{get;set;} + //Many to many Relation between Role and User + public List<User>? Users{get;set;} + +} \ No newline at end of file diff --git a/TicketingSystem.Database/Entities/Status.cs b/TicketingSystem.Database/Entities/Status.cs new file mode 100644 index 0000000000000000000000000000000000000000..250ddb4beb5ec340110554a4381f7462ab74d70d --- /dev/null +++ b/TicketingSystem.Database/Entities/Status.cs @@ -0,0 +1,19 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; + + + +namespace TicketingSystem.Database.Entities; + +public class Status +{ + [Key] + public int StatusId { get; set; } + public string? StatusName { get; set; } + [JsonIgnore] + public List<Ticket>? Tickets { get; set; } + +} + + diff --git a/TicketingSystem.Database/Entities/Ticket.cs b/TicketingSystem.Database/Entities/Ticket.cs new file mode 100644 index 0000000000000000000000000000000000000000..cf2946e116485ea3e45597db919f1746443014c5 --- /dev/null +++ b/TicketingSystem.Database/Entities/Ticket.cs @@ -0,0 +1,25 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace TicketingSystem.Database.Entities; +public class Ticket +{ + [Key] + public int TicketId { get; set; } + public string? Description { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime UpdatedAt { get; set; } + public int CategoryId { get; set; } + public int PriorityId { get; set; } + public int StatusId { get; set; } + public int UserId { get; set; } + //One to One Relation between Ticket and Category + public TicketCategory? Category { get; set; } + //One to One Relation between Ticket and Priority + public Priority? Priority { get; set; } + //One to One Relation between Ticket and Status + public Status? Status { get; set; } + //One to One Relation between Ticket and User + public User? User { get; set; } + +} diff --git a/TicketingSystem.Database/Entities/TicketCategory.cs b/TicketingSystem.Database/Entities/TicketCategory.cs new file mode 100644 index 0000000000000000000000000000000000000000..7201b70551433aa65ca37bf2361b8549f4487af4 --- /dev/null +++ b/TicketingSystem.Database/Entities/TicketCategory.cs @@ -0,0 +1,16 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; + +namespace TicketingSystem.Database.Entities; + +public class TicketCategory +{ + [Key] + public int CategoryId { get; set; } + public string? Name { get; set; } + public string? Description { get; set; } + [JsonIgnore] + //One to many relation between TicketCategory(1) and Ticket(*) + public List<Ticket>? Ticket { get; set; } +} diff --git a/TicketingSystem.Database/Entities/User.cs b/TicketingSystem.Database/Entities/User.cs new file mode 100644 index 0000000000000000000000000000000000000000..e000c6602b7180c2fca4ebaddbe066df444c5e1f --- /dev/null +++ b/TicketingSystem.Database/Entities/User.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Identity; +namespace TicketingSystem.Database.Entities; +public class User +{ + public int ID {get;set;} + public string? UserName {get;set;} + public string? Email{get;set;} + public string? PassWord{get;set;} + //Many to Many Relation between User and Role + public List<Role>? Roles{get;set;} + //One to Many Relation between User(1) and Ticket(*) + public List<Ticket>? Tickets{get;set;} +} \ No newline at end of file