Upload ruck
This commit is contained in:
12
RecordMyRuck/Controllers/HomeController.cs
Normal file
12
RecordMyRuck/Controllers/HomeController.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace RecordMyRuck.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
67
RecordMyRuck/Controllers/RuckController.cs
Normal file
67
RecordMyRuck/Controllers/RuckController.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using RecordMyRuck.Models;
|
||||
|
||||
namespace RecordMyRuck.Controllers
|
||||
{
|
||||
public class RuckController : Controller
|
||||
{
|
||||
private const string DateTimeFormat = "u";
|
||||
|
||||
private readonly IRuckRepository _ruckRepository;
|
||||
|
||||
public RuckController(IRuckRepository ruckRepository)
|
||||
{
|
||||
_ruckRepository = ruckRepository;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult New()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult New(RuckUpload ruckUpload)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return View(ruckUpload);
|
||||
}
|
||||
|
||||
var gpxStream = ruckUpload.Route.OpenReadStream();
|
||||
var reader = new StreamReader(gpxStream);
|
||||
var gpxData = reader.ReadToEnd();
|
||||
_ruckRepository.CreateRuck(new Ruck
|
||||
{
|
||||
DateTime = ruckUpload.DateTime,
|
||||
Route = gpxData,
|
||||
WeightPounds = ruckUpload.WeightPounds,
|
||||
Notes = ruckUpload.Notes ?? "",
|
||||
});
|
||||
return RedirectToAction("Edit", new { dateTimeString = ruckUpload.DateTime.ToString(DateTimeFormat) });
|
||||
}
|
||||
|
||||
public IActionResult Edit(string dateTimeString)
|
||||
{
|
||||
DateTime dateTime;
|
||||
try
|
||||
{
|
||||
dateTime = DateTime.ParseExact(dateTimeString, DateTimeFormat, null);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
var ruck = _ruckRepository.Get(dateTime);
|
||||
if (ruck == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return View(ruck);
|
||||
}
|
||||
}
|
||||
}
|
46
RecordMyRuck/Migrations/20240517025819_CreateRuck.Designer.cs
generated
Normal file
46
RecordMyRuck/Migrations/20240517025819_CreateRuck.Designer.cs
generated
Normal file
@ -0,0 +1,46 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using RecordMyRuck.Models;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace RecordMyRuck.Migrations
|
||||
{
|
||||
[DbContext(typeof(RecordMyRuckDbContext))]
|
||||
[Migration("20240517025819_CreateRuck")]
|
||||
partial class CreateRuck
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.4");
|
||||
|
||||
modelBuilder.Entity("RecordMyRuck.Models.Ruck", b =>
|
||||
{
|
||||
b.Property<DateTime>("DateTime")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Notes")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Route")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<float>("WeightPounds")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.HasKey("DateTime");
|
||||
|
||||
b.ToTable("Rucks");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
36
RecordMyRuck/Migrations/20240517025819_CreateRuck.cs
Normal file
36
RecordMyRuck/Migrations/20240517025819_CreateRuck.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace RecordMyRuck.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class CreateRuck : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Rucks",
|
||||
columns: table => new
|
||||
{
|
||||
DateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
Route = table.Column<string>(type: "TEXT", nullable: false),
|
||||
WeightPounds = table.Column<float>(type: "REAL", nullable: false),
|
||||
Notes = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Rucks", x => x.DateTime);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Rucks");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using RecordMyRuck.Models;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace RecordMyRuck.Migrations
|
||||
{
|
||||
[DbContext(typeof(RecordMyRuckDbContext))]
|
||||
partial class RecordMyRuckDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.4");
|
||||
|
||||
modelBuilder.Entity("RecordMyRuck.Models.Ruck", b =>
|
||||
{
|
||||
b.Property<DateTime>("DateTime")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Notes")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Route")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<float>("WeightPounds")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.HasKey("DateTime");
|
||||
|
||||
b.ToTable("Rucks");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
9
RecordMyRuck/Models/IRuckRepository.cs
Normal file
9
RecordMyRuck/Models/IRuckRepository.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace RecordMyRuck.Models
|
||||
{
|
||||
public interface IRuckRepository
|
||||
{
|
||||
Ruck? Get(DateTime dateTime);
|
||||
IEnumerable<Ruck> GetAll();
|
||||
void CreateRuck(Ruck ruck);
|
||||
}
|
||||
}
|
11
RecordMyRuck/Models/RecordMyRuckDbContext.cs
Normal file
11
RecordMyRuck/Models/RecordMyRuckDbContext.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace RecordMyRuck.Models
|
||||
{
|
||||
public class RecordMyRuckDbContext : Microsoft.EntityFrameworkCore.DbContext
|
||||
{
|
||||
public RecordMyRuckDbContext(DbContextOptions<RecordMyRuckDbContext> options) : base(options) { }
|
||||
|
||||
public DbSet<Ruck> Rucks { get; set; }
|
||||
}
|
||||
}
|
25
RecordMyRuck/Models/Ruck.cs
Normal file
25
RecordMyRuck/Models/Ruck.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace RecordMyRuck.Models
|
||||
{
|
||||
[PrimaryKey(nameof(DateTime))]
|
||||
public class Ruck
|
||||
{
|
||||
[Required]
|
||||
[Display(Name = "Date/Time")]
|
||||
[DataType(DataType.DateTime)]
|
||||
public DateTime DateTime { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Route { get; set; }
|
||||
|
||||
[Required]
|
||||
[Display(Name = "Weigh (lb)")]
|
||||
|
||||
public float WeightPounds { get; set; }
|
||||
|
||||
[DataType(DataType.MultilineText)]
|
||||
public string Notes { get; set; } = "";
|
||||
}
|
||||
}
|
28
RecordMyRuck/Models/RuckRepository.cs
Normal file
28
RecordMyRuck/Models/RuckRepository.cs
Normal file
@ -0,0 +1,28 @@
|
||||
namespace RecordMyRuck.Models
|
||||
{
|
||||
public class RuckRepository : IRuckRepository
|
||||
{
|
||||
RecordMyRuckDbContext _dbContext;
|
||||
|
||||
public RuckRepository(RecordMyRuckDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public void CreateRuck(Ruck ruck)
|
||||
{
|
||||
_dbContext.Rucks.Add(ruck);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
public Ruck? Get(DateTime dateTime)
|
||||
{
|
||||
return _dbContext.Rucks.FirstOrDefault(r => r.DateTime == dateTime);
|
||||
}
|
||||
|
||||
public IEnumerable<Ruck> GetAll()
|
||||
{
|
||||
return _dbContext.Rucks;
|
||||
}
|
||||
}
|
||||
}
|
22
RecordMyRuck/Models/RuckUpload.cs
Normal file
22
RecordMyRuck/Models/RuckUpload.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace RecordMyRuck.Models
|
||||
{
|
||||
public class RuckUpload
|
||||
{
|
||||
[Required]
|
||||
[Display(Name = "Date/Time")]
|
||||
[DataType(DataType.DateTime)]
|
||||
public DateTime DateTime { get; set; }
|
||||
|
||||
[Required]
|
||||
public IFormFile Route { get; set; }
|
||||
|
||||
[Required]
|
||||
[Display(Name = "Weigh (lb)")]
|
||||
public float WeightPounds { get; set; }
|
||||
|
||||
[DataType(DataType.MultilineText)]
|
||||
public string Notes { get; set; } = "";
|
||||
}
|
||||
}
|
22
RecordMyRuck/Program.cs
Normal file
22
RecordMyRuck/Program.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RecordMyRuck.Models;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddDbContext<RecordMyRuck.Models.RecordMyRuckDbContext>(options =>
|
||||
{
|
||||
options.UseSqlite(builder.Configuration["ConnectionStrings:AppDb"]);
|
||||
});
|
||||
builder.Services.AddScoped<IRuckRepository, RuckRepository>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.MapDefaultControllerRoute();
|
||||
|
||||
app.Run();
|
38
RecordMyRuck/Properties/launchSettings.json
Normal file
38
RecordMyRuck/Properties/launchSettings.json
Normal file
@ -0,0 +1,38 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:46321",
|
||||
"sslPort": 44397
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5201",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7197;http://localhost:5201",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
RecordMyRuck/RecordMyRuck.csproj
Normal file
18
RecordMyRuck/RecordMyRuck.csproj
Normal file
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
1
RecordMyRuck/Views/Home/Index.cshtml
Normal file
1
RecordMyRuck/Views/Home/Index.cshtml
Normal file
@ -0,0 +1 @@
|
||||
<p>Hello world!</p>
|
13
RecordMyRuck/Views/Ruck/Edit.cshtml
Normal file
13
RecordMyRuck/Views/Ruck/Edit.cshtml
Normal file
@ -0,0 +1,13 @@
|
||||
@model Ruck
|
||||
|
||||
<h2>Date/Time</h2>
|
||||
@Model.DateTime
|
||||
|
||||
<h2>Weight</h2>
|
||||
@Model.WeightPounds lb
|
||||
|
||||
<h2>Notes</h2>
|
||||
<p>@Model.Notes</p>
|
||||
|
||||
<h2>GPX data</h2>
|
||||
<pre>@Model.Route</pre>
|
5
RecordMyRuck/Views/Ruck/Index.cshtml
Normal file
5
RecordMyRuck/Views/Ruck/Index.cshtml
Normal file
@ -0,0 +1,5 @@
|
||||
@*
|
||||
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
*@
|
||||
@{
|
||||
}
|
21
RecordMyRuck/Views/Ruck/New.cshtml
Normal file
21
RecordMyRuck/Views/Ruck/New.cshtml
Normal file
@ -0,0 +1,21 @@
|
||||
@model RuckUpload
|
||||
|
||||
<h2>Record new ruck</h2>
|
||||
|
||||
<div asp-validation-summary="All"></div>
|
||||
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div>
|
||||
<label asp-for="DateTime"></label><input asp-for="DateTime" type="datetime-local" />
|
||||
</div>
|
||||
<div>
|
||||
<label asp-for="Route"></label><input asp-for="Route" type="file" />
|
||||
</div>
|
||||
<div>
|
||||
<label asp-for="WeightPounds"></label><input asp-for="WeightPounds" type="number" />
|
||||
</div>
|
||||
<div>
|
||||
<label asp-for="Notes"></label><textarea asp-for="Notes" placeholder="Type notes here…"></textarea>
|
||||
</div>
|
||||
<input type="submit" value="Create" />
|
||||
</form>
|
22
RecordMyRuck/Views/Shared/_Layout.cshtml
Normal file
22
RecordMyRuck/Views/Shared/_Layout.cshtml
Normal file
@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Record My Ruck</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Record My Ruck</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a asp-controller="Home" asp-action="Index">Home</a></li>
|
||||
<li><a asp-controller="Ruck" asp-action="New">Record ruck</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<hr />
|
||||
<content>
|
||||
@RenderBody()
|
||||
</content>
|
||||
</body>
|
||||
</html>
|
3
RecordMyRuck/Views/_ViewImports.cshtml
Normal file
3
RecordMyRuck/Views/_ViewImports.cshtml
Normal file
@ -0,0 +1,3 @@
|
||||
@using RecordMyRuck.Models
|
||||
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
3
RecordMyRuck/Views/_ViewStart.cshtml
Normal file
3
RecordMyRuck/Views/_ViewStart.cshtml
Normal file
@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
8
RecordMyRuck/appsettings.Development.json
Normal file
8
RecordMyRuck/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
12
RecordMyRuck/appsettings.json
Normal file
12
RecordMyRuck/appsettings.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"AppDb": "Data Source=RecordMyRuck.db"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
Reference in New Issue
Block a user