-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24b3691
commit e91cf1e
Showing
34 changed files
with
2,243 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27703.2018 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoftJail", "SoftJail\SoftJail.csproj", "{B3A112C9-15D1-47E6-895D-6D381C436243}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{B3A112C9-15D1-47E6-895D-6D381C436243}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B3A112C9-15D1-47E6-895D-6D381C436243}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B3A112C9-15D1-47E6-895D-6D381C436243}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B3A112C9-15D1-47E6-895D-6D381C436243}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {994022F9-7A30-46DF-BC21-3B62FD63882E} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace SoftJail.Data | ||
{ | ||
public static class Configuration | ||
{ | ||
public static string ConnectionString = @"Server=.;Database=SoftJail;Trusted_Connection=True"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace SoftJail.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
public class Cell | ||
{ | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
[Range(1, 1000)] | ||
public int CellNumber { get; set; } | ||
|
||
[Required] | ||
public bool HasWindow { get; set; } | ||
|
||
[ForeignKey(nameof(Department))] | ||
public int DepartmentId { get; set; } | ||
[Required] | ||
public Department Department { get; set; } | ||
|
||
public ICollection<Prisoner> Prisoners { get; set; } = new HashSet<Prisoner>(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
ExamPrep-12-August-2018/SoftJail/Data/Models/Department.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace SoftJail.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
public class Department | ||
{ | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
[MinLength(3), MaxLength(25)] | ||
public string Name { get; set; } | ||
|
||
public ICollection<Cell> Cells { get; set; } = new HashSet<Cell>(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
ExamPrep-12-August-2018/SoftJail/Data/Models/Enums/Position.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace SoftJail.Data.Models.Enums | ||
{ | ||
public enum Position | ||
{ | ||
Overseer, | ||
Guard, | ||
Watcher, | ||
Labour | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
ExamPrep-12-August-2018/SoftJail/Data/Models/Enums/Weapon.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace SoftJail.Data.Models.Enums | ||
{ | ||
public enum Weapon | ||
{ | ||
Knife, | ||
FlashPulse, | ||
ChainRifle, | ||
Pistol, | ||
Sniper | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace SoftJail.Data.Models | ||
{ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
public class Mail | ||
{ | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
public string Description { get; set; } | ||
|
||
[Required] | ||
public string Sender { get; set; } | ||
|
||
[Required] | ||
[RegularExpression(@"^[A-Za-z0-9\s]+?str.$")] | ||
public string Address { get; set; } | ||
|
||
[ForeignKey(nameof(Prisoner))] | ||
public int PrisonerId { get; set; } | ||
[Required] | ||
public Prisoner Prisoner { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace SoftJail.Data.Models | ||
{ | ||
using SoftJail.Data.Models.Enums; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
public class Officer | ||
{ | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
[MinLength(3), MaxLength(30)] | ||
public string FullName { get; set; } | ||
|
||
[Required] | ||
[Range(typeof(decimal), "0", "79228162514264337593543950335")] | ||
public decimal Salary { get; set; } | ||
|
||
[Required] | ||
public Position Position { get; set; } | ||
|
||
[Required] | ||
public Weapon Weapon { get; set; } | ||
|
||
[ForeignKey(nameof(Department))] | ||
public int DepartmentId { get; set; } | ||
[Required] | ||
public Department Department { get; set; } | ||
|
||
public ICollection<OfficerPrisoner> OfficerPrisoners { get; set; } = new HashSet<OfficerPrisoner>(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
ExamPrep-12-August-2018/SoftJail/Data/Models/OfficerPrisoner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace SoftJail.Data.Models | ||
{ | ||
public class OfficerPrisoner | ||
{ | ||
public int PrisonerId { get; set; } | ||
public Prisoner Prisoner { get; set; } | ||
|
||
public int OfficerId { get; set; } | ||
public Officer Officer { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace SoftJail.Data.Models | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
public class Prisoner | ||
{ | ||
public int Id { get; set; } | ||
|
||
[Required] | ||
[MinLength(3), MaxLength(20)] | ||
public string FullName { get; set; } | ||
|
||
[Required] | ||
[RegularExpression(@"^The [A-Z]{1}[A-Za-z]+$")] | ||
public string Nickname { get; set; } | ||
|
||
[Required] | ||
[Range(18,65)] | ||
public int Age { get; set; } | ||
|
||
[Required] | ||
public DateTime IncarcerationDate { get; set; } | ||
|
||
public DateTime? ReleaseDate { get; set; } | ||
|
||
[Range(typeof(decimal), "0", "79228162514264337593543950335")] | ||
public decimal? Bail { get; set; } | ||
|
||
[ForeignKey(nameof(Cell))] | ||
public int? CellId { get; set; } | ||
public Cell Cell { get; set; } | ||
|
||
public ICollection<Mail> Mails { get; set; } = new HashSet<Mail>(); | ||
|
||
public ICollection<OfficerPrisoner> PrisonerOfficers { get; set; } = new HashSet<OfficerPrisoner>(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
ExamPrep-12-August-2018/SoftJail/Data/SoftJailDbContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace SoftJail.Data | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using SoftJail.Data.Models; | ||
|
||
public class SoftJailDbContext : DbContext | ||
{ | ||
public SoftJailDbContext() | ||
{ | ||
} | ||
|
||
public SoftJailDbContext(DbContextOptions options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<Officer> Officers { get; set; } | ||
public DbSet<OfficerPrisoner> OfficersPrisoners { get; set; } | ||
public DbSet<Prisoner> Prisoners { get; set; } | ||
public DbSet<Mail> Mails { get; set; } | ||
public DbSet<Cell> Cells { get; set; } | ||
public DbSet<Department> Departments { get; set; } | ||
|
||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
if (!optionsBuilder.IsConfigured) | ||
{ | ||
optionsBuilder | ||
.UseSqlServer(Configuration.ConnectionString); | ||
} | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder builder) | ||
{ | ||
builder.Entity<OfficerPrisoner>().HasKey(x => new { x.PrisonerId, x.OfficerId }); | ||
|
||
builder.Entity<OfficerPrisoner>().HasOne(x => x.Prisoner) | ||
.WithMany(p => p.PrisonerOfficers) | ||
.HasForeignKey(x => x.PrisonerId) | ||
.OnDelete(DeleteBehavior.Restrict); | ||
|
||
builder.Entity<OfficerPrisoner>().HasOne(x => x.Officer) | ||
.WithMany(o => o.OfficerPrisoners) | ||
.HasForeignKey(x => x.OfficerId) | ||
.OnDelete(DeleteBehavior.Restrict); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace SoftJail.DataProcessor | ||
{ | ||
using Data; | ||
using System; | ||
|
||
public class Bonus | ||
{ | ||
public static string ReleasePrisoner(SoftJailDbContext context, int prisonerId) | ||
{ | ||
var prisoner = context.Prisoners.Find(prisonerId); | ||
|
||
if (prisoner.ReleaseDate == null) | ||
{ | ||
return $"Prisoner {prisoner.FullName} is sentenced to life"; | ||
} | ||
|
||
prisoner.ReleaseDate = DateTime.Now; | ||
prisoner.Cell = null; | ||
|
||
context.SaveChanges(); | ||
|
||
return $"Prisoner {prisoner.FullName} released"; | ||
} | ||
} | ||
} |
Oops, something went wrong.