2024-09-28 01:31:46 +01:00
|
|
|
import AdminBadgesViewModel from "../models/admin/AdminBadgesViewModel";
|
|
|
|
import AdminBadgeViewModel from "../models/admin/AdminBadgeViewModel";
|
|
|
|
import AdminDeleteBadgeModel from "../models/admin/AdminDeleteBadgeModel";
|
2024-09-26 00:47:08 +01:00
|
|
|
import AdminIndexViewModel from "../models/admin/AdminIndexViewModel";
|
|
|
|
import AdminPartiesViewModel from "../models/admin/AdminPartiesViewModel";
|
|
|
|
import AdminUsersViewModel from "../models/admin/AdminUsersViewModel";
|
2024-09-28 01:31:46 +01:00
|
|
|
import BadgeService from "../services/BadgeService";
|
2024-09-26 00:47:08 +01:00
|
|
|
import PartyService from "../services/PartyService";
|
|
|
|
import UserService from "../services/UserService";
|
|
|
|
import Controller from "./Controller";
|
|
|
|
|
|
|
|
export default class AdminController_Auth$Admin extends Controller {
|
|
|
|
public async Index_Get() {
|
|
|
|
const adminIndexViewModel: AdminIndexViewModel = {
|
|
|
|
userCount: await UserService.GetUserCount(),
|
|
|
|
partyCount: await PartyService.GetPartyCount()
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.view(adminIndexViewModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Users_Get() {
|
|
|
|
const adminUsersViewModel: AdminUsersViewModel = {
|
|
|
|
users: await UserService.GetAll()
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.view(adminUsersViewModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Parties_Get() {
|
|
|
|
const adminPartiesViewModel: AdminPartiesViewModel = {
|
|
|
|
parties: await PartyService.GetAll()
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.view(adminPartiesViewModel);
|
|
|
|
}
|
2024-09-28 01:31:46 +01:00
|
|
|
|
|
|
|
public async Badges_Get() {
|
|
|
|
const adminBadgesViewModel: AdminBadgesViewModel = {
|
|
|
|
badges: await BadgeService.LoadAll()
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.view(adminBadgesViewModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Badge_Get(adminBadgeViewModel: AdminBadgeViewModel) {
|
|
|
|
const badge = adminBadgeViewModel.id ? await BadgeService.LoadBadge(parseInt(adminBadgeViewModel.id)) : null;
|
|
|
|
if (typeof(adminBadgeViewModel.id) !== "undefined" && badge) {
|
|
|
|
adminBadgeViewModel.name = badge.Name;
|
|
|
|
adminBadgeViewModel.description = badge.Description;
|
|
|
|
adminBadgeViewModel.imageUrl = badge.ImageUrl;
|
|
|
|
adminBadgeViewModel.forUrl = badge.ForUrl;
|
|
|
|
} else {
|
|
|
|
adminBadgeViewModel.name = "";
|
|
|
|
adminBadgeViewModel.description = "";
|
|
|
|
adminBadgeViewModel.imageUrl = "";
|
|
|
|
adminBadgeViewModel.forUrl = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.view(adminBadgeViewModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Badge_Post(adminBadgeViewModel: AdminBadgeViewModel) {
|
|
|
|
if (typeof(adminBadgeViewModel.id) === "undefined") {
|
|
|
|
return this.badRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
await BadgeService.SaveBadge(this.session.userId, parseInt(adminBadgeViewModel.id), adminBadgeViewModel.name ?? "", adminBadgeViewModel.description ?? "", adminBadgeViewModel.imageUrl ?? "", adminBadgeViewModel.forUrl ?? "");
|
|
|
|
|
|
|
|
return this.redirectToAction("badges");
|
|
|
|
}
|
|
|
|
|
|
|
|
public async DeleteBadge_Get(adminDeleteBadgeModel: AdminDeleteBadgeModel) {
|
|
|
|
if (typeof(adminDeleteBadgeModel.id) === "undefined" || typeof(adminDeleteBadgeModel.id) !== "string") {
|
|
|
|
return this.badRequest();
|
|
|
|
}
|
|
|
|
const badgeId = parseInt(adminDeleteBadgeModel.id);
|
|
|
|
|
|
|
|
await BadgeService.DeleteBadge(this.session.userId, badgeId);
|
|
|
|
|
|
|
|
return this.redirectToAction("badges");
|
|
|
|
}
|
2024-09-26 00:47:08 +01:00
|
|
|
}
|