UUUUUUUUH everything works????!? -Add/Delete but still WOW
This commit is contained in:
parent
ba99c0a94b
commit
efcdee701a
|
@ -1,4 +1,5 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using PokemonSleep.Web.Models;
|
using PokemonSleep.Web.Models;
|
||||||
using PokemonSleep.Web.Service.IService;
|
using PokemonSleep.Web.Service.IService;
|
||||||
|
@ -41,5 +42,77 @@ namespace PokemonSleep.Web.Controllers
|
||||||
|
|
||||||
return View(list);
|
return View(list);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public async Task<IActionResult> PokemonCreate()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new Pokemon on Submit
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> PokemonCreate(PokemonDto model)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
ResponseDto? response = await _pokemonService.CreatePokemonAsync(model);
|
||||||
|
|
||||||
|
if (response != null && response.IsSuccess)
|
||||||
|
{
|
||||||
|
TempData["success"] = "Pokemon Created. " + response?.Message;
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TempData["error"] = response?.Message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
//return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Access the "Delete a Pokemon" form
|
||||||
|
public async Task<IActionResult> PokemonDelete(int Id)
|
||||||
|
{
|
||||||
|
ResponseDto? response = await _pokemonService.GetPokemonByIdAsync(Id);
|
||||||
|
|
||||||
|
if (response != null && response.IsSuccess)
|
||||||
|
{
|
||||||
|
PokemonDto? model = JsonConvert.DeserializeObject<PokemonDto>(Convert.ToString(response.Result));
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete a Pokemon on Submit
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> PokemonDelete(PokemonDto pokemonDto)
|
||||||
|
{
|
||||||
|
ResponseDto? response = await _pokemonService.DeletePokemonAsync(pokemonDto.Id);
|
||||||
|
|
||||||
|
if (response != null && response.IsSuccess)
|
||||||
|
{
|
||||||
|
TempData["success"] = "Pokemon Deleted. " + response?.Message;
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TempData["error"] = response?.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(pokemonDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* OH BOY HERE WE GO */
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult GetPokemonDetails(int pokemonId)
|
||||||
|
{
|
||||||
|
var selectedPokemon = _pokemonService.GetPokemonByIdAsync(pokemonId);
|
||||||
|
return Json(selectedPokemon);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PokemonSleep.Web.Service;
|
using PokemonSleep.Web.Service;
|
||||||
using PokemonSleep.Web.Service.IService;
|
using PokemonSleep.Web.Service.IService;
|
||||||
using PokemonSleep.Web.Utility;
|
using PokemonSleep.Web.Utility;
|
||||||
|
using PokemonSleepAPI.Data;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
@ -20,6 +22,8 @@ builder.Services.AddScoped<IPokemonService, PokemonService>();
|
||||||
builder.Services.AddScoped<IPokemonNatureService, PokemonNatureService>();
|
builder.Services.AddScoped<IPokemonNatureService, PokemonNatureService>();
|
||||||
builder.Services.AddScoped<IPokemonSubskillService, PokemonSubskillService>();
|
builder.Services.AddScoped<IPokemonSubskillService, PokemonSubskillService>();
|
||||||
|
|
||||||
|
builder.Services.AddDbContext<PokemonDbContext>(options =>
|
||||||
|
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@model PokemonSleepDto
|
@model PokemonSleepDto
|
||||||
|
<!--
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h1 class="display-4">Welcome</h1>
|
<h1 class="display-4">Welcome</h1>
|
||||||
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||||
|
@ -40,3 +40,61 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<div class="card shadow border-0 mt-4" style ="margin: auto; width: 900px; max-width: 60%; ">
|
||||||
|
<div class="card-header bg-secondary bg-gradient ml-0 py-3">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 text-center">
|
||||||
|
<h1 class="text-info">Available Pokemon</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body p-4">
|
||||||
|
<div class="row pb-3">
|
||||||
|
<div class="col-6">
|
||||||
|
</div>
|
||||||
|
<div class="col-6 text-end">
|
||||||
|
<a asp-controller="Pokemon" asp-action="PokemonCreate" class="btn btn-outline-primary"><i class="bi bi-plus-square"></i> Add New Pokemon</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th scope="col" style="width: 50%;"></th>
|
||||||
|
<th scope="col">#</th>
|
||||||
|
<th scope="col">Pokemon</th>
|
||||||
|
<th scope="col">Sleep Type</th>
|
||||||
|
<th scope="col" style="padding-right: 30px;">Speciality</th>
|
||||||
|
<th scope="col"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var pokemon in Model.pokemonList)
|
||||||
|
{
|
||||||
|
string URL = "https://www.serebii.net/pokemonsleep/pokemon/" + pokemon.Id + ".png";
|
||||||
|
string ShinyURL = "https://www.serebii.net/pokemonsleep/pokemon/shiny/" + pokemon.Id + ".png";
|
||||||
|
|
||||||
|
<tr style=" text-align: center; margin:0; padding: 0; border-bottom: 1px solid purple;">
|
||||||
|
<td style="display: block; margin:0; padding: 0;">
|
||||||
|
<img style=" width: 90px; height: 90px; " src=@URL />
|
||||||
|
<img style=" width: 90px; height: 90px; " src=@ShinyURL />
|
||||||
|
</td>
|
||||||
|
<th scope="row">@pokemon.Id</th>
|
||||||
|
<td> @pokemon.Name</td>
|
||||||
|
<td>@pokemon.SleepType</td>
|
||||||
|
<td style="padding-right: 30px;">@pokemon.Speciality</td>
|
||||||
|
<td>
|
||||||
|
<a asp-controller="Pokemon" asp-action="PokemonDelete" asp-route-Id="@pokemon.Id" class="btn btn-danger">
|
||||||
|
<i class="bi bi-trash"></i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
@model PokemonDto
|
||||||
|
<form asp-action="PokemonCreate">
|
||||||
|
<br />
|
||||||
|
<div class="container border p-3" style="max-width: 60%; ">
|
||||||
|
<h1 class="text-info text-center">Add Pokemon</h1>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<label class="control-label pt-2" style="font-size:20px;">Pokemon</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-10 pb-3">
|
||||||
|
<input asp-for="Name" class="form-control" />
|
||||||
|
<span asp-validation-for="Name" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-2">
|
||||||
|
<label class="control-label pt-2" style="font-size:20px;">Number</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-10 pb-3">
|
||||||
|
<input asp-for="Id" class="form-control" />
|
||||||
|
<span asp-validation-for="Id" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-2">
|
||||||
|
<label class="control-label pt-2" style="font-size:20px;">Sleep Type</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-10 pb-3">
|
||||||
|
<select asp-for="SleepType" class="form-control">
|
||||||
|
<option value="" disabled selected> Choose a Sleep Type</option>
|
||||||
|
<option value="Dozing">Dozing</option>
|
||||||
|
<option value="Snoozing">Snoozing</option>
|
||||||
|
<option value="Slumbering">Slumbering</option>
|
||||||
|
</select>
|
||||||
|
<span asp-validation-for="SleepType" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-2">
|
||||||
|
<label class="control-label pt-2" style="font-size:20px;">Speciality</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-10 pb-3">
|
||||||
|
<select asp-for="Speciality" class="form-control">
|
||||||
|
<option value="" disabled selected> Choose a Speciality</option>
|
||||||
|
<option value="Berries">Berries</option>
|
||||||
|
<option value="Ingredients">Ingredients</option>
|
||||||
|
<option value="Skills">Skills</option>
|
||||||
|
</select>
|
||||||
|
<span asp-validation-for="Speciality" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-5 offset-2">
|
||||||
|
|
||||||
|
<a asp-controller="Home" asp-action="Index" class="btn-primary btn form-control ">Back to List</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-5">
|
||||||
|
<input type="submit" value="Create" class="btn btn-success form-control" />
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
@model PokemonDto
|
||||||
|
<form asp-action="PokemonDelete">
|
||||||
|
<br />
|
||||||
|
<div class="container border p-3">
|
||||||
|
<h1 class="text-warning text-center">Delete Pokemon</h1>
|
||||||
|
<input asp-for="Id" hidden />
|
||||||
|
<hr />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<label class="control-label pt-2" style="font-size:20px;">Pokemon</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-10 pb-3">
|
||||||
|
<input asp-for="Name" disabled class="form-control" />
|
||||||
|
</div>
|
||||||
|
<div class="col-2">
|
||||||
|
<label class="control-label pt-2" style="font-size:20px;">Number</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-10 pb-3">
|
||||||
|
<input asp-for="Id" disabled class="form-control" />
|
||||||
|
</div>
|
||||||
|
<div class="col-2">
|
||||||
|
<label class="control-label pt-2" style="font-size:20px;">Sleep Type</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-10 pb-3">
|
||||||
|
<input asp-for="SleepType" disabled class="form-control" />
|
||||||
|
</div>
|
||||||
|
<div class="col-2">
|
||||||
|
<label class="control-label pt-2" style="font-size:20px;">Speciality</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-10 pb-3">
|
||||||
|
<input asp-for="Speciality" disabled class="form-control" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-5 offset-2">
|
||||||
|
<a asp-controller="Home" asp-action="Index" class="btn-primary btn form-control ">Back to List</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-5">
|
||||||
|
<input type="submit" value="Delete" class="btn btn-danger form-control" />
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
@model PokemonSleepDto
|
|
||||||
|
@model PokemonSleepDto
|
||||||
<div class="card shadow border-0 mt-4">
|
<div class="card shadow border-0 mt-4">
|
||||||
<div class="card-header bg-secondary bg-gradient ml-0 py-3">
|
<div class="card-header bg-secondary bg-gradient ml-0 py-3">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -11,113 +11,182 @@
|
||||||
<div class="card-body p-4">
|
<div class="card-body p-4">
|
||||||
<div class="row pb-3">
|
<div class="row pb-3">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
|
<label>Select Pokemon</label>
|
||||||
|
<select class="form-control form-control-lg" id="pokemonSelect">
|
||||||
|
<option value="" disabled selected>Choose your Pokémon...</option>
|
||||||
|
@foreach(var pokemon in Model.pokemonList)
|
||||||
|
{
|
||||||
|
<option value="@pokemon.Id">@pokemon.Id @pokemon.Name</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6 text-end">
|
<div class="col-6 text-end">
|
||||||
<a class="btn btn-outline-primary"><i class="bi bi-plus-square"></i> Add Pokemon</a>
|
<a class="btn btn-outline-primary"><i class="bi bi-plus-square"></i> Add Pokemon</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<table class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
Select Pokemon
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
|
|
||||||
</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<!--<td><img src="https://www.serebii.net/pokemonsleep/pokemon/{pokemon.Id}.png" alt="Girl in a jacket" width="300" height="300"></td> -->
|
|
||||||
<td>
|
|
||||||
<select class="form-control form-control-lg">
|
|
||||||
<option value="" disabled selected>Choose your Pokémon...</option>
|
|
||||||
@foreach(var pokemon in Model.pokemonList)
|
|
||||||
{
|
|
||||||
string URL = "https://www.serebii.net/pokemonsleep/pokemon/" + pokemon.Id + ".png";
|
|
||||||
|
|
||||||
<img style=" width: 30px; height: 30px; border: 1px solid green; " src=@URL />
|
|
||||||
<option>@pokemon.Id @pokemon.Name</option>
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</tbody>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
Nature
|
|
||||||
</th>
|
|
||||||
<th>Sub Skills</th>
|
|
||||||
<th>
|
|
||||||
</th>
|
|
||||||
<th></th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<select class="form-control form-control-lg">
|
|
||||||
<option value="" disabled selected>Nature</option>
|
|
||||||
@foreach (var nature in Model.natureList)
|
|
||||||
{
|
|
||||||
<option>@nature.Nature</option>
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td>
|
|
||||||
<select class="form-control form-control-lg">
|
|
||||||
<option value="" disabled selected>Sub Skill</option>
|
|
||||||
@foreach (var subskill in Model.subskillList)
|
|
||||||
{
|
|
||||||
<option>@subskill.SubSkill</option>
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select class="form-control form-control-lg">
|
|
||||||
<option value="" disabled selected>Sub Skill</option>
|
|
||||||
@foreach (var subskill in Model.subskillList)
|
|
||||||
{
|
|
||||||
<option>@subskill.SubSkill</option>
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select class="form-control form-control-lg">
|
|
||||||
<option value="" disabled selected>Sub Skill</option>
|
|
||||||
@foreach (var subskill in Model.subskillList)
|
|
||||||
{
|
|
||||||
<option>@subskill.SubSkill</option>
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div id="pokemonDetails" class="mt-4 p-3 border rounded" style="display: none;">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<img id="pokemonImage" src="" alt="Pokemon Image" width="100" height="100" class="me-3">
|
||||||
|
<div>
|
||||||
|
<h3 id="pokemonName"></h3>
|
||||||
|
<p><strong>Pokédex #:</strong> <span id="pokemonId"></span></p>
|
||||||
|
<p><strong>Sleep Type:</strong> <span id="pokemonSleepType"></span></p>
|
||||||
|
<p><strong>Specialty:</strong> <span id="pokemonSpecialty"></span></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">
|
||||||
|
<label for="natureSelect">Select Nature</label>
|
||||||
|
<select id="natureSelect" class="form-control form-control-lg">
|
||||||
|
<option value="" disabled selected>Choose Nature...</option>
|
||||||
|
@foreach (var nature in Model.natureList)
|
||||||
|
{
|
||||||
|
<option value="@nature.Id">@nature.Nature</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<label for="subskillSelect1">Select Sub Skill 1</label>
|
||||||
|
<select id="subskillSelect1" class="form-control form-control-lg">
|
||||||
|
<option value="" disabled selected>Choose Sub Skill...</option>
|
||||||
|
@foreach (var subskill in Model.subskillList)
|
||||||
|
{
|
||||||
|
<option value="@subskill.Id">@subskill.SubSkill</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<label for="subskillSelect2">Select Sub Skill 2</label>
|
||||||
|
<select id="subskillSelect2" class="form-control form-control-lg">
|
||||||
|
<option value="" disabled selected>Choose Sub Skill...</option>
|
||||||
|
@foreach (var subskill in Model.subskillList)
|
||||||
|
{
|
||||||
|
<option value="@subskill.Id">@subskill.SubSkill</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<label for="subskillSelect3">Select Sub Skill 3</label>
|
||||||
|
<select id="subskillSelect3" class="form-control form-control-lg">
|
||||||
|
<option value="" disabled selected>Choose Sub Skill...</option>
|
||||||
|
@foreach (var subskill in Model.subskillList)
|
||||||
|
{
|
||||||
|
<option value="@subskill.Id">@subskill.SubSkill</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col-12">
|
||||||
|
<button id="calculateScore" class="btn btn-primary">Calculate Final Score</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col-12">
|
||||||
|
<h4>Final Score: <span id="finalScore">0</span></h4>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
console.log("Script Loaded Successfully!");
|
||||||
|
var modelData = {
|
||||||
|
pokemonList: @Html.Raw(Json.Serialize(Model.pokemonList)),
|
||||||
|
natureList: @Html.Raw(Json.Serialize(Model.natureList)),
|
||||||
|
subskillList: @Html.Raw(Json.Serialize(Model.subskillList))
|
||||||
|
};
|
||||||
|
var selectedPokemon;
|
||||||
|
console.log(modelData);
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
const selectElement = document.getElementById("pokemonSelect");
|
||||||
|
|
||||||
|
selectElement.addEventListener("change", function () {
|
||||||
|
let pokemonId = this.value;
|
||||||
|
|
||||||
|
if (pokemonId) {
|
||||||
|
fetch(`https://localhost:7001/api/pokemon/${pokemonId}`)
|
||||||
|
.then(response => response.json()) // Directly parse JSON response
|
||||||
|
.then(data => {
|
||||||
|
if (data.isSuccess && data.result) {
|
||||||
|
let pokemon = data.result;
|
||||||
|
// Update HTML with Pokémon details
|
||||||
|
document.getElementById("pokemonImage").src = `https://www.serebii.net/pokemonsleep/pokemon/${pokemon.id}.png`;
|
||||||
|
document.getElementById("pokemonName").textContent = pokemon.name;
|
||||||
|
document.getElementById("pokemonId").textContent = pokemon.id;
|
||||||
|
document.getElementById("pokemonSleepType").textContent = pokemon.sleepType;
|
||||||
|
document.getElementById("pokemonSpecialty").textContent = pokemon.speciality;
|
||||||
|
document.getElementById("pokemonDetails").style.display = "block"; // Show the details div
|
||||||
|
} else {
|
||||||
|
console.error("Error:", data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Error fetching Pokémon data:", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("calculateScore").addEventListener("click", function () {
|
||||||
|
|
||||||
|
|
||||||
|
var pkmnId = document.getElementById("pokemonSelect").value;
|
||||||
|
var natureId = document.getElementById("natureSelect").value;
|
||||||
|
var subskill1Id = document.getElementById("subskillSelect1").value;
|
||||||
|
var subskill2Id = document.getElementById("subskillSelect2").value;
|
||||||
|
var subskill3Id = document.getElementById("subskillSelect3").value;
|
||||||
|
console.log(pkmnId);
|
||||||
|
if (natureId && subskill1Id && subskill2Id && subskill3Id) {
|
||||||
|
// Fetch the selected nature and subskills from the API or preloaded data
|
||||||
|
var pkmn = modelData.pokemonList.find(p => p.id == pkmnId);
|
||||||
|
var nature = modelData.natureList.find(n => n.id == natureId);
|
||||||
|
var subskill1 = modelData.subskillList.find(s => s.id == subskill1Id);
|
||||||
|
var subskill2 = modelData.subskillList.find(s => s.id == subskill2Id);
|
||||||
|
var subskill3 = modelData.subskillList.find(s => s.id == subskill3Id);
|
||||||
|
|
||||||
|
console.log(pkmn)
|
||||||
|
console.log(nature);
|
||||||
|
console.log(subskill1);
|
||||||
|
console.log(subskill2);
|
||||||
|
console.log(subskill3);
|
||||||
|
|
||||||
|
|
||||||
|
// Check if any object is undefined (just in case)
|
||||||
|
if (!pkmn || !nature || !subskill1 || !subskill2 || !subskill3) {
|
||||||
|
alert("Invalid selection. Please check your inputs.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let finalScore = 0; // Initialize score
|
||||||
|
|
||||||
|
// Sum the ranks based on the Pokémon's specialty
|
||||||
|
if (pkmn.speciality === "Berries") {
|
||||||
|
finalScore = nature.berryRating + subskill1.berryRank + subskill2.berryRank + subskill3.berryRank;
|
||||||
|
}
|
||||||
|
else if (pkmn.speciality === "Ingredients") {
|
||||||
|
finalScore = nature.ingredientRating + subskill1.ingredientRank + subskill2.ingredientRank + subskill3.ingredientRank;
|
||||||
|
}
|
||||||
|
else if (pkmn.speciality === "Skills") {
|
||||||
|
finalScore = nature.skillRating + subskill1.skillRank + subskill2.skillRank + subskill3.skillRank;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Update the final score on the screen
|
||||||
|
document.getElementById("finalScore").innerText = finalScore;
|
||||||
|
} else {
|
||||||
|
alert("Please select all options!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
using PokemonSleep.Web.Models;
|
||||||
|
using PokemonSleepAPI.Models;
|
||||||
|
|
||||||
|
namespace PokemonSleep.Web.Views.Pokemon
|
||||||
|
{
|
||||||
|
public class PokemonIndex
|
||||||
|
{
|
||||||
|
PokemonDto Model = new PokemonDto();
|
||||||
|
public int GetRatingForNature(PokemonNature nature)
|
||||||
|
{
|
||||||
|
return nature switch
|
||||||
|
{
|
||||||
|
var n when Model.Speciality == "Berries" => n.BerryRating,
|
||||||
|
var n when Model.Speciality == "Ingredients" => n.IngredientRating,
|
||||||
|
var n when Model.Speciality == "Skill" => n.SkillRating,
|
||||||
|
_ => 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetFitColorForNature(PokemonNature nature)
|
||||||
|
{
|
||||||
|
var rating = GetRatingForNature(nature);
|
||||||
|
return rating > 0 ? "green" : rating < 0 ? "red" : "black";
|
||||||
|
}
|
||||||
|
public int GetRatingForSubskill(PokemonSubskill subskill)
|
||||||
|
{
|
||||||
|
return subskill switch
|
||||||
|
{
|
||||||
|
var s when Model.Speciality == "Berries" => s.BerryRank,
|
||||||
|
var s when Model.Speciality == "Ingredients" => s.IngredientRank,
|
||||||
|
var s when Model.Speciality == "Skill" => s.SkillRank,
|
||||||
|
_ => 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetFitColorForSubskill(PokemonSubskill subskill)
|
||||||
|
{
|
||||||
|
var rating = GetRatingForSubskill(subskill);
|
||||||
|
return rating > 0 ? "green" : rating < 0 ? "red" : "black";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||||
<link rel="stylesheet" href="~/PokemonSleep.Web.styles.css" asp-append-version="true" />
|
<link rel="stylesheet" href="~/PokemonSleep.Web.styles.css" asp-append-version="true" />
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||||
|
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css" /> <!-- Toastr -->
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
|
@ -34,17 +35,19 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<main role="main" class="pb-3">
|
<main role="main" class="pb-3">
|
||||||
@RenderBody()
|
@RenderBody()
|
||||||
|
<partial name="_Notifications" />
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer class="footer text-muted">
|
<footer class="footer text-muted">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<i class="bi bi-arrow-through-heart-fill"></i>
|
Made with Love <i class="bi bi-arrow-through-heart"></i> -K
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||||
|
|
||||||
@await RenderSectionAsync("Scripts", required: false)
|
@await RenderSectionAsync("Scripts", required: false)
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
@if (TempData["error"] != null)
|
||||||
|
{
|
||||||
|
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js" integrity="sha512-VEd+nq25CkR676O+pLBnDW09R7VQX9Mdiij052gVCp5yVH3jGtH70Ho/UUv4mJDsEdTvqRCFZg0NKGiojGnUCw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
toastr.error('@TempData["error"]')
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (TempData["success"] != null)
|
||||||
|
{
|
||||||
|
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js" integrity="sha512-VEd+nq25CkR676O+pLBnDW09R7VQX9Mdiij052gVCp5yVH3jGtH70Ho/UUv4mJDsEdTvqRCFZg0NKGiojGnUCw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
toastr.success('@TempData["success"]')
|
||||||
|
</script>
|
||||||
|
}
|
|
@ -8,5 +8,8 @@
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ServiceUrls": {
|
"ServiceUrls": {
|
||||||
"PokemonSleepAPI": "https://localhost:7001"
|
"PokemonSleepAPI": "https://localhost:7001"
|
||||||
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DefaultConnection": "Server=(localdb)\\MSSQLFishbowlDB;Database=PokemonSleep;Trusted_Connection=True;TrustServerCertificate=True"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
// for details on configuring this project to bundle and minify static web assets.
|
// for details on configuring this project to bundle and minify static web assets.
|
||||||
|
|
||||||
// Write your JavaScript code.
|
// Write your JavaScript code.
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,13 @@ namespace PokemonSleepAPI.Controllers
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Pokemon pokemon = _db.Pokemons.FirstOrDefault(p => p.Id == id);
|
Pokemon pokemon = _db.Pokemons.FirstOrDefault(p => p.Id == id);
|
||||||
_response.Message = $"{pokemon.Name} found.";
|
if (pokemon == null)
|
||||||
|
{
|
||||||
|
_response.IsSuccess = false;
|
||||||
|
_response.Message = "Pokemon not found.";
|
||||||
|
return _response;
|
||||||
|
}
|
||||||
|
_response.Message = $"{pokemon.Name} found.";
|
||||||
_response.Result = _mapper.Map<PokemonDto>(pokemon);
|
_response.Result = _mapper.Map<PokemonDto>(pokemon);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,6 +67,7 @@ namespace PokemonSleepAPI.Controllers
|
||||||
return _response;
|
return _response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add a Pokemon */
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ResponseDto PostPokemon([FromBody] PokemonDto pokemonDto) {
|
public ResponseDto PostPokemon([FromBody] PokemonDto pokemonDto) {
|
||||||
try
|
try
|
||||||
|
@ -68,7 +75,7 @@ namespace PokemonSleepAPI.Controllers
|
||||||
Pokemon pokemon = _mapper.Map<Pokemon>(pokemonDto);
|
Pokemon pokemon = _mapper.Map<Pokemon>(pokemonDto);
|
||||||
_db.Pokemons.Add(pokemon);
|
_db.Pokemons.Add(pokemon);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
|
_response.Message = $"{pokemon.Name} added to Database.";
|
||||||
_response.Result = _mapper.Map<PokemonDto>(pokemon);
|
_response.Result = _mapper.Map<PokemonDto>(pokemon);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
|
@ -17,14 +16,24 @@ builder.Services.AddSwaggerGen();
|
||||||
builder.Services.AddDbContext<PokemonDbContext>(options =>
|
builder.Services.AddDbContext<PokemonDbContext>(options =>
|
||||||
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
IMapper mapper = MappingConfig.RegisterMaps().CreateMapper();
|
IMapper mapper = MappingConfig.RegisterMaps().CreateMapper();
|
||||||
builder.Services.AddSingleton(mapper);
|
builder.Services.AddSingleton(mapper);
|
||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||||
|
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("AllowAllOrigins",
|
||||||
|
builder => builder.AllowAnyOrigin()
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyHeader());
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
app.UseCors("AllowAllOrigins");
|
||||||
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue