Skip to content

Commit

Permalink
Prepared to refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleybot committed Oct 24, 2024
1 parent 5325aa6 commit 00816a1
Show file tree
Hide file tree
Showing 37 changed files with 691 additions and 574 deletions.
10 changes: 5 additions & 5 deletions src/UDS.Net.Forms.Tests/Services/VisitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public static List<Visit> GetSeedingVisits()
{
return new List<Visit>()
{
new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Unsubmitted, DateTime.Now, "[email protected]", "", "", false, null),
new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Unsubmitted, DateTime.Now, "[email protected]", "", "", false, null),
new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Unsubmitted, DateTime.Now, "[email protected]", "", "", false, null),
new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Unsubmitted, DateTime.Now, "[email protected]", "", "", false, null),
new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Unsubmitted, DateTime.Now, "[email protected]", "", "", false, null)
new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Pending, DateTime.Now, "[email protected]", "", "", false, null),
new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Pending, DateTime.Now, "[email protected]", "", "", false, null),
new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Pending, DateTime.Now, "[email protected]", "", "", false, null),
new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Pending, DateTime.Now, "[email protected]", "", "", false, null),
new Visit(1, 1, 1,"4", Net.Services.Enums.PacketKind.I, DateTime.Now, "TST", Net.Services.Enums.PacketStatus.Pending, DateTime.Now, "[email protected]", "", "", false, null)
};
}

Expand Down
42 changes: 30 additions & 12 deletions src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,35 @@ public static VisitModel ToVM(this Visit visit)
};
}

public static PacketSubmissionsModel ToVM(this IEnumerable<PacketSubmission> packetSubmissions)
public static PacketModel ToVM(this Packet packet)
{
PacketSubmissionsModel vm = new PacketSubmissionsModel();

if (packetSubmissions != null)
return new PacketModel()
{
foreach (var packetSubmission in packetSubmissions)
{
vm.List.Add(packetSubmission.ToVM());
}
}
Id = packet.Id,
ParticipationId = packet.ParticipationId,
VISITNUM = packet.VISITNUM,
PACKET = packet.PACKET,
FORMVER = packet.FORMVER,
VISIT_DATE = packet.VISIT_DATE,
INITIALS = packet.INITIALS,
Status = packet.Status,
CreatedAt = packet.CreatedAt,
CreatedBy = packet.CreatedBy,
ModifiedBy = packet.ModifiedBy,
DeletedBy = packet.DeletedBy,
IsDeleted = packet.IsDeleted,
CanBeFinalized = packet.IsFinalizable,
Forms = packet.Forms.ToVM(),
PacketSubmissions = packet.Submissions.ToVM()
};
}

public static List<PacketSubmissionModel> ToVM(this IList<PacketSubmission> packetSubmissions)
{
List<PacketSubmissionModel> vm = new List<PacketSubmissionModel>();

if (packetSubmissions != null && packetSubmissions.Count() > 0)
vm = packetSubmissions.Select(p => p.ToVM()).ToList();

return vm;
}
Expand All @@ -106,15 +124,15 @@ public static PacketSubmissionModel ToVM(this PacketSubmission packetSubmission)
return vm;
}

public static PacketSubmissionErrorsPaginatedModel ToVM(this List<PacketSubmissionError> packetSubmissionErrors)
public static List<PacketSubmissionErrorModel> ToVM(this List<PacketSubmissionError> packetSubmissionErrors)
{
PacketSubmissionErrorsPaginatedModel vm = new PacketSubmissionErrorsPaginatedModel();
List<PacketSubmissionErrorModel> vm = new List<PacketSubmissionErrorModel>();

if (packetSubmissionErrors != null)
{
foreach (var error in packetSubmissionErrors)
{
vm.List.Add(error.ToVM());
vm.Add(error.ToVM());
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ public static Visit ToEntity(this VisitModel vm)
return new Visit(vm.Id, vm.VISITNUM, vm.ParticipationId, vm.FORMVER, vm.PACKET, vm.VISIT_DATE, vm.INITIALS, vm.Status, vm.CreatedAt, vm.CreatedBy, vm.ModifiedBy, vm.DeletedBy, vm.IsDeleted, vm.Forms.ToEntity());
}

public static Packet ToEntity(this PacketModel vm)
{
return new Packet(vm.Id, vm.VISITNUM, vm.ParticipationId, vm.FORMVER, vm.PACKET, vm.VISIT_DATE, vm.INITIALS, vm.Status, vm.CreatedAt, vm.CreatedBy, vm.ModifiedBy, vm.DeletedBy, vm.IsDeleted, vm.Forms.ToEntity(), vm.PacketSubmissions.ToEntity());
}

public static List<PacketSubmission> ToEntity(this IList<PacketSubmissionModel> vm)
{
List<PacketSubmission> submissions = new List<PacketSubmission>();

if (vm != null)
{
submissions = vm.Select(p => p.ToEntity()).ToList();
}

return submissions;
}

public static PacketSubmission ToEntity(this PacketSubmissionModel vm)
{
return new PacketSubmission(vm.Id, "", vm.SubmissionDate, vm.VisitId, vm.CreatedAt, vm.CreatedBy, vm.ModifiedBy, "", false, 0);
Expand Down
4 changes: 4 additions & 0 deletions src/UDS.Net.Forms/Models/FormModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public bool AllowsRemote
[Required]
public bool IsDeleted { get; set; }

public int? UnresolvedErrorCount { get; set; }

public List<PacketSubmissionErrorModel> UnresolvedErrors { get; set; } = new List<PacketSubmissionErrorModel>();

public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (Status == FormStatus.NotStarted)
Expand Down
9 changes: 9 additions & 0 deletions src/UDS.Net.Forms/Models/PacketModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
namespace UDS.Net.Forms.Models
{
public class PacketModel : VisitModel
{
public virtual IList<PacketSubmissionModel> PacketSubmissions { get; set; } = new List<PacketSubmissionModel>();
}
}

11 changes: 0 additions & 11 deletions src/UDS.Net.Forms/Models/PacketSubmissionErrorsPaginatedModel.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/UDS.Net.Forms/Models/PacketSubmissionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class PacketSubmissionModel

public int? ErrorCount { get; set; }

public virtual PacketSubmissionErrorsPaginatedModel Errors { get; set; } = new PacketSubmissionErrorsPaginatedModel();
public List<PacketSubmissionErrorModel> Errors { get; set; } = new List<PacketSubmissionErrorModel>();

public string GetFileName(string participantLegacyId, DateTime visitDate)
{
return $"UDS_{participantLegacyId}_{visitDate.Year}_EXPORTED_{SubmissionDate.ToFileTime()}.csv";
Expand Down
10 changes: 0 additions & 10 deletions src/UDS.Net.Forms/Models/PacketSubmissionsPaginatedModel.cs

This file was deleted.

37 changes: 37 additions & 0 deletions src/UDS.Net.Forms/Models/PageModels/PacketPageModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using UDS.Net.Forms.Extensions;
using UDS.Net.Services;

namespace UDS.Net.Forms.Models.PageModels
{
public class PacketPageModel : PageModel
{
protected readonly IPacketService _packetService;

[BindProperty]
public PacketModel? Packet { get; set; }

public PacketPageModel(IPacketService packetService) : base()
{
_packetService = packetService;
}

public async Task<IActionResult> OnGetAsync(int? id)
{
if (id == null || id == 0)
return NotFound();

var packet = await _packetService.GetById("", id.Value);

if (packet == null)
return NotFound();

Packet = packet.ToVM();

return Page();
}
}
}

48 changes: 0 additions & 48 deletions src/UDS.Net.Forms/Models/PageModels/PacketSubmissionPageModel.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/UDS.Net.Forms/Models/VisitModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class VisitModel

public bool CanBeFinalized { get; set; } = false;

public int? TotalUnresolvedErrorCount { get; set; }

[Required]
public DateTime CreatedAt { get; set; }

Expand All @@ -53,7 +55,6 @@ public class VisitModel

public virtual IList<FormModel> Forms { get; set; } = new List<FormModel>();

public virtual IList<PacketSubmissionModel> PacketSubmissions { get; set; } = new List<PacketSubmissionModel>();
}
}

2 changes: 1 addition & 1 deletion src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<input asp-for="PacketSubmission.CreatedAt" type="hidden" />
<input asp-for="PacketSubmission.CreatedBy" type="hidden" />
<button type="submit" class="inline-flex w-full justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 sm:col-start-2">Yes, download</button>
<a asp-page="Index" asp-route-visitId="@Model.Visit.Id" class="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:col-start-1 sm:mt-0">Cancel</a>
<a asp-page="Index" asp-route-visitId="@Model.Packet.Id" class="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:col-start-1 sm:mt-0">Cancel</a>
</div>
</div>

Expand Down
28 changes: 13 additions & 15 deletions src/UDS.Net.Forms/Pages/PacketSubmissions/Create.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,54 @@ namespace UDS.Net.Forms.Pages.PacketSubmissions
{
public class CreateModel : PageModel
{
protected readonly IVisitService _visitService;
protected readonly IParticipationService _participationService;
protected readonly IPacketSubmissionService _packetSubmissionService;
protected readonly IPacketService _packetService;

[BindProperty]
public PacketSubmissionModel? PacketSubmission { get; set; }

public VisitModel? Visit { get; set; }
public PacketModel? Packet { get; set; }

public string PageTitle
{
get
{
if (Visit != null)
if (Packet != null)
{
return $"Participant {Visit.Participation.LegacyId} Visit {Visit.VISITNUM} Packet Submissions";
return $"Participant {Packet.Participation.LegacyId} Visit {Packet.VISITNUM} Packet Submissions";
}
return "";
}
}

public CreateModel(IVisitService visitService, IParticipationService participationService, IPacketSubmissionService packetSubmissionService)
public CreateModel(IParticipationService participationService, IPacketService packetService)
{
_visitService = visitService;
_participationService = participationService;
_packetSubmissionService = packetSubmissionService;
_packetService = packetService;
}

public async Task<IActionResult> OnGetAsync(int? visitId)
{
if (visitId == null || visitId == 0)
return NotFound();

var visit = await _visitService.GetById("", visitId.Value);
var packet = await _packetService.GetById("", visitId.Value);

if (visit == null)
if (packet == null)
return NotFound();

var participation = await _participationService.GetById("", visit.ParticipationId);
var participation = await _participationService.GetById("", packet.ParticipationId);

if (participation == null)
return NotFound();

Visit = visit.ToVM();
Packet = packet.ToVM();

Visit.Participation = participation.ToVM();
Packet.Participation = participation.ToVM();

PacketSubmission = new PacketSubmissionModel
{
VisitId = visit.Id,
VisitId = packet.Id,
SubmissionDate = DateTime.Now,
CreatedAt = DateTime.UtcNow,
CreatedBy = User.Identity.IsAuthenticated ? User.Identity.Name : "Username"
Expand All @@ -77,7 +75,7 @@ public async Task<IActionResult> OnPostAsync()
try
{
// TODO add isn't working yet
await _packetSubmissionService.Add(User.Identity.IsAuthenticated ? User.Identity.Name : "Username", PacketSubmission.ToEntity());
await _packetService.Update(User.Identity.IsAuthenticated ? User.Identity.Name : "Username", Packet.ToEntity());
}
catch (Exception ex)
{
Expand Down
4 changes: 2 additions & 2 deletions src/UDS.Net.Forms/Pages/PacketSubmissions/Details.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace UDS.Net.Forms.Pages.PacketSubmissions
{
public class DetailsModel : PacketSubmissionPageModel
public class DetailsModel : PacketPageModel
{
public DetailsModel(IVisitService visitService, IPacketSubmissionService packetSubmissionService) : base(visitService, packetSubmissionService)
public DetailsModel(IPacketService packetService) : base(packetService)
{
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/UDS.Net.Forms/Pages/PacketSubmissions/Edit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace UDS.Net.Forms.Pages.PacketSubmissions
{
public class EditModel : PacketSubmissionPageModel
public class EditModel : PacketPageModel
{
public EditModel(IVisitService visitService, IPacketSubmissionService packetSubmissionService) : base(visitService, packetSubmissionService)
public EditModel(IPacketService packetSubmissionService) : base(packetSubmissionService)
{
}
}
Expand Down
Loading

0 comments on commit 00816a1

Please sign in to comment.