Skip to content

Commit 526e4d0

Browse files
authored
Merge pull request #4 from SensitTechnologies/line-operators-crud
Updated with all requested changes and some minor fixes
2 parents f22fa5b + c9d01f6 commit 526e4d0

File tree

10 files changed

+437
-29
lines changed

10 files changed

+437
-29
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
@page "/lineoperators/addoperator"
2+
@using MESS.Data.Models
3+
@using MESS.Services.LineOperator
4+
@rendermode InteractiveServer
5+
@inject ILineOperatorService LineOperatorService
6+
@inject NavigationManager NavigationManager
7+
8+
<h3>Add Operator</h3>
9+
10+
<input type="text" @bind="NewLineOperator.FirstName" placeholder="First Name"/>
11+
<input type="text" @bind="NewLineOperator.LastName" placeholder="Last Name"/>
12+
<button @onclick="AddLineOperator">Add Operator</button>
13+
<br/>
14+
<button @onclick="LineOperatorNavigate">Back</button>
15+
16+
@if (OperatorAdded)
17+
{
18+
<p>Operator successfully added.</p>
19+
}
20+
21+
@code {
22+
private List<LineOperator> Operators = new();
23+
private LineOperator NewLineOperator = new()
24+
{
25+
FirstName = string.Empty,
26+
LastName = string.Empty,
27+
CreatedBy = string.Empty,
28+
LastModifiedBy = string.Empty,
29+
CreatedOn = DateTimeOffset.UtcNow,
30+
LastModifiedOn = DateTimeOffset.UtcNow
31+
};
32+
33+
private Task LoadOperators()
34+
{
35+
Operators = LineOperatorService.GetLineOperators();
36+
StateHasChanged();
37+
return Task.CompletedTask;
38+
}
39+
40+
private bool OperatorAdded;
41+
42+
private async Task AddLineOperator()
43+
{
44+
if (!string.IsNullOrWhiteSpace(NewLineOperator.FirstName) && !string.IsNullOrWhiteSpace(NewLineOperator.LastName))
45+
{
46+
bool succeeded = await LineOperatorService.AddLineOperator(NewLineOperator);
47+
if (succeeded)
48+
{
49+
OperatorAdded = true;
50+
}
51+
52+
NewLineOperator = new LineOperator
53+
{
54+
FirstName = string.Empty,
55+
LastName = string.Empty,
56+
CreatedOn = DateTimeOffset.UtcNow,
57+
LastModifiedOn = DateTimeOffset.UtcNow
58+
};
59+
await LoadOperators();
60+
}
61+
}
62+
63+
private void LineOperatorNavigate()
64+
{
65+
NavigationManager.NavigateTo("/lineoperators");
66+
}
67+
68+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@page "/lineoperators/deleteperator"
2+
@using MESS.Data.Models
3+
@using MESS.Services.LineOperator
4+
@rendermode InteractiveServer
5+
@inject ILineOperatorService LineOperatorService
6+
7+
8+
@if (Operators == null || Operators.Count == 0)
9+
{
10+
<p>ERROR: No operators found.</p>
11+
}
12+
else
13+
{
14+
<select @bind="SelectedOperatorId" @bind:event="OperatorChanged">
15+
<option value=""> Select Operator </option>
16+
@foreach (var op in Operators)
17+
{
18+
<option value="@op.Id">@op.FirstName @op.LastName</option>
19+
}
20+
</select>
21+
22+
@if (SelectedOperator != null)
23+
{
24+
<p>Selected Operator: @SelectedOperator.FirstName @SelectedOperator.LastName</p>
25+
<button @onclick="DeleteLineOperator">Delete Operator</button>
26+
}
27+
}
28+
29+
30+
@code {
31+
private List<LineOperator> Operators = new();
32+
private int? SelectedOperatorId;
33+
private LineOperator? SelectedOperator;
34+
35+
protected override async Task OnInitializedAsync()
36+
{
37+
await LoadOperators();
38+
}
39+
40+
private Task LoadOperators()
41+
{
42+
Operators = LineOperatorService.GetLineOperators();
43+
StateHasChanged();
44+
return Task.CompletedTask;
45+
}
46+
47+
private async Task<bool> DeleteLineOperator()
48+
{
49+
if (SelectedOperatorId.HasValue)
50+
{
51+
await LineOperatorService.DeleteLineOperator(SelectedOperatorId.Value);
52+
await LoadOperators();
53+
SelectedOperator = null;
54+
SelectedOperatorId = null;
55+
}
56+
return true;
57+
}
58+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
@page "/lineoperators"
2+
@using MESS.Services.LineOperator
3+
@using MESS.Data.Models
4+
@rendermode InteractiveServer
5+
@inject ILineOperatorService LineOperatorService
6+
@inject NavigationManager NavigationManager
7+
8+
<PageTitle>Operator Select</PageTitle>
9+
10+
<h2>Operator Select</h2>
11+
<br/>
12+
13+
@if (Operators == null || Operators.Count == 0)
14+
{
15+
<p>ERROR: No operators found.</p>
16+
}
17+
else
18+
{
19+
<select @bind="SelectedOperatorId">
20+
<option value=""> Select Operator </option>
21+
@foreach (var op in Operators)
22+
{
23+
<option value="@op.Id">@op.FirstName @op.LastName</option>
24+
}
25+
</select>
26+
27+
@if (SelectedOperator != null)
28+
{
29+
<p>Current Operator: @SelectedOperator.FirstName @SelectedOperator.LastName</p>
30+
}
31+
32+
<h3>Operator Management</h3>
33+
<br/>
34+
<button @onclick="AddOperator">Add Operator</button>
35+
<button @onclick="UpdateOperator">Update Operator</button>
36+
<button @onclick="DeleteOperator">Delete Operator</button>
37+
}
38+
39+
@code {
40+
private List<LineOperator> Operators = new();
41+
private int? _selectedOperatorId;
42+
private LineOperator? SelectedOperator;
43+
44+
private int? SelectedOperatorId
45+
{
46+
get => _selectedOperatorId;
47+
set
48+
{
49+
_selectedOperatorId = value;
50+
SelectedOperator = Operators.FirstOrDefault(op => op.Id == value);
51+
}
52+
}
53+
54+
protected override async Task OnInitializedAsync()
55+
{
56+
await LoadOperators();
57+
}
58+
59+
private Task LoadOperators()
60+
{
61+
Operators = LineOperatorService.GetLineOperators();
62+
StateHasChanged();
63+
return Task.CompletedTask;
64+
}
65+
66+
private void AddOperator()
67+
{
68+
NavigationManager.NavigateTo("/lineoperators/addoperator");
69+
}
70+
71+
private void DeleteOperator()
72+
{
73+
NavigationManager.NavigateTo("/lineoperators/deleteoperator");
74+
}
75+
76+
private void UpdateOperator()
77+
{
78+
NavigationManager.NavigateTo($"/lineoperators/updateoperator/{SelectedOperatorId}");
79+
}
80+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
@page "/lineoperators/updateoperator/{id:int}"
2+
@using MESS.Services.LineOperator
3+
@using MESS.Data.Models
4+
@rendermode InteractiveServer
5+
@inject ILineOperatorService LineOperatorService
6+
@inject NavigationManager NavigationManager
7+
8+
<h3>Update Operator</h3>
9+
10+
@if (Operator == null)
11+
{
12+
<p>ERROR: No operators found.</p>
13+
}
14+
else
15+
{
16+
<div>
17+
<label>First Name:</label>
18+
<input @bind="Operator.FirstName" />
19+
20+
<label>Last Name:</label>
21+
<input @bind="Operator.LastName" />
22+
23+
<br/>
24+
<button @onclick="UpdateLineOperator">Update</button>
25+
26+
<br/>
27+
<button @onclick="NavigateBack">Back</button>
28+
</div>
29+
}
30+
31+
@code {
32+
[Parameter] public int Id { get; set; }
33+
private LineOperator? Operator { get; set; }
34+
35+
private async Task UpdateLineOperator()
36+
{
37+
if (Operator != null)
38+
{
39+
var success = await LineOperatorService.UpdateLineOperator(Operator);
40+
}
41+
}
42+
43+
protected override async Task OnInitializedAsync()
44+
{
45+
await LoadOperators();
46+
}
47+
48+
private Task LoadOperators()
49+
{
50+
Operator = LineOperatorService.GetLineOperatorById(Id);
51+
StateHasChanged();
52+
return Task.CompletedTask;
53+
}
54+
55+
private void NavigateBack()
56+
{
57+
NavigationManager.NavigateTo("/lineoperators");
58+
}
59+
}

MESS/MESS.Blazor/MESS.Blazor.csproj

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<ProjectReference Include="..\MESS.Data\MESS.Data.csproj" />
13-
<ProjectReference Include="..\MESS.Services\MESS.Services.csproj" />
12+
<ProjectReference Include="..\MESS.Data\MESS.Data.csproj" />
13+
<ProjectReference Include="..\MESS.Services\MESS.Services.csproj" />
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="FluentValidation" Version="11.11.0" />
18-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
19-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.2">
20-
<PrivateAssets>all</PrivateAssets>
21-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22-
</PackageReference>
23-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.2" />
24-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.2" />
25-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.2">
26-
<PrivateAssets>all</PrivateAssets>
27-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
28-
</PackageReference>
29-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
30-
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
31-
<PackageReference Include="Serilog" Version="4.2.0" />
32-
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
33-
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
34-
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
17+
<PackageReference Include="FluentValidation" Version="11.11.0" />
18+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
19+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.2">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageReference>
23+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.2" />
24+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.2" />
25+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.2">
26+
<PrivateAssets>all</PrivateAssets>
27+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
28+
</PackageReference>
29+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
30+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
31+
<PackageReference Include="Serilog" Version="4.2.0" />
32+
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
33+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
34+
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
3535
</ItemGroup>
3636

3737
</Project>

MESS/MESS.Data/Models/LineOperator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class LineOperator : AuditableEntity
1616
public ProductionLog? ProductionLog { get; set; }
1717
}
1818

19+
1920
public class LineOperatorValidator : AbstractValidator<LineOperator>
2021
{
2122
public LineOperatorValidator()

MESS/MESS.Services/Class1.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace MESS.Services.LineOperator;
2+
using Data.Models;
3+
4+
public interface ILineOperatorService
5+
{
6+
//<summary>
7+
// Retrieves a list of all LineOperators currently registered
8+
//</summary>
9+
//<returns>List of LineOperator objects</returns>
10+
public List<LineOperator> GetLineOperators();
11+
12+
//<summary>
13+
// Retrieves a LineOperator by id number
14+
//</summary>
15+
//<returns>LineOperator object</returns>
16+
public LineOperator? GetLineOperatorById(int id);
17+
18+
//<summary>
19+
// Retrieves a LineOperator by last name
20+
//</summary>
21+
//<returns>LineOperator object</returns>
22+
public LineOperator? GetLineOperatorByLastName(string lastName);
23+
24+
//<summary>
25+
// Creates a LineOperator object and saves it to the database
26+
//</summary>
27+
//<returns>LineOperator object</returns>
28+
public Task<bool> AddLineOperator(LineOperator lineOperator);
29+
30+
//<summary>
31+
// Updates a LineOperator currently in the database
32+
//</summary>
33+
//<returns>Updated LineOperator object</returns>
34+
public Task<bool> UpdateLineOperator(LineOperator lineOperator);
35+
36+
//<summary>
37+
// Deletes a LineOperator currently in the database
38+
//</summary>
39+
//<returns>Deleted LineOperator boolean</returns>
40+
public Task<bool> DeleteLineOperator(int id);
41+
42+
}

0 commit comments

Comments
 (0)