NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using Microsoft.AspNetCore.Http;
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(Event ev)
{
Events.Add(ev);
return Ok($"Event {ev.Name} created successfully!");
}

// POST api/event/join
[HttpPost("join")]
public ActionResult JoinEvent(User user, string eventName)
{
// Check if the event exists
Event eventDetails = Events.FirstOrDefault(e => e.Name == eventName);

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

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

UserEvents[user.Username].Add($"Participant: {user.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.");
}
}
}

<!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>

<!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>

<!-- 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>
</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}!`;
}
});


function displayUpcomingEvents() {

// se JavaScript to fetch and display events
document.addEventListener('DOMContentLoaded', function () {
// Fetch upcoming events from the API
fetch('https://localhost:7299/api/Evensht/upcoming')
.then(response => response.json())
.then(events => {
// Display events on the page
const eventsContainer = document.getElementById('eventsContainer');
events.forEach(event => {
const eventDiv = document.createElement('div');
eventDiv.classList.add('event-container');
eventDiv.innerHTML = `<h3>${event.name}</h3><p>${event.date}</p>`;
eventsContainer.appendChild(eventDiv);
});
})
.catch(error => console.error('Error fetching upcoming events:', error));
});
}


function manageMyEvents() {
// Implement logic to manage user's events using AJAX
// Make an AJAX POST request to the join event endpoint


const eventName = prompt("Enter the event name to join:");
$.post(`https://localhost:7299/api/Evensht/join`, { Username: "currentUsername", EventName: eventName }, function (data) {
alert(data);
});
}

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 the event description:");

$.post(`$https://localhost:7299/api/Evensht/create`, { Name: eventName, Location: location, Date: date, Description: description }, function (data) {
alert(data);
});
}

function trackMyEvents() {
// Implement logic to track user's events using AJAX
// Make an AJAX GET request to the track events endpoint


$.get(`$https://localhost:7299/api/Evensht/track/currentUsername`, function (data) {
alert(JSON.stringify(data));
});
}

function logout() {
// Implement logout logic
$("#registration-form").hide();
$("#login-form").show();
$("#event-management").hide();
}
</script>
</html>
     
 
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.