Compare commits

..

5 Commits

Author SHA1 Message Date
Tracy Pearson
0ef09b334c Functioning partial view usings ajax 2022-12-10 17:01:11 -05:00
Tracy Pearson
075283f884 Functional partialview via ajax 2022-12-10 02:51:51 -05:00
Tracy Pearson
57946e64d5 Attempt to use PartialView 2022-12-10 01:16:37 -05:00
Tracy Pearson
8cb745063d Using sessions is troubled. 2022-11-22 16:53:39 -05:00
Tracy Pearson
57146a02f1 Consumes and FromBody was needed 2022-11-22 16:53:18 -05:00
12 changed files with 179 additions and 7 deletions

3
.gitignore vendored
View File

@@ -3,6 +3,9 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
Caddy/*
!Caddyfile
# User-specific files
*.rsuser
*.suo

16
Caddy/Caddyfile Normal file
View File

@@ -0,0 +1,16 @@
{
log {
output stderr
format json {
time_local
time_format wall_milli
duration_format string
}
level debug
}
}
http://*:9000 {
reverse_proxy localhost:5000
log
}

View File

@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using WebPostPartialJsonObject.Extensions;
using WebPostPartialJsonObject.Models;
namespace WebPostPartialJsonObject.Controllers
@@ -22,12 +23,12 @@ namespace WebPostPartialJsonObject.Controllers
{
return View();
}
[HttpPost]
public IActionResult Index(ExpectedViewModel data)
[HttpPost, Consumes("application/json")]
public IActionResult Index([FromBody] ExpectedViewModel data)
{
return View();
HttpContext.Session.SetObject("KioskSettings", data);
return RedirectToAction("Index", "Settings");
}
public IActionResult Privacy()
{
return View();

View File

@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Mvc;
using WebPostPartialJsonObject.Extensions;
using WebPostPartialJsonObject.Models;
namespace WebPostPartialJsonObject.Controllers
{
public class SettingsController : Controller
{
public IActionResult Index()
{
ExpectedViewModel data = HttpContext.Session.GetObject<ExpectedViewModel>("KioskSettings");
return View(data);
}
[HttpPost]
public IActionResult Reprint([FromForm] int ckinid)
{
ReprintInfo model = new ReprintInfo();
model.CkInId = ckinid;
model.PrinterName = "printer";
return PartialView("ReprintView", model);
}
}
}

View File

@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System.Text.Json.Serialization;
namespace WebPostPartialJsonObject.Extensions
{
public static class SessionExtensions
{
public static void SetObject(this ISession session, string key, object value)
{
session.SetString(key, JsonConvert.SerializeObject(value));
}
public static T GetObject<T>(this ISession session, string key)
{
var value = session.GetString(key);
return value == null ? default : JsonConvert.DeserializeObject<T>(value);
}
}
}

View File

@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
namespace WebPostPartialJsonObject.Models
{
public class ReprintInfo
{
public IEnumerable<string> LabelSets { get; set; }
public IEnumerable<string> LabelNames { get; set; }
public int PrinterType { get; set; }
public string PrinterName { get; set; }
public int CkInId { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace WebPostPartialJsonObject.Models
{
public class ReprintRequest
{
public int CkInId { get; set; }
}
}

View File

@@ -18,7 +18,7 @@
"WebPostPartialJsonObject": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",
"applicationUrl": "http://+:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

View File

@@ -22,8 +22,12 @@ namespace WebPostPartialJsonObject
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromHours(2.0);
});
services.AddControllersWithViews().AddSessionStateTempDataProvider();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
@@ -37,6 +41,7 @@ namespace WebPostPartialJsonObject
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseSession();
app.UseRouting();

View File

@@ -0,0 +1,69 @@
@model WebPostPartialJsonObject.Models.ExpectedViewModel
@{
ViewData["Title"] = "Index";
}
<h1>Index</h1>
<h4>ExpectedViewModel</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Index">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="KioskName" class="control-label"></label>
<input asp-for="KioskName" class="form-control" />
<span asp-validation-for="KioskName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="StartUp" class="control-label"></label>
<input asp-for="StartUp" class="form-control" />
<span asp-validation-for="StartUp" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</form>
<div id="reprintLabels" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Select the labels you want to reprint</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">x</span></button>
</div>
<div class="modal-body" id="reprintLabelsForm"></div>
</div>
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-outline-secondary" id="btnReprintLabels" data-toggle="modal" data-target="#reprintLabels" data-ckinid="123">
Reprint Label(s)
</button>
<div>
<a asp-action="Index">Back to List</a>
</div>
@section Scripts {
@{
await Html.RenderPartialAsync("_ValidationScriptsPartial");
}
<script type="text/javascript">
$('#btnReprintLabels').click(function (e) { pickLabels(e, $(this)); });
function pickLabels(e, element) {
var id = element.data('ckinid');
$.ajax({
type: 'POST',
url: '/Settings/Reprint',
data: { 'ckinid': id },
success: function (response) {
$('#reprintLabelsForm').html(response);
}
});
};
</script>
}

View File

@@ -0,0 +1,10 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@model WebPostPartialJsonObject.Models.ReprintInfo
@{
}
<h5>Partial View @Model.CkInId</h5>
<div>Printer: @Model.PrinterName</div>

View File

@@ -4,4 +4,9 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>