Skip to content

Commit

Permalink
Auto Increment Visit Number (#95)
Browse files Browse the repository at this point in the history
* Progress commit

* Access the last visit number for given participation

* Edits SelectList with VisitKindOptions tag helper

* Adds conditional SelectList depending on LastVisitNumber

* removes whitespace

* Removes ParticipationsSelectList Adds LegacyId

* formatting

* Adds User.Identity?.Name parameter on post

* Adds error message for VisitKind

* Adds hidden input for ParticipationId

* Changes select element to input

---------

Co-authored-by: Ashley Wilson <[email protected]>
  • Loading branch information
smiththay and ashleybot authored Oct 11, 2023
1 parent 96a6815 commit e0bff3d
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 28 deletions.
5 changes: 3 additions & 2 deletions src/UDS.Net.Forms/Extensions/DomainToViewModelMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public static ParticipationModel ToVM(this Participation participation)
{
Id = participation.Id,
LegacyId = participation.LegacyId,
VisitCount = participation.Visits.Count(),
Visits = participation.Visits.ToVM()
VisitCount = participation.Visits == null ? participation.VisitCount : participation.Visits.Count(), // TODO possibly use visitcount on the object??
Visits = participation.Visits.ToVM(),
LastVisitNumber = participation.LastVisitNumber
};
}

Expand Down
5 changes: 4 additions & 1 deletion src/UDS.Net.Forms/Extensions/ViewModelToDomainMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public static Participation ToEntity(this ParticipationModel vm)
CreatedBy = vm.CreatedBy,
ModifiedBy = vm.ModifiedBy,
DeletedBy = vm.DeletedBy,
IsDeleted = vm.IsDeleted
IsDeleted = vm.IsDeleted,
VisitCount = vm.VisitCount,
LastVisitNumber = vm.LastVisitNumber

};
}

Expand Down
2 changes: 2 additions & 0 deletions src/UDS.Net.Forms/Models/ParticipationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ParticipationModel
public bool IsDeleted { get; set; }

public IList<VisitModel> Visits { get; set; } = new List<VisitModel>();

public int LastVisitNumber { get; set; }
}
}

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 @@ -16,7 +16,7 @@ public class VisitModel
[Display(Name = "Number")]
public int Number { get; set; }

[Required]
[Required(ErrorMessage = "Please select a visit type")]
[Display(Name = "Type")]
public VisitKind Kind { get; set; }

Expand All @@ -42,6 +42,7 @@ public class VisitModel
public virtual ParticipationModel? Participation { get; set; }

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

}
}

2 changes: 1 addition & 1 deletion src/UDS.Net.Forms/Pages/Participations/Details.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>


<h2>Details for @Model.Participation.LegacyId</h2>
<h2>Details for @Model.Participation.LegacyId <div class="rounded-full flex-none py-1 px-2 text-xs font-medium ring-1 ring-inset text-indigo-400 bg-indigo-400/10 ring-indigo-400/30">@Model.Participation.VisitCount visits</div></h2>
<table>
<thead>
<tr>
Expand Down
25 changes: 15 additions & 10 deletions src/UDS.Net.Forms/Pages/Visits/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@
}



<form method="post">

<div class="space-y-16 p-16 xl:space-y-20">
<div class="mt-10 space-y-8 border-b border-gray-900/10 pb-12 sm:space-y-0 sm:divide-y sm:divide-gray-900/10 sm:border-t sm:pb-0">

<label for="Visit_ParticipationId">Participant</label>
<select asp-for="Visit.ParticipationId" asp-items="@Model.ParticipationsSelectList" class="mt-2 block w-full rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6">
<option value=""></option>
</select>
<div>
<span><b>Create visit for @Model.Participation.LegacyId</b></span>
</div>
</br>

<input type="hidden" asp-for="Visit.ParticipationId" asp-items="@Model.ParticipationsSelectList">
</input>

<label asp-for="Visit.Kind"></label>
<select asp-for="Visit.Kind" asp-items="Html.GetEnumSelectList<VisitKind>()" class="mt-2 block w-full rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6">
<option value=""></option>
</select>
<div>
<label asp-for="Visit.Kind"></label>
<select asp-for="Visit.Kind" asp-items="Model.VisitKindOptions" class="mt-2 block w-full rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6">
<option value=""></option>
</select>
<span class="mt-2 text-sm text-red-600" asp-validation-for="Visit.Kind"></span>
</div>

<label asp-for="Visit.Number"></label>
<input asp-for="Visit.Number" />
<input asp-for="Visit.Number" value="@Model.SelectedParticipationNextVisit" />

<label asp-for="Visit.StartDateTime"></label>
<input asp-for="Visit.StartDateTime" />
Expand Down
33 changes: 30 additions & 3 deletions src/UDS.Net.Forms/Pages/Visits/Create.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using UDS.Net.Forms.Models;
using UDS.Net.Services;
using UDS.Net.Services.DomainModels;
using UDS.Net.Services.Enums;

namespace UDS.Net.Forms.Pages.Visits
{
Expand All @@ -18,11 +19,13 @@ public class CreateModel : PageModel
protected readonly IVisitService _visitService;

public SelectList ParticipationsSelectList { get; private set; }
public int SelectedParticipationNextVisit { get; private set; }
public int SelectedParticipationNextVisit { get; private set; } = 0;

[BindProperty]
public VisitModel? Visit { get; set; }

public Participation? Participation { get; set; }

public CreateModel(IVisitService visitService, IParticipationService participationService)
{
_visitService = visitService;
Expand All @@ -44,21 +47,45 @@ public async Task PopulateParticipationsDropDownList(int? selectedParticipationI

}

public List<SelectListItem> VisitKindOptions { get; set; }

public async Task<IActionResult> OnGetAsync(int? participationId)
{
await PopulateParticipationsDropDownList(participationId);

Participation = await _participationService.GetById(User.Identity.Name, participationId.Value);

if (Participation != null)
SelectedParticipationNextVisit = Participation.LastVisitNumber + 1;


Visit = new VisitModel
{
Version = "UDS3",
CreatedAt = DateTime.UtcNow,
CreatedBy = User.Identity.IsAuthenticated ? User.Identity.Name : "Username",
StartDateTime = DateTime.Now
StartDateTime = DateTime.Now,
};

if (participationId.HasValue)
Visit.ParticipationId = participationId.Value;

VisitKindOptions = new List<SelectListItem>();

if (Participation != null)
{
if (Participation.LastVisitNumber < 1)
{
VisitKindOptions.Add(new SelectListItem { Value = VisitKind.IVP.ToString(), Text = "IVP" });
VisitKindOptions.Add(new SelectListItem { Value = VisitKind.TIP.ToString(), Text = "TIP" });
}
else if (Participation.LastVisitNumber >= 1)
{
VisitKindOptions.Add(new SelectListItem { Value = VisitKind.FVP.ToString(), Text = "FVP" });
VisitKindOptions.Add(new SelectListItem { Value = VisitKind.TFP.ToString(), Text = "TFP" });
}
}

return Page();
}

Expand All @@ -72,7 +99,7 @@ public async Task<IActionResult> OnPostAsync(int? participationId)
if (Visit != null)
{
Visit.Forms = new List<FormModel>(); // initialize form set
await _visitService.Add("", Visit.ToEntity());
await _visitService.Add(User.Identity?.Name, Visit.ToEntity());
}

return RedirectToPage("./Index");
Expand Down
4 changes: 4 additions & 0 deletions src/UDS.Net.Services/DomainModels/Participation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class Participation
public bool IsDeleted { get; set; }

public IList<Visit> Visits { get; set; } = new List<Visit>();

public int VisitCount { get; set; }

public int LastVisitNumber { get; set; }
}
}

4 changes: 3 additions & 1 deletion src/UDS.Net.Services/Extensions/DomainToDtoMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public static ParticipationDto ToDto(this Participation participation)
CreatedBy = participation.CreatedBy,
ModifiedBy = participation.ModifiedBy,
DeletedBy = participation.DeletedBy,
IsDeleted = participation.IsDeleted
IsDeleted = participation.IsDeleted,
VisitCount = participation.VisitCount,
LastVisitNumber = participation.LastVisitNumber
};
}
public static VisitDto ToDto(this Visit visit)
Expand Down
6 changes: 5 additions & 1 deletion src/UDS.Net.Services/Extensions/DtoToDomainMapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using UDS.Net.Dto;
using UDS.Net.Services.DomainModels;
Expand All @@ -20,7 +21,10 @@ public static Participation ToDomain(this ParticipationDto dto, string username)
CreatedBy = dto.CreatedBy,
ModifiedBy = dto.ModifiedBy,
DeletedBy = dto.DeletedBy,
IsDeleted = dto.IsDeleted
IsDeleted = dto.IsDeleted,
VisitCount = dto.VisitCount,
LastVisitNumber = dto.LastVisitNumber

};

if (dto.Visits != null)
Expand Down
6 changes: 0 additions & 6 deletions src/UDS.Net.Services/UDS.Net.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@
<ItemGroup>
<PackageReference Include="UDS.Net.Dto" Version="1.5.1" />
</ItemGroup>
<ItemGroup>
<None Remove="LookupModels\" />
</ItemGroup>
<ItemGroup>
<Folder Include="LookupModels\" />
</ItemGroup>
</Project>
6 changes: 4 additions & 2 deletions src/UDS.Net.Web.MVC/UDS.Net.Web.MVC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DocumentationFile></DocumentationFile>
<DocumentationFile></DocumentationFile>
<DocumentationFile>
</DocumentationFile>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.18" />
Expand Down

0 comments on commit e0bff3d

Please sign in to comment.