682 lines
18 KiB
C#
682 lines
18 KiB
C#
#region
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MySql.Data.MySqlClient;
|
|
using website.Models;
|
|
using website.Models.events;
|
|
|
|
#endregion
|
|
|
|
namespace website.Controllers {
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class EventController : ControllerBase { // TODO add docs to methods
|
|
|
|
[HttpGet("~/event/get")]
|
|
public ActionResult<Event> get(int eventId) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531, null);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532, null);
|
|
}
|
|
|
|
MySqlCommand cmd = new("SELECT * FROM events where eventId=@eventId", cnn);
|
|
cmd.Parameters.AddWithValue("@eventId", eventId);
|
|
MySqlDataReader rdr = cmd.ExecuteReader();
|
|
|
|
Event evnt = null;
|
|
while (rdr.Read())
|
|
evnt = new Event {
|
|
eventId = rdr.GetInt32("eventId"),
|
|
location = rdr.GetString("location"),
|
|
date = rdr.GetDateTime("date"),
|
|
time = rdr.IsDBNull(3) ? null : rdr.GetTimeSpan("time"),
|
|
color = rdr.IsDBNull(4) ? null : rdr.GetString("color"),
|
|
textColor = rdr.IsDBNull(5) ? null : rdr.GetString("textColor"),
|
|
imageUri = rdr.IsDBNull(6) ? null : rdr.GetString("imageUri"),
|
|
description = rdr.IsDBNull(7) ? null : rdr.GetString("description")
|
|
};
|
|
|
|
cnn.Close();
|
|
if (evnt == null)
|
|
return StatusCode(204, null);
|
|
return StatusCode(200, evnt);
|
|
}
|
|
|
|
|
|
[HttpGet("~/event/getAll")]
|
|
public ActionResult<List<Event>> get() {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531, null);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532, null);
|
|
}
|
|
|
|
MySqlCommand cmd = new("SELECT * FROM events", cnn);
|
|
MySqlDataReader rdr = cmd.ExecuteReader();
|
|
List<Event> events = new();
|
|
|
|
while (rdr.Read())
|
|
events.Add(new Event {
|
|
eventId = rdr.GetInt32("eventId"),
|
|
location = rdr.GetString("location"),
|
|
date = rdr.GetDateTime("date"),
|
|
time = rdr.IsDBNull(3) ? null : rdr.GetTimeSpan("time"),
|
|
color = rdr.IsDBNull(4) ? null : rdr.GetString("color"),
|
|
textColor = rdr.IsDBNull(5) ? null : rdr.GetString("textColor"),
|
|
imageUri = rdr.IsDBNull(6) ? null : rdr.GetString("imageUri"),
|
|
description = rdr.IsDBNull(7) ? null : rdr.GetString("description")
|
|
});
|
|
|
|
cnn.Close();
|
|
if (events.Count == 0)
|
|
return StatusCode(204, null);
|
|
return StatusCode(200, events);
|
|
}
|
|
|
|
[HttpPost("~/admin/event/postCsv.csv")]
|
|
public IActionResult postCsv(IFormFile file) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531, null);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532, null);
|
|
}
|
|
|
|
MySqlCommand cmd;
|
|
|
|
Stream stream = file.OpenReadStream();
|
|
|
|
byte[] byteFile = new byte[stream.Length];
|
|
stream.Read(byteFile);
|
|
|
|
string result = Encoding.Default.GetString(byteFile);
|
|
string[] results = result.Split('\n');
|
|
|
|
for (uint i = 1; i < results.Length-1; i++) {
|
|
string[] items = results[i].Split(',');
|
|
cmd = new(
|
|
"INSERT INTO san_antonio_senior_golf.events (location, date, time, color, textColor, imageUri, description) VALUES (@location, @date, @time, @color, @textColor, @imageUri, @description);",
|
|
cnn);
|
|
|
|
cmd.Parameters.AddWithValue("@location", items[0]);
|
|
cmd.Parameters.AddWithValue("@date", items[1]);
|
|
cmd.Parameters.AddWithValue("@time", items[2]);
|
|
cmd.Parameters.AddWithValue("@color", items[3]);
|
|
cmd.Parameters.AddWithValue("@textColor", items[4]);
|
|
cmd.Parameters.AddWithValue("@imageUri", items[5]);
|
|
cmd.Parameters.AddWithValue("@description", items[6]);
|
|
|
|
cmd.ExecuteReader().Close();
|
|
}
|
|
|
|
return NoContent();
|
|
}
|
|
|
|
[HttpGet("~/event/getBetween")]
|
|
public ActionResult<List<Event>> get(string start, string end) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531, null);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532, null);
|
|
}
|
|
|
|
MySqlCommand cmd = new("SELECT * FROM events WHERE date BETWEEN @start AND @end;", cnn);
|
|
cmd.Parameters.AddWithValue("@start", start);
|
|
cmd.Parameters.AddWithValue("@end", end);
|
|
MySqlDataReader rdr = cmd.ExecuteReader();
|
|
List<Event> events = new();
|
|
|
|
while (rdr.Read())
|
|
events.Add(new Event {
|
|
eventId = rdr.GetInt32("eventId"),
|
|
location = rdr.GetString("location"),
|
|
date = rdr.GetDateTime("date"),
|
|
time = rdr.IsDBNull(3) ? null : rdr.GetTimeSpan("time"),
|
|
color = rdr.IsDBNull(4) ? null : rdr.GetString("color"),
|
|
textColor = rdr.IsDBNull(5) ? null : rdr.GetString("textColor"),
|
|
imageUri = rdr.IsDBNull(6) ? null : rdr.GetString("imageUri"),
|
|
description = rdr.IsDBNull(7) ? null : rdr.GetString("description")
|
|
});
|
|
|
|
cnn.Close();
|
|
if (events.Count == 0)
|
|
return StatusCode(204, null);
|
|
return StatusCode(200, events);
|
|
}
|
|
|
|
[HttpGet("~/event/getYear")]
|
|
public ActionResult<List<Event>> getYear() {
|
|
MySqlConnection cnn = Utilities.getConnection();
|
|
cnn.Open();
|
|
MySqlCommand cmd = new("SELECT * FROM events WHERE date BETWEEN @start AND @end;", cnn);
|
|
cmd.Parameters.AddWithValue("@start", DateTime.Now.AddYears(-1));
|
|
cmd.Parameters.AddWithValue("@end", DateTime.Now.AddYears(1));
|
|
MySqlDataReader rdr = cmd.ExecuteReader();
|
|
List<Event> events = new();
|
|
|
|
while (rdr.Read())
|
|
events.Add(new Event {
|
|
eventId = rdr.GetInt32("eventId"),
|
|
location = rdr.GetString("location"),
|
|
date = rdr.GetDateTime("date"),
|
|
time = rdr.IsDBNull(3) ? null : rdr.GetTimeSpan("time"),
|
|
color = rdr.IsDBNull(4) ? null : rdr.GetString("color"),
|
|
textColor = rdr.IsDBNull(5) ? null : rdr.GetString("textColor"),
|
|
imageUri = rdr.IsDBNull(6) ? null : rdr.GetString("imageUri"),
|
|
description = rdr.IsDBNull(7) ? null : rdr.GetString("description")
|
|
});
|
|
|
|
cnn.Close();
|
|
if (events.Count == 0)
|
|
return StatusCode(204, null);
|
|
return StatusCode(200, events);
|
|
}
|
|
|
|
[HttpGet("~/event/getTodays")]
|
|
public ActionResult<List<Event>> getTodays() {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531, null);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532, null);
|
|
}
|
|
|
|
MySqlCommand cmd = new("SELECT * FROM events WHERE date=curdate()", cnn);
|
|
MySqlDataReader rdr = cmd.ExecuteReader();
|
|
List<Event> events = new();
|
|
|
|
while (rdr.Read())
|
|
events.Add(new Event {
|
|
eventId = rdr.GetInt32("eventId"),
|
|
location = rdr.GetString("location"),
|
|
date = rdr.GetDateTime("date"),
|
|
time = rdr.IsDBNull(3) ? null : rdr.GetTimeSpan("time"),
|
|
color = rdr.IsDBNull(4) ? null : rdr.GetString("color"),
|
|
textColor = rdr.IsDBNull(5) ? null : rdr.GetString("textColor"),
|
|
imageUri = rdr.IsDBNull(6) ? null : rdr.GetString("imageUri"),
|
|
description = rdr.IsDBNull(7) ? null : rdr.GetString("description")
|
|
});
|
|
|
|
cnn.Close();
|
|
if (events.Count == 0)
|
|
return StatusCode(204, null);
|
|
return StatusCode(200, events);
|
|
}
|
|
|
|
[HttpGet("~/event/getLocation")]
|
|
public ActionResult<string> getLocation(int eventId) {
|
|
ObjectResult result = get(eventId).Result as ObjectResult;
|
|
return StatusCode((int)result.StatusCode, ((Event)result.Value).date);
|
|
}
|
|
|
|
[HttpGet("~/event/getDate")]
|
|
public ActionResult<string> getDate(int eventId) {
|
|
ObjectResult result = get(eventId).Result as ObjectResult;
|
|
return StatusCode((int)result.StatusCode, ((Event)result.Value).date);
|
|
}
|
|
|
|
[HttpGet("~/event/getTime")]
|
|
public ActionResult<string>? getTime(int eventId) {
|
|
ObjectResult result = get(eventId).Result as ObjectResult;
|
|
return StatusCode((int)result.StatusCode, ((Event)result.Value).date);
|
|
}
|
|
|
|
[HttpGet("~/event/getColor")]
|
|
public ActionResult<string> getColor(int eventId) {
|
|
ObjectResult result = get(eventId).Result as ObjectResult;
|
|
return StatusCode((int)result.StatusCode, ((Event)result.Value).date);
|
|
}
|
|
|
|
[HttpGet("~/event/getDescription")]
|
|
public ActionResult<string> getDescription(int eventId) {
|
|
ObjectResult result = get(eventId).Result as ObjectResult;
|
|
return StatusCode((int)result.StatusCode, ((Event)result.Value).date);
|
|
}
|
|
|
|
[HttpGet("~/event/getEventsAt")]
|
|
public ActionResult<List<Event>> getEventsAt(string location) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531, null);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532, null);
|
|
}
|
|
|
|
MySqlCommand cmd = new("SELECT * FROM events WHERE location=@location", cnn);
|
|
cmd.Parameters.AddWithValue("@location", location);
|
|
MySqlDataReader rdr = cmd.ExecuteReader();
|
|
List<Event> events = new();
|
|
|
|
while (rdr.Read())
|
|
events.Add(
|
|
new Event {
|
|
eventId = rdr.GetInt32("eventId"),
|
|
location = rdr.GetString("location"),
|
|
date = rdr.GetDateTime("date"),
|
|
time = rdr.IsDBNull(3) ? null : rdr.GetTimeSpan("time"),
|
|
color = rdr.IsDBNull(4) ? null : rdr.GetString("color"),
|
|
textColor = rdr.IsDBNull(5) ? null : rdr.GetString("textColor"),
|
|
imageUri = rdr.IsDBNull(6) ? null : rdr.GetString("imageUri"),
|
|
description = rdr.IsDBNull(7) ? null : rdr.GetString("description")
|
|
});
|
|
|
|
cnn.Close();
|
|
if (events.Count == 0)
|
|
return StatusCode(204, null);
|
|
return StatusCode(200, events);
|
|
}
|
|
|
|
[HttpGet("~/event/getEventsOn")]
|
|
public ActionResult<List<Event>> GetEventsOn(string date) {
|
|
Regex regex = new("^[0-9]{4}/[0-9]{2}/[0-9]{2}$", RegexOptions.IgnoreCase);
|
|
if (!regex.IsMatch(date)) return StatusCode(432, null);
|
|
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531, null);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532, null);
|
|
}
|
|
|
|
MySqlCommand cmd = new("SELECT * FROM events WHERE date=@date", cnn);
|
|
cmd.Parameters.AddWithValue("@date", date);
|
|
MySqlDataReader rdr = cmd.ExecuteReader();
|
|
List<Event> events = new();
|
|
|
|
while (rdr.Read())
|
|
events.Add(
|
|
new Event {
|
|
eventId = rdr.GetInt32("eventId"),
|
|
location = rdr.GetString("location"),
|
|
date = rdr.GetDateTime("date"),
|
|
time = rdr.IsDBNull(3) ? null : rdr.GetTimeSpan("time"),
|
|
color = rdr.IsDBNull(4) ? null : rdr.GetString("color"),
|
|
textColor = rdr.IsDBNull(5) ? null : rdr.GetString("textColor"),
|
|
imageUri = rdr.IsDBNull(6) ? null : rdr.GetString("imageUri"),
|
|
description = rdr.IsDBNull(7) ? null : rdr.GetString("description")
|
|
});
|
|
|
|
cnn.Close();
|
|
if (events.Count == 0)
|
|
return StatusCode(204, null);
|
|
return StatusCode(200, events);
|
|
}
|
|
|
|
[HttpPost("~/admin/event/create")]
|
|
public ActionResult create([FromBody] PostEvent evnt) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532);
|
|
}
|
|
|
|
MySqlCommand cmd =
|
|
new(
|
|
"INSERT INTO san_antonio_senior_golf.events (location, date, time, color, textColor, imageUri, description) VALUES (@location, @date, @time, @color, @textColor, @imageUri, @description);"
|
|
, cnn);
|
|
cmd.Parameters.AddWithValue("@location", evnt.location);
|
|
cmd.Parameters.AddWithValue("@date", evnt.date);
|
|
cmd.Parameters.AddWithValue("@time", evnt.time);
|
|
cmd.Parameters.AddWithValue("@color", evnt.color);
|
|
cmd.Parameters.AddWithValue("@textColor", evnt.textColor);
|
|
cmd.Parameters.AddWithValue("@imageUri", evnt.imageUri);
|
|
cmd.Parameters.AddWithValue("@description", evnt.description);
|
|
|
|
try {
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
cnn.Close();
|
|
return StatusCode(435);
|
|
}
|
|
|
|
cnn.Close();
|
|
return StatusCode(204);
|
|
}
|
|
|
|
[HttpPut("~/admin/event/edit/location")]
|
|
public ActionResult editLocation([FromBody] EditEventLocation editEventLocation) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532);
|
|
}
|
|
|
|
MySqlCommand cmd =
|
|
new("UPDATE san_antonio_senior_golf.events t SET t.location = @location WHERE t.eventId = @eventId;",
|
|
cnn);
|
|
cmd.Parameters.AddWithValue("@location", editEventLocation.location);
|
|
cmd.Parameters.AddWithValue("@eventId", editEventLocation.eventId);
|
|
try {
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
cnn.Close();
|
|
return StatusCode(435);
|
|
}
|
|
|
|
return StatusCode(204);
|
|
}
|
|
|
|
[HttpPut("~/admin/event/edit/date")]
|
|
public ActionResult editDate([FromBody] EditEventDate editEventDate) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532);
|
|
}
|
|
|
|
MySqlCommand cmd =
|
|
new("UPDATE san_antonio_senior_golf.events t SET t.date = @date WHERE t.eventId = @eventId;", cnn);
|
|
cmd.Parameters.AddWithValue("@date", editEventDate.date);
|
|
cmd.Parameters.AddWithValue("@eventId", editEventDate.eventId);
|
|
try {
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
cnn.Close();
|
|
return StatusCode(435);
|
|
}
|
|
|
|
return StatusCode(204);
|
|
}
|
|
|
|
[HttpPut("~/admin/event/edit/time")]
|
|
public ActionResult editTime([FromBody] EditEventTime editEventTime) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532);
|
|
}
|
|
|
|
MySqlCommand cmd =
|
|
new("UPDATE san_antonio_senior_golf.events t SET t.time = @time WHERE t.eventId = @eventId;", cnn);
|
|
cmd.Parameters.AddWithValue("@time", editEventTime.time);
|
|
cmd.Parameters.AddWithValue("@eventId", editEventTime.eventId);
|
|
try {
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
cnn.Close();
|
|
return StatusCode(435);
|
|
}
|
|
|
|
return StatusCode(204);
|
|
}
|
|
|
|
[HttpPut("~/admin/event/edit/color")]
|
|
public ActionResult editColor([FromBody] EditEventColor editEventColor) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532);
|
|
}
|
|
|
|
MySqlCommand cmd =
|
|
new("UPDATE san_antonio_senior_golf.events t SET t.color = @color WHERE t.eventId=@eventId;", cnn);
|
|
cmd.Parameters.AddWithValue("@color", editEventColor.color);
|
|
cmd.Parameters.AddWithValue("@eventId", editEventColor.eventId);
|
|
cmd.ExecuteNonQuery();
|
|
|
|
cnn.Close();
|
|
return StatusCode(204);
|
|
}
|
|
|
|
[HttpPut("~/admin/event/edit/textColor")]
|
|
public ActionResult editTextColor([FromBody] EditEventTextColor editEventTextColor) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532);
|
|
}
|
|
|
|
MySqlCommand cmd =
|
|
new("UPDATE san_antonio_senior_golf.events t SET t.textColor = @textColor WHERE t.eventId=@eventId;",
|
|
cnn);
|
|
cmd.Parameters.AddWithValue("@textColor", editEventTextColor.textColor);
|
|
cmd.Parameters.AddWithValue("@eventId", editEventTextColor.eventId);
|
|
cmd.ExecuteNonQuery();
|
|
|
|
cnn.Close();
|
|
return StatusCode(204);
|
|
}
|
|
|
|
[HttpPut("~/admin/event/edit/imageUri")]
|
|
public ActionResult editImageUri([FromBody] EditEventImageUri editEventImageUri) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532);
|
|
}
|
|
|
|
MySqlCommand cmd =
|
|
new("UPDATE san_antonio_senior_golf.events t SET t.imageUri = @imageUri WHERE t.eventId=@eventId;",
|
|
cnn);
|
|
cmd.Parameters.AddWithValue("@imageUri", editEventImageUri.imageUri);
|
|
cmd.Parameters.AddWithValue("@eventId", editEventImageUri.eventId);
|
|
cmd.ExecuteNonQuery();
|
|
|
|
cnn.Close();
|
|
return StatusCode(204);
|
|
}
|
|
|
|
[HttpPut("~/admin/event/edit/description")]
|
|
public ActionResult editDescription([FromBody] EditEventDescription editEventDescription) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532);
|
|
}
|
|
|
|
MySqlCommand cmd =
|
|
new(
|
|
"UPDATE san_antonio_senior_golf.events t SET t.description = @description WHERE t.eventId=@eventId;",
|
|
cnn);
|
|
cmd.Parameters.AddWithValue("@description", editEventDescription.description);
|
|
cmd.Parameters.AddWithValue("@eventId", editEventDescription.eventId);
|
|
cmd.ExecuteNonQuery();
|
|
|
|
cnn.Close();
|
|
return StatusCode(204);
|
|
}
|
|
|
|
[HttpDelete("~/admin/event/delete")]
|
|
public ActionResult delete(int eventId) {
|
|
MySqlConnection cnn;
|
|
try {
|
|
cnn = Utilities.getConnection();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(531);
|
|
}
|
|
|
|
try {
|
|
cnn.Open();
|
|
}
|
|
catch (MySqlException e) {
|
|
Console.WriteLine(e);
|
|
return StatusCode(532);
|
|
}
|
|
|
|
MySqlCommand cmd = new("DELETE FROM san_antonio_senior_golf.events WHERE eventId=@eventId;", cnn);
|
|
cmd.Parameters.AddWithValue("@eventId", eventId);
|
|
cmd.ExecuteNonQuery();
|
|
|
|
cnn.Close();
|
|
return StatusCode(204);
|
|
}
|
|
}
|
|
} |