diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..03614d7 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +EventsDto.cs \ No newline at end of file diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..55d1bc1 --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,483 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..4ad08a4 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + 1745947457286 + + + + \ No newline at end of file diff --git a/WebApp/ts/eventCreate.js b/WebApp/ts/eventCreate.js new file mode 100644 index 0000000..2013e47 --- /dev/null +++ b/WebApp/ts/eventCreate.js @@ -0,0 +1,61 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +console.log("TypeScript działa!"); +function createEvent() { + return __awaiter(this, void 0, void 0, function* () { + // Pobieranie danych z formularza + const title = document.getElementById('title').value; + const location = document.getElementById('location').value; + const description = document.getElementById('description').value; + const eventDateRaw = document.getElementById('eventDate').value; + const organisationIdRaw = document.getElementById('organisationId').value; + // Walidacja prostych pól + if (!title || !location || !eventDateRaw || !organisationIdRaw) { + alert("Uzupełnij wszystkie wymagane pola!"); + return; + } + const eventDate = new Date(eventDateRaw).toISOString(); + const organisationId = parseInt(organisationIdRaw); + const payload = { + title, + location, + description, + eventDate, + organisationId + }; + try { + const response = yield fetch('/api/events', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload) + }); + if (!response.ok) { + const errorText = yield response.text(); + throw new Error(errorText); + } + alert("Wydarzenie zostało utworzone!"); + window.location.href = "/"; // Przekierowanie do strony głównej + } + catch (error) { + console.error("Błąd podczas tworzenia:", error); + alert("Nie udało się utworzyć wydarzenia: " + error); + } + }); +} +document.addEventListener("DOMContentLoaded", () => { + const saveBtn = document.getElementById("saveBtn"); + if (saveBtn) { + saveBtn.addEventListener("click", (e) => { + e.preventDefault(); + createEvent(); + }); + } +}); diff --git a/WebApp/ts/eventCreate.ts b/WebApp/ts/eventCreate.ts new file mode 100644 index 0000000..356f531 --- /dev/null +++ b/WebApp/ts/eventCreate.ts @@ -0,0 +1,56 @@ +console.log("TypeScript działa!"); + +async function createEvent() { + // Pobieranie danych z formularza + const title = (document.getElementById('title') as HTMLInputElement).value; + const location = (document.getElementById('location') as HTMLInputElement).value; + const description = (document.getElementById('description') as HTMLTextAreaElement).value; + const eventDateRaw = (document.getElementById('eventDate') as HTMLInputElement).value; + const organisationIdRaw = (document.getElementById('organisationId') as HTMLInputElement).value; + + // Walidacja prostych pól + if (!title || !location || !eventDateRaw || !organisationIdRaw) { + alert("Uzupełnij wszystkie wymagane pola!"); + return; + } + + const eventDate = new Date(eventDateRaw).toISOString(); + const organisationId = parseInt(organisationIdRaw); + + const payload = { + title, + location, + description, + eventDate, + organisationId + }; + + try { + const response = await fetch('/api/events', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload) + }); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(errorText); + } + + alert("Wydarzenie zostało utworzone!"); + window.location.href = "/"; // Przekierowanie do strony głównej + } catch (error) { + console.error("Błąd podczas tworzenia:", error); + alert("Nie udało się utworzyć wydarzenia: " + error); + } +} + +document.addEventListener("DOMContentLoaded", () => { + const saveBtn = document.getElementById("saveBtn"); + if (saveBtn) { + saveBtn.addEventListener("click", (e) => { + e.preventDefault(); + createEvent(); + }); + } +}); \ No newline at end of file diff --git a/WebApp/ts/eventDelete.ts b/WebApp/ts/eventDelete.ts new file mode 100644 index 0000000..a16246e --- /dev/null +++ b/WebApp/ts/eventDelete.ts @@ -0,0 +1,24 @@ +document.addEventListener("DOMContentLoaded", () => { + const deleteButtons = document.querySelectorAll(".delete-btn"); + + deleteButtons.forEach(button => { + button.addEventListener("click", async () => { + const id = (button as HTMLButtonElement).dataset.id; + if (!id) return; + + const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?"); + if (!confirmed) return; + + const response = await fetch(`/api/events/${id}`, { + method: "DELETE" + }); + + if (response.ok) { + const row = button.closest("tr"); + if (row) row.remove(); + } else { + alert("Nie udało się usunąć wydarzenia."); + } + }); + }); +}); diff --git a/WebApp/wwwroot/css/site.css b/WebApp/wwwroot/css/site.css index f8d98fc..a3cd7e1 100644 --- a/WebApp/wwwroot/css/site.css +++ b/WebApp/wwwroot/css/site.css @@ -19,4 +19,17 @@ html { body { margin-bottom: 60px; -} \ No newline at end of file +} +.custom-btn { + background: linear-gradient(135deg, #00b09b, #96c93d); + color: white; + border: none; + padding: 12px 24px; + border-radius: 10px; + font-size: 18px; + transition: background 0.3s ease; +} + +.custom-btn:hover { + background: linear-gradient(135deg, #007d71, #7ba328); +} diff --git a/WebApp/wwwroot/js/eventCreate.js b/WebApp/wwwroot/js/eventCreate.js new file mode 100644 index 0000000..2013e47 --- /dev/null +++ b/WebApp/wwwroot/js/eventCreate.js @@ -0,0 +1,61 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +console.log("TypeScript działa!"); +function createEvent() { + return __awaiter(this, void 0, void 0, function* () { + // Pobieranie danych z formularza + const title = document.getElementById('title').value; + const location = document.getElementById('location').value; + const description = document.getElementById('description').value; + const eventDateRaw = document.getElementById('eventDate').value; + const organisationIdRaw = document.getElementById('organisationId').value; + // Walidacja prostych pól + if (!title || !location || !eventDateRaw || !organisationIdRaw) { + alert("Uzupełnij wszystkie wymagane pola!"); + return; + } + const eventDate = new Date(eventDateRaw).toISOString(); + const organisationId = parseInt(organisationIdRaw); + const payload = { + title, + location, + description, + eventDate, + organisationId + }; + try { + const response = yield fetch('/api/events', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload) + }); + if (!response.ok) { + const errorText = yield response.text(); + throw new Error(errorText); + } + alert("Wydarzenie zostało utworzone!"); + window.location.href = "/"; // Przekierowanie do strony głównej + } + catch (error) { + console.error("Błąd podczas tworzenia:", error); + alert("Nie udało się utworzyć wydarzenia: " + error); + } + }); +} +document.addEventListener("DOMContentLoaded", () => { + const saveBtn = document.getElementById("saveBtn"); + if (saveBtn) { + saveBtn.addEventListener("click", (e) => { + e.preventDefault(); + createEvent(); + }); + } +}); diff --git a/WebApp/wwwroot/js/eventDelete.js b/WebApp/wwwroot/js/eventDelete.js new file mode 100644 index 0000000..d8dc896 --- /dev/null +++ b/WebApp/wwwroot/js/eventDelete.js @@ -0,0 +1,34 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +document.addEventListener("DOMContentLoaded", () => { + const deleteButtons = document.querySelectorAll(".delete-btn"); + deleteButtons.forEach(button => { + button.addEventListener("click", () => __awaiter(void 0, void 0, void 0, function* () { + const id = button.dataset.id; + if (!id) + return; + const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?"); + if (!confirmed) + return; + const response = yield fetch(`/api/events/${id}`, { + method: "DELETE" + }); + if (response.ok) { + const row = button.closest("tr"); + if (row) + row.remove(); + } + else { + alert("Nie udało się usunąć wydarzenia."); + } + })); + }); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..0067f3c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "es6", + "strict": true, + "esModuleInterop": true, + "outDir": "WebApp/wwwroot/js", + "lib": [ "es2015", "dom" ] + }, + "include": [ "WebApp/ts/**/*" ] +}