Skip to content

Commit

Permalink
Added createKit
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron.allen authored and aaron.allen committed Nov 14, 2023
1 parent ef435e8 commit 0fc2637
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Data/Kit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public partial class Kit

public bool? Shoulddisplay { get; set; }

public string? ThumbnailPath { get; set; }

public virtual Creature? Creature { get; set; }

public virtual ICollection<KitAccessory> KitAccessories { get; set; } = new List<KitAccessory>();
Expand Down
1 change: 1 addition & 0 deletions Data/PostgresContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.ToTable("kit", "toy");

entity.Property(e => e.Id).HasColumnName("id");
entity.Property(e => e.ThumbnailPath).HasColumnName("thumbnail_path");
entity.Property(e => e.CreatureId).HasColumnName("creature_id");
entity.Property(e => e.Kitname)
.HasMaxLength(40)
Expand Down
45 changes: 45 additions & 0 deletions Pages/CreateKit.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@page "/CreateKit"
@inject ILogger<CreateKit> Logger
@using Microsoft.EntityFrameworkCore;
@using MythicalToyMachine.Data
@inject IDbContextFactory<PostgresContext> dbcontext

<EditForm Model="@Model" OnSubmit="@Submit">
<InputText @bind-Value="Model!.Kitname" />
<InputFile OnChange="@LoadPick"/>
<button type="submit">Submit</button>

</EditForm>

@code {
public Kit Model { get; set; } = new Kit();
private bool cannotSavePick = false;

protected override void OnInitialized() => Model ??= new();

private void Submit()
{
Logger.LogInformation("Model.Id = {Id}", Model.Id);
}

private async Task LoadPick(InputFileChangeEventArgs e)
{
var filetype = e.GetType;
try{
if (Model.Kitname is null)
{
Model.Kitname = Model.Id.ToString();
}
//Model.Kitname = Model.Kitname.Replace(" ", "");
var path = $"wwwroot/Images/{Model.Kitname.Replace(" ", "") + Model.Id}.jpg";
await using FileStream fs = new(path, FileMode.Create);
await e.File.OpenReadStream().CopyToAsync(fs); //maxfilesize
}
catch (Exception ex)
{
cannotSavePick = true;
}
}

}
2 changes: 1 addition & 1 deletion Pages/Shop.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@foreach (var k in Kits)
{
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="\Images\KidWithToys.jpg">
<img class="card-img-top" src=@k.ThumbnailPath>
<div class="card-body">
<h5 class="card-title">@(k.Kitname) </h5>
<h7 class="card-body">@(k.Creature?.Creaturename) base figure</h7>
Expand Down
4 changes: 2 additions & 2 deletions Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
<span class="oi oi-cart" aria-hidden="true"></span> Shopping Cart
</NavLink>
</div>

</div>



<style>
Expand Down
Binary file added wwwroot/Images/toys.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0fc2637

Please sign in to comment.