This commit is contained in:
Paul Schneider 2026-02-16 00:14:33 +00:00
commit ca03b496db
19 changed files with 45 additions and 106 deletions

View file

@ -13,19 +13,19 @@ namespace Yavsc.Controllers
public HyperLinkController(ApplicationDbContext context)
{
_context = context;
_context = context;
}
// GET: HyperLink
public async Task<IActionResult> Index()
{
return View(await _context.HyperLink.ToListAsync());
return Ok(await _context.HyperLink.ToListAsync());
}
// GET: HyperLink/Details/5
public async Task<IActionResult> Details(string href, string method)
{
if (href == null || method ==null)
if (href == null || method == null)
{
return NotFound();
}
@ -36,14 +36,9 @@ namespace Yavsc.Controllers
return NotFound();
}
return View(hyperLink);
return Ok(hyperLink);
}
// GET: HyperLink/Create
public IActionResult Create()
{
return View();
}
// POST: HyperLink/Create
[HttpPost]
@ -54,15 +49,15 @@ namespace Yavsc.Controllers
{
_context.HyperLink.Add(hyperLink);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
return Ok(hyperLink);
}
return View(hyperLink);
return BadRequest(ModelState);
}
// GET: HyperLink/Edit/5
public async Task<IActionResult> Edit(string href, string method)
{
if (href == null || method ==null)
if (href == null || method == null)
{
return NotFound();
}
@ -72,7 +67,7 @@ namespace Yavsc.Controllers
{
return NotFound();
}
return View(hyperLink);
return Ok(hyperLink);
}
// POST: HyperLink/Edit/5
@ -84,36 +79,17 @@ namespace Yavsc.Controllers
{
_context.Update(hyperLink);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
return Ok(hyperLink);
}
return View(hyperLink);
}
// GET: HyperLink/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(string href, string method)
{
if (href == null || method ==null)
{
return NotFound();
}
HyperLink hyperLink = await _context.HyperLink.SingleAsync(m => m.HRef == href && m.Method == method);
if (hyperLink == null)
{
return NotFound();
}
return View(hyperLink);
return BadRequest(ModelState);
}
// POST: HyperLink/Delete/5
[HttpPost, ActionName("Delete")]
[HttpDelete, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string HRef, string Method)
{
if (HRef == null || Method ==null)
if (HRef == null || Method == null)
{
return NotFound();
}
@ -122,7 +98,7 @@ namespace Yavsc.Controllers
_context.HyperLink.Remove(hyperLink);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
return Ok();
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 841 B

View file

@ -30,6 +30,8 @@ namespace Yavsc.Controllers
this._dbContext = context;
}
[Authorize("AdministratorOnly")]
public async Task<IActionResult> Role(string id)
{
var role = await _roleManager.FindByIdAsync(id);
@ -39,7 +41,7 @@ namespace Yavsc.Controllers
Id = id,
Name = role.Name,
Users = (await this._userManager.GetUsersInRoleAsync(role.Name))
.Select(u => new UserInfo (id, u.UserName, u.Email, u.Avatar)).ToArray()
.Select(u => new UserInfo(id, u.UserName, u.Email, u.Avatar)).ToArray()
};
return View(roleUserCollection);
}
@ -62,17 +64,16 @@ namespace Yavsc.Controllers
if (!resultCreate.Succeeded)
{
AddErrors(resultCreate);
return false;
}
}
if (ModelState.ErrorCount > 0) return false;
return true;
}
/// <summary>
/// Gives the (new if was not existing) administrator role
/// to current authenticated user, when no existing
/// administrator was found.
/// When nothing is to do, it returns a 404.
/// Gives the new, when not existing, administrator role
/// to current authenticated user.
/// If nothing is to do, it returns a 404.
/// </summary>
/// <returns></returns>
[Produces("application/json")]
@ -110,7 +111,6 @@ namespace Yavsc.Controllers
}
[Authorize("AdministratorOnly")]
[Produces("application/json")]
public async Task<IActionResult> Index()
{
var adminCount = await _userManager.GetUsersInRoleAsync(
@ -197,6 +197,7 @@ namespace Yavsc.Controllers
ViewBag.UserId = new SelectList(_dbContext.Users, "Id", "UserName");
return View(model);
}
private void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)

View file

@ -7,7 +7,7 @@ using Yavsc.Models;
namespace Yavsc.Controllers
{
[Authorize()]
[Authorize("AdministratorOnly")]
public class DatabaseController : Controller
{
private readonly ILogger<DatabaseController> logger;

View file

@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Attributes.Validation;
namespace Yavsc.Models.Musical
@ -17,7 +18,10 @@ namespace Yavsc.Models.Musical
public int Rate { get; set; }
[YaRequired]
public long TendencyId {get; set; }
public long TendencyId { get; set; }
[ForeignKey("TendencyId")]
public virtual MusicalTendency MusicalTendency { get; set; }
}
}

View file

@ -15,6 +15,7 @@ namespace Yavsc.Models.Payment {
[YaRequired]
public string ExecutorId { get; set; }
[ForeignKey("ExecutorId")]
public virtual ApplicationUser Executor { get; set; }

View file

@ -18,4 +18,4 @@
<ProjectReference Include="..\Abstract\Abstract.csproj" />
<ProjectReference Include="..\Server\Server.csproj" />
</ItemGroup>
</Project>
</Project>