Candyroll93
Candyroll93
Explore posts from servers
NNuxt
Created by Candyroll93 on 9/6/2024 in #❓・help
$fetch goes to the incorrect url
No description
4 replies
CC#
Created by Candyroll93 on 5/5/2024 in #help
✅ wanting to learn microservices for new job opportunities.
I’ve successfully deployed an api to docker and connected to MySQL on my network. Now I’d like to learn a few things: 1. If I build a second api then connect it to the first, that is the microservice yes or no? 2. How do these two APIs talk to each other? Please provide resources or links so I can learn further. Thank you.
34 replies
CC#
Created by Candyroll93 on 7/19/2023 in #help
asp api 7 jwt not recognizing "Staff" role but recognizes "Customer" role, verified user has staff
19 replies
CC#
Created by Candyroll93 on 5/26/2023 in #help
❔ api doesn't return anything.
https://github.com/emt2dev/MandalorianAPI .net 6
using MandalorianAPI.Models;
using MandalorianAPI.Data.Enums;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace MandalorianAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class MandoController : ControllerBase
{
private readonly ILogger<MandoController> _logger;

public MandoController(ILogger<MandoController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetMando")]
public IActionResult Index()
//public async Task<IActionResult> Index()
{

var moldyCrow = new StarShip
{
Id = "MC1",
Type = "Mandalorian Dropship",
HyperDriverCapable = true,
Name = "The Moldy Crow",
Ability = Ability.Cloaking,
};

var BoKatanKryze = new Mando
{
Clan = "Kryze",
Name = "Bo-Katan",
Signet = "Night Owls",
HelmetType = "Slim",
ArmorColorPrimary = "Blue",
ArmorColorSecondary = "Teal",
ArmorSpandexColor = "Tan",
SkillSet = SkillSet.Pilot,
Weapon = Weapon.Blaster,
HomePlanet = "Mandalore",
StarShipId = "MC1",
StarShip = moldyCrow,
};

// var objReturning = JsonConvert.SerializeObject(BoKatanKryze);

return Ok(JsonConvert.SerializeObject(BoKatanKryze));
}
}
}
using MandalorianAPI.Models;
using MandalorianAPI.Data.Enums;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace MandalorianAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class MandoController : ControllerBase
{
private readonly ILogger<MandoController> _logger;

public MandoController(ILogger<MandoController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetMando")]
public IActionResult Index()
//public async Task<IActionResult> Index()
{

var moldyCrow = new StarShip
{
Id = "MC1",
Type = "Mandalorian Dropship",
HyperDriverCapable = true,
Name = "The Moldy Crow",
Ability = Ability.Cloaking,
};

var BoKatanKryze = new Mando
{
Clan = "Kryze",
Name = "Bo-Katan",
Signet = "Night Owls",
HelmetType = "Slim",
ArmorColorPrimary = "Blue",
ArmorColorSecondary = "Teal",
ArmorSpandexColor = "Tan",
SkillSet = SkillSet.Pilot,
Weapon = Weapon.Blaster,
HomePlanet = "Mandalore",
StarShipId = "MC1",
StarShip = moldyCrow,
};

// var objReturning = JsonConvert.SerializeObject(BoKatanKryze);

return Ok(JsonConvert.SerializeObject(BoKatanKryze));
}
}
}
This is installed via pkg mgr. Here is my builder
using Newtonsoft.Json.Serialization;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers().AddJsonOptions(options =>
{

}); // Allows to return JSON
using Newtonsoft.Json.Serialization;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers().AddJsonOptions(options =>
{

}); // Allows to return JSON
10 replies
CC#
Created by Candyroll93 on 5/6/2023 in #help
✅ asp.net handling image uploads.
error: NullReferenceException: Object reference not set to an instance of an object. controller:
[HttpPost]
public async Task<IActionResult> Edit(int Id, ClubViewModel _CVM)
{
if (!ModelState.IsValid)
{
ModelState.AddModelError("", "Failed to edit this club");

return View("Edit", _CVM);
}

var clubUploadingImage = await _clubRepository.GetByIdAsync(Id);

if (clubUploadingImage == null) return View("Error");
[HttpPost]
public async Task<IActionResult> Edit(int Id, ClubViewModel _CVM)
{
if (!ModelState.IsValid)
{
ModelState.AddModelError("", "Failed to edit this club");

return View("Edit", _CVM);
}

var clubUploadingImage = await _clubRepository.GetByIdAsync(Id);

if (clubUploadingImage == null) return View("Error");
here is the error
var photoResult = await _photoService.AddPhotoAsync(_CVM.Image);
var photoResult = await _photoService.AddPhotoAsync(_CVM.Image);
here is after the error
if (photoResult.Error != null)
{
ModelState.AddModelError("Image", "Unable to upload photo");
return View(_CVM);
}

if (clubUploadingImage.Image == null)
{
_ = await _photoService.DeletePhotoAsync(clubUploadingImage.Image);
}

var updateClubImage = new Club()
{
Id = _CVM.Id,
Title = _CVM.Title,
Description = _CVM.Description,
Image = photoResult.Url.ToString(),
AddressId = _CVM.AddressId,
Address = _CVM.Address,
ClubCategory = _CVM.ClubCategory,
};

_clubRepository.Update(updateClubImage);

return RedirectToAction("Index");
}
if (photoResult.Error != null)
{
ModelState.AddModelError("Image", "Unable to upload photo");
return View(_CVM);
}

if (clubUploadingImage.Image == null)
{
_ = await _photoService.DeletePhotoAsync(clubUploadingImage.Image);
}

var updateClubImage = new Club()
{
Id = _CVM.Id,
Title = _CVM.Title,
Description = _CVM.Description,
Image = photoResult.Url.ToString(),
AddressId = _CVM.AddressId,
Address = _CVM.Address,
ClubCategory = _CVM.ClubCategory,
};

_clubRepository.Update(updateClubImage);

return RedirectToAction("Index");
}
here is the viewModel's image properties
public class ClubViewModel
{
public int Id { get; set; } // [Key] not required if the id is declared like this
public string? Title { get; set; }
public string? Description { get; set; }
public IFormFile Image { get; set; }
public string? ImageURL { get; set; }
public class ClubViewModel
{
public int Id { get; set; } // [Key] not required if the id is declared like this
public string? Title { get; set; }
public string? Description { get; set; }
public IFormFile Image { get; set; }
public string? ImageURL { get; set; }
the actual model
public string? Image { get; set; }
public string? Image { get; set; }
37 replies
CC#
Created by Candyroll93 on 4/30/2023 in #help
A vs A with helpers tag for controller?
C#
<a asp-controller="Race" asp-action="Details" asp-route-id="@race.Id" class="btn btn-sm btn-outline-secondary">View</a>
<a href="race/details/@race.Id" class="btn btn-sm btn-outline-secondary">View</a>
C#
<a asp-controller="Race" asp-action="Details" asp-route-id="@race.Id" class="btn btn-sm btn-outline-secondary">View</a>
<a href="race/details/@race.Id" class="btn btn-sm btn-outline-secondary">View</a>
What is the acceptable practice?
3 replies