NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

event Management page
front end------------>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Management System</title>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}

.container {
max-width: 600px;
margin: 50px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h1 {
text-align: center;
color: #333;
}

form {
display: grid;
gap: 15px;
}

label {
font-weight: bold;
}

input,
textarea {
width: 100%;
padding: 10px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}

button {
background-color: #4caf50;
color: #fff;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
}

button:hover {
background-color: #45a049;
}

</style>
<body>

<!-- Event Management Section -->
<h1>"Event scehdule Manager"</h1>
<div id="event-management" >
<h2>Event Management</h2>
<div id="username"></div>
<button onclick="displayUpcomingEvents()">Upcoming Events</button>
<button onclick="manageMyEvents()">Manage My Events</button>


<button onclick="createNewEvent()">Create New Event</button>
<button onclick="trackMyEvents()">Track My Events</button>
<button onclick="logout()">Logout</button>
<div id="eventsContainer"></div>
<div id="manageEventsContainer" style="display: none"> </div>
<div id="trackEventsContainer" style="display: none"> </div>
</div>
</body>
<script>

document.addEventListener('DOMContentLoaded', function () {
// Get the username parameter from the URL
const urlParams = new URLSearchParams(window.location.search);
const username = urlParams.get('username');

// Display the username on the page
const usernameElement = document.getElementById('username');
if (usernameElement) {
usernameElement.textContent = `Welcome, ${username}!`;
}
});

//upcoming event

function displayUpcomingEvents() {
fetch('https://localhost:7299/api/Evensht/upcoming')
.then(response => {
if (!response.ok) {
throw new Error(`Failed to fetch upcoming events: ${response.status} - ${response.statusText}`);
}
return response.json();
})
.then(upcomingEvents => {
const eventsContainer = document.getElementById('eventsContainer');
eventsContainer.innerHTML = '';

upcomingEvents.forEach(event => {
const eventDiv = document.createElement('div');
eventDiv.classList.add('event-container');
eventDiv.innerHTML = `<h3>${event.name}</h3><p><strong>Date:</strong>${event.date}</p><p><strong>Description :</strong>${event.description}</p><p><strong>Location:</strong${event.location}</p>-`;

// Add a Join button with an onclick event to dynamically obtain the event name




const joinButton = document.createElement('button');
joinButton.textContent = 'Join Event';
joinButton.onclick = function () {
joinEvent(event.name);
};

eventDiv.appendChild(joinButton);
eventsContainer.appendChild(eventDiv);
});
})
.catch(error => {
alert(`Error fetching upcoming events: ${error.message}`);
});
}


//join the event
function joinEvent(eventName) {
const urlParams = new URLSearchParams(window.location.search);
const username = urlParams.get('username') || "YourDefaultUsername";
const joinRequest = {
EventName: eventName,
Username: username
};

fetch('https://localhost:7299/api/Evensht/join', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(joinRequest),
})
.then(response => {
if (!response.ok) {
throw new Error(`Failed to join event: ${response.status} - ${response.statusText}`);
}
return response.json();
})
.then(data => {
alert(`Successfully joined event: ${data}`);
// You can perform additional actions here after a successful join
})
.catch(error => {
alert(`Error joining event: ${error.message}`);
});
}


/// manage
function manageMyEvents() {
const urlParams = new URLSearchParams(window.location.search);
const username = urlParams.get('username') || "YourDefaultUsername";



fetch(`https://localhost:7299/api/Evensht/manage/${username}`)
.then(response => {
if (!response.ok) {
throw new Error(`Failed to fetch managed events: ${response.status} - ${response.statusText}`);
}
return response.json();
})
.then(managedEvents => {
const manageEventsContainer = document.getElementById('manageEventsContainer');
manageEventsContainer.innerHTML = '';

if (managedEvents.length > 0) {
managedEvents.forEach(eventInfo => {
const eventDiv = document.createElement('div');
eventDiv.classList.add('event-container');
eventDiv.innerHTML = `<p>${eventInfo}</p>`;
manageEventsContainer.appendChild(eventDiv);
});
} else {
manageEventsContainer.innerHTML = '<p>No events tracked yet.</p>';
}

// Show the manageEventsContainer and hide eventsContainer
document.getElementById('eventsContainer').style.display = 'none';
manageEventsContainer.style.display = 'block';
})
.catch(error => {
alert(`Error fetching managed events: ${error.message}`);
});
}

function createNewEvent() {
// Implement logic to create a new event using AJAX
// Make an AJAX POST request to the create event endpoint
const eventName = prompt("Enter the event name:");
const location = prompt("Enter the event location:");
const date = prompt("Enter the event date (YYYY-MM-DDTHH:mm:ss.fffZ):");


const description = prompt("Enter tEe event description:");

// Data to be sent in the request body
const eventData = {
Name: eventName,
Location: location,
Date: date,
Description: description
};

// Make an AJAX POST request
$.ajax({
type: "POST",
url: "https://localhost:7299/api/Evensht/create",
contentType: "application/json",
data: JSON.stringify(eventData),
success: function (data) {
alert(data);
},
error: function (error) {
alert("Error creating event: " + error.responseText);
}
});
}

//track the events

function trackMyEvents() {
const urlParams = new URLSearchParams(window.location.search);
const username = urlParams.get('username') || "YourDefaultUsername";



fetch(`https://localhost:7299/api/Evensht/track/${username}`)
.then(response => {
if (!response.ok) {
throw new Error(`Failed to fetch tracked events: ${response.status} - ${response.statusText}`);
}
return response.json();
})
.then(trackedEvents => {
const trackEventsContainer = document.getElementById('trackEventsContainer');
trackEventsContainer.innerHTML = '';

if (trackedEvents.length > 0) {
trackedEvents.forEach(eventInfo => {
const eventDiv = document.createElement('div');
eventDiv.classList.add('event-container');
eventDiv.innerHTML = `<p>${eventInfo}</p>`;
trackEventsContainer.appendChild(eventDiv);
});
} else {
trackEventsContainer.innerHTML = '<p>No events tracked yet.</p>';
}

// Show the trackEventsContainer and hide eventsContainer
document.getElementById('eventsContainer').style.display = 'none';




document.getElementById('manageEventsContainer').style.display = 'none';
trackEventsContainer.style.display = 'block';
})
.catch(error => {
alert(`Error fetching tracked events: ${error.message}`);
});
}


function logout() {
window.location.href=`project.html`;

}
</script>
</html>

================================================================================================

login page html---------->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Management System</title>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<style>

h1, h2 {
color: #333;
}

#registration-form, #login-form, #event-management {
max-width: 400px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
}

label {
display: block;
margin-bottom: 5px;
color: #555;
}

input {
width: 100%;
padding: 8px;
margin-bottom: 10px;
box-sizing: border-box;
}

button {
background-color: #4caf50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 3px;
cursor: pointer;
}

button:hover {
background-color: #45a049;
}
</style>
<body>

<h1>Event Management System</h1>

<div id="registration-form" >
<h2>User Registration</h2>
<label for="reg-username">Username:</label>
<input type="text" id="reg-username" required>
<br>
<label for="reg-password">Password:</label>
<input type="password" id="reg-password" required>
<br>
<button onclick="registerUser()">Register</button>
</div>

<!-- User Login Form -->
<div id="login-form" >
<h2>User Login</h2>
<label for="login-username">Username:</label>
<input type="text" id="login-username" required>
<br>
<label for="login-password">Password:</label>
<input type="password" id="login-password" required>
<br>
<button onclick="loginUser()">Login</button>
</div>

<!-- Event Management Section -->
<div id="event-management" style="display: none;">
<h2>Event Management</h2>
<button onclick="displayUpcomingEvents()">Upcoming Events</button>
<button onclick="manageMyEvents()">Manage My Events</button>


<button onclick="createNewEvent()">Create New Event</button>
<button onclick="trackMyEvents()">Track My Events</button>
<button onclick="logout()">Logout</button>
</div>
</body>

<script>
const apiUrl = "https://localhost:7299/api/Evensht";

function registerUser() {
const username = $("#reg-username").val();
const password = $("#reg-password").val();

$.post({
url: "https://localhost:7299/api/Evensht/register",
data: JSON.stringify({ Username: username, Password: password }),
contentType: "application/json",
success: function (data) {
alert("registration sucessful");
},
error: function (xhr, status, error) {
alert("Registration failed. Please try again or change username");
console.error("Error:", xhr.responseText);
}
});
}


function loginUser() {

const username = $("#login-username").val();
const password = $("#login-password").val();

$.post({
url: `https://localhost:7299/api/Evensht/login`,
type:"POST",
contentType: "application/json",
data: JSON.stringify({ Username: username, Password: password }),
success: function(data)
{
if (data.message === "Login successful")
{
alert("login succesfully");
window.location.href= `event login page.html?username=${encodeURIComponent(username)}`;


} else
{
alert("Login failed. Please check your credentials.");
}
},
error: function(error) {
// Handle errors here
console.error("Error during login:", error);
}
});
}
</script>
</body>
</html>


================================================================================================

controller
-------------->

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity.Data;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using WebApplication10.models;

namespace WebApplication10.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class EvenshtController : ControllerBase
{
private static readonly List<User> Users = new List<User>();
private static readonly List<Event> Events = new List<Event>();


private static readonly Dictionary<string, List<string>> EventDetails = new Dictionary<string, List<string>>();
private static readonly Dictionary<string, List<string>> UserEvents = new Dictionary<string, List<string>>();

// POST api/event/register
[HttpPost("register")]
public IActionResult Register(User user)
{
if (Users.Any(u => u.Username == user.Username))
{
return BadRequest("user already exist");

}
Users.Add(user);
return Ok("registration sucessfull ");
}

// POST api/event/login
[HttpPost("login")]
public IActionResult Login([FromBody] User user)
{
if (ModelState.IsValid)
{
if (Users.Any(u => u.Username == user.Username && u.Password == user.Password))
{
return Ok(new { message = "Login successful", username = user.Username });
}
return BadRequest("Invalid credentials.");

}
return BadRequest("Invalid model state");

}

// GET api/event/upcoming
[HttpGet("upcoming")]
public IActionResult GetUpcomingEvents()
{
if(Events.Count ==0)
{
return Ok("no events yet");
}
return Ok(Events);
}

// POST api/event/create
[HttpPost("create")]
public IActionResult CreateEvent([FromBody]Event ev)
{
if(ev==null)
{
return BadRequest("invalid data");
}

Events.Add(ev);
return Ok($"Event {ev.Name} created successfully!");
}

// POST api/event/join
[HttpPost("join")]

public ActionResult JoinEvent([FromBody] JoinRequest joinRequest)
{
string eventName = joinRequest.Eventname;
string username = joinRequest.Username;

// Check if the event exists
Event eventDetails = Events.FirstOrDefault(e => e.Name == eventName);

if (eventDetails == null)
{
return NotFound($"Event '{eventName}' does not exist.");
}

if (!UserEvents.ContainsKey(username))
{
UserEvents[username] = new List<string>();
}

// Check if the user has already joined the event
if (UserEvents[username].Contains($"Participant: {username}, Event: {eventName}"))
{
return Conflict($"User '{username}' has already joined the event '{eventName}'.");
}

UserEvents[username].Add($"Participant: {username}, Event: {eventName}");
// Add more event information as needed

return Ok($"Successfully joined event: {eventName}");
}

// GET api/event/track/{username}



[HttpGet("track/{username}")]
public IActionResult TrackEvents(string username)
{
if (UserEvents.ContainsKey(username))
{
List<string> trackedEvents = UserEvents[username];

if (trackedEvents.Count == 0)
{
return Ok("No events tracked yet.");
}

List<Event> userEventsDetails = new List<Event>();

foreach (string trackedEvent in trackedEvents)
{
// Extract event name from trackedEvent
string eventName = trackedEvent.Split(',')[1].Trim().Split(':')[1].Trim();

// Find the event in Events list
Event eventDetails = Events.FirstOrDefault(e => e.Name == eventName);

if (eventDetails != null)
{
userEventsDetails.Add(eventDetails);
}
}

// Sort events by date
userEventsDetails = userEventsDetails.OrderBy(e => e.Date).ToList();

// Construct detailed event information
List<string> detailedEventInfo = userEventsDetails
.Select(e => $"Event: {e.Name}, Location: {e.Location}, Date: {e.Date}, Description: {e.Description}")
.ToList();

return Ok(detailedEventInfo);
}

return Ok("No events tracked yet.");
}
[HttpGet("manage/{username}")]
public IActionResult Manage(string username)
{
if (UserEvents.ContainsKey(username))
{
List<string> trackedEvents = UserEvents[username];
List<string> detailedEventInfo = new List<string>();

foreach (string trackedEvent in trackedEvents)
{
// Extract event name from trackedEvent
string eventName = trackedEvent.Split(',')[1].Trim().Split(':')[1].Trim();

// Find the event in Events list
Event eventDetails = Events.FirstOrDefault(e => e.Name == eventName);

if (eventDetails != null)
{
// Construct detailed event information
string eventInfo = $"Event: {eventDetails.Name}, Location: {eventDetails.Location}, Date: {eventDetails.Date}, Description: {eventDetails.Description}";
detailedEventInfo.Add(eventInfo);
}
}

return Ok(detailedEventInfo);
}

return Ok("No events tracked yet.");
}
}
}



==============================================================================================

models
---------------------->


namespace WebApplication10.models
{
public class User

{
public string Username { get; set; }
public string Password { get; set; }
}
public class Event
{
public String Name { get; set; }
public string Location { get; set; }
public DateTime Date { get; set; }
public string Description { get; set; }
}
public class JoinRequest
{
public string Eventname { get; set; }
public string Username { get; set; }
}
}



=====================================================================

program
------------------------------>



var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAnyOrigin",
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});

var app = builder.Build();

// Configure the HTTP request pipeline.
app.UseCors("AllowAnyOrigin");

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.