Skip to content

Commit

Permalink
Merge pull request #10 from lukearnould/develop
Browse files Browse the repository at this point in the history
Fix warnings and merge SQL files
  • Loading branch information
lukearnould authored Jul 30, 2024
2 parents f8fa6fe + 5307f86 commit 7f85a5d
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,5 @@
<ItemGroup>
<Build Include="dbo\Tables\Hospital.sql" />
<Build Include="Security\HospitalManagementUser.sql" />
<Build Include="Security\HospitalManagementUser_1.sql" />
<Build Include="Security\RoleMemberships.sql" />
<Build Include="Security\Permissions.sql" />
</ItemGroup>
</Project>
23 changes: 22 additions & 1 deletion HospitalManagement.Database/Security/HospitalManagementUser.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
CREATE USER [HospitalManagementUser] FOR LOGIN [HospitalManagementUser];
CREATE LOGIN [HospitalManagementUser] WITH PASSWORD = ''
go

CREATE USER [HospitalManagementUser] FOR LOGIN [HospitalManagementUser];
go

GRANT VIEW ANY COLUMN ENCRYPTION KEY DEFINITION TO PUBLIC;
GO

GRANT VIEW ANY COLUMN MASTER KEY DEFINITION TO PUBLIC;
GO

GRANT CONNECT TO [HospitalManagementUser];
go

ALTER ROLE [db_accessadmin] ADD MEMBER [HospitalManagementUser];
GO

ALTER ROLE [db_datareader] ADD MEMBER [HospitalManagementUser];
go

ALTER ROLE [db_datawriter] ADD MEMBER [HospitalManagementUser];
go

This file was deleted.

10 changes: 0 additions & 10 deletions HospitalManagement.Database/Security/Permissions.sql

This file was deleted.

10 changes: 0 additions & 10 deletions HospitalManagement.Database/Security/RoleMemberships.sql

This file was deleted.

5 changes: 2 additions & 3 deletions HospitalManagement.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

namespace HospitalManagement.Web.Controllers
{
public class HomeController(ILogger<HomeController> _logger, Service service) : Controller
public class HomeController(Service service) : Controller
{
public async Task<IActionResult> Index()
{
List<Hospital> hospitals = await service.Get();

return View(hospitals);
}

Expand Down Expand Up @@ -54,8 +53,8 @@ public async Task<IActionResult> Save(Hospital hospital)
public async Task<IActionResult> Delete(int hospitalId)
{
await service.Delete(hospitalId);

Toast(ActionType.Delete, "Hospital deleted.");

return RedirectToAction("Index");
}

Expand Down
7 changes: 6 additions & 1 deletion HospitalManagement.Web/Models/Toast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
{
public record Toast
{
public Toast() { }
public Toast()
{
Message = "";
Icon = "";
Color = "";
}

public Toast(ActionType actionType, string message)
{
Expand Down
4 changes: 0 additions & 4 deletions HospitalManagement.Web/wwwroot/js/site.js

This file was deleted.

12 changes: 6 additions & 6 deletions HospitalManagement/Models/Hospital.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ public record Hospital

[StringLength(50)]
[Required]
public string Name { get; set; }
public string Name { get; set; } = "";

[StringLength(500)]
[Required]
public string Description { get; set; }
public string Description { get; set; } = "";

[Required]
public string Color { get; set; } = "#000000";

public string PhoneNumber
{
get { return _phoneNumber; }
set { _phoneNumber = value?.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-", ""); }
set { _phoneNumber = value?.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-", "") ?? ""; }
}

private string _phoneNumber;
private string _phoneNumber = "";

[EmailAddress]
[StringLength(100)]
public string EmailAddress { get; set; }
public string EmailAddress { get; set; } = "";

[StringLength(100)]
public string URL { get; set; }
public string URL { get; set; } = "";
}
}
11 changes: 6 additions & 5 deletions HospitalManagement/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ namespace HospitalManagement
{
public class Repository(ICoreConfig config)
{
private HospitalContext DefaultContext()
{
return new HospitalContext(config.ConnectionString);
}

public async Task<List<Hospital>> Get()
{
using var db = DefaultContext();
Expand All @@ -34,6 +29,7 @@ public async Task Save(Hospital hospital)
{
db.Update(hospital);
}

await db.SaveChangesAsync();
}

Expand All @@ -46,5 +42,10 @@ public async Task Delete(int id)
db.Remove(hospital);
await db.SaveChangesAsync();
}

private HospitalContext DefaultContext()
{
return new HospitalContext(config.ConnectionString);
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
dotnet user-secrets set "Database__Password" "<your password goes here>"
```

4. Update the password set in `HospitalManagement.Database.Security.HospitalManagementUser_1.sql` to match the password you entered above.
4. Update the password set in `HospitalManagement.Database.Security.HospitalManagementUser.sql` to match the password you entered above.
5. Publish the `HospitalManagement.Database` project to your database.
6. Run the below command at the root of the `HospitalManagement.Web` project:

Expand Down

0 comments on commit 7f85a5d

Please sign in to comment.