Initial
This commit is contained in:
commit
b2ee3b430a
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/website/bin/
|
||||
/website/obj/
|
||||
/unitTests/bin/
|
||||
/unitTests/obj/
|
13
.idea/.idea.sanAntonioSeniorGolf.dir/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.sanAntonioSeniorGolf.dir/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/modules.xml
|
||||
/.idea.sanAntonioSeniorGolf.iml
|
||||
/contentModel.xml
|
||||
/projectSettingsUpdater.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
16
.idea/.idea.sanAntonioSeniorGolf.dir/.idea/dataSources.xml
generated
Normal file
16
.idea/.idea.sanAntonioSeniorGolf.dir/.idea/dataSources.xml
generated
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="@192.168.1.52" uuid="f3927a93-4184-4a40-99cb-b68c99e90458">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://192.168.1.52:5618</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
<driver-properties>
|
||||
<property name="serverTimezone" value="UTC" />
|
||||
<property name="allowPublicKeyRetrieval" value="TRUE" />
|
||||
</driver-properties>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
4
.idea/.idea.sanAntonioSeniorGolf.dir/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.sanAntonioSeniorGolf.dir/.idea/encodings.xml
generated
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
8
.idea/.idea.sanAntonioSeniorGolf.dir/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.sanAntonioSeniorGolf.dir/.idea/indexLayout.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
25
.idea/.idea.sanAntonioSeniorGolf.dir/.idea/misc.xml
generated
Normal file
25
.idea/.idea.sanAntonioSeniorGolf.dir/.idea/misc.xml
generated
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="BuildServerSettings">
|
||||
<option name="LOGIN" value="" />
|
||||
<option name="SERVER_URL" value="" />
|
||||
<option name="COMMIT_PATTERN" value="{message}" />
|
||||
<option name="REMEMBER_ME" value="true" />
|
||||
<option name="USE_IDEA_PROXY_SETTINGS" value="true" />
|
||||
<option name="INSPECTIONS_BUILD_TYPE_IDS" />
|
||||
<option name="DUPLICATES_BUILD_TYPE_IDS" />
|
||||
<option name="ENABLE_SUITABLE_CONFIGURATION_CACHING" value="true" />
|
||||
<option name="COVERAGE_SETTINGS" />
|
||||
<option name="TEST_STATUS_ENABLED" value="true" />
|
||||
<option name="TEST_STATUS_SHOW_SUCCESSFUL" value="false" />
|
||||
<option name="POSTPONE_SUITABLE_CONFIGURATIONS_SEARCH" value="false" />
|
||||
<option name="ARTIFACTS_BUILD_TYPE_IDS" />
|
||||
<option name="PERFORM_COMMIT_IF_SUCCESSFUL" value="true" />
|
||||
<option name="PERFORM_COMMIT_IF_NO_NEW_FAILED_TESTS" value="false" />
|
||||
<option name="REQUEST_CONFIRMATON" value="false" />
|
||||
<option name="PRE_TESTED_COMMIT" value="true" />
|
||||
<option name="FILTER_BY_STATUS" value="false" />
|
||||
<option name="FILTER_MARKED_AS_FIXED" value="false" />
|
||||
<option name="TOOL_WINDOW_SELECTED_CONTENT_INDEX" value="0" />
|
||||
</component>
|
||||
</project>
|
13
.idea/.idea.sanAntonioSeniorGolf/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.sanAntonioSeniorGolf/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/projectSettingsUpdater.xml
|
||||
/modules.xml
|
||||
/.idea.sanAntonioSeniorGolf.iml
|
||||
/contentModel.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
23
.idea/.idea.sanAntonioSeniorGolf/.idea/dataSources.xml
generated
Normal file
23
.idea/.idea.sanAntonioSeniorGolf/.idea/dataSources.xml
generated
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="MySQL - @192.168.1.52" uuid="1dfcc831-442e-45db-9f92-ef77632f85b5">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://192.168.1.52:5618</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
<driver-properties>
|
||||
<property name="serverTimezone" value="UTC" />
|
||||
<property name="useSSL" value="FALSE" />
|
||||
</driver-properties>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="core.sqlite" uuid="054c42b6-db02-4962-ad8f-31add7bf43ff">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:$USER_HOME$/.local/share/scoreSphere/core.sqlite</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
14
.idea/.idea.sanAntonioSeniorGolf/.idea/deployment.xml
generated
Normal file
14
.idea/.idea.sanAntonioSeniorGolf/.idea/deployment.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PublishConfigData" serverName="boysserver" remoteFilesAllowedToDisappearOnAutoupload="false">
|
||||
<serverData>
|
||||
<paths name="boysserver">
|
||||
<serverdata>
|
||||
<mappings>
|
||||
<mapping deploy="/" local="$PROJECT_DIR$" web="/" />
|
||||
</mappings>
|
||||
</serverdata>
|
||||
</paths>
|
||||
</serverData>
|
||||
</component>
|
||||
</project>
|
4
.idea/.idea.sanAntonioSeniorGolf/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.sanAntonioSeniorGolf/.idea/encodings.xml
generated
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
8
.idea/.idea.sanAntonioSeniorGolf/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.sanAntonioSeniorGolf/.idea/indexLayout.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
6
.idea/.idea.sanAntonioSeniorGolf/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/.idea.sanAntonioSeniorGolf/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="SqlResolveInspection" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
25
.idea/.idea.sanAntonioSeniorGolf/.idea/misc.xml
generated
Normal file
25
.idea/.idea.sanAntonioSeniorGolf/.idea/misc.xml
generated
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="BuildServerSettings">
|
||||
<option name="LOGIN" value="" />
|
||||
<option name="SERVER_URL" value="" />
|
||||
<option name="COMMIT_PATTERN" value="{message}" />
|
||||
<option name="REMEMBER_ME" value="true" />
|
||||
<option name="USE_IDEA_PROXY_SETTINGS" value="true" />
|
||||
<option name="INSPECTIONS_BUILD_TYPE_IDS" />
|
||||
<option name="DUPLICATES_BUILD_TYPE_IDS" />
|
||||
<option name="ENABLE_SUITABLE_CONFIGURATION_CACHING" value="true" />
|
||||
<option name="COVERAGE_SETTINGS" />
|
||||
<option name="TEST_STATUS_ENABLED" value="true" />
|
||||
<option name="TEST_STATUS_SHOW_SUCCESSFUL" value="false" />
|
||||
<option name="POSTPONE_SUITABLE_CONFIGURATIONS_SEARCH" value="false" />
|
||||
<option name="ARTIFACTS_BUILD_TYPE_IDS" />
|
||||
<option name="PERFORM_COMMIT_IF_SUCCESSFUL" value="true" />
|
||||
<option name="PERFORM_COMMIT_IF_NO_NEW_FAILED_TESTS" value="false" />
|
||||
<option name="REQUEST_CONFIRMATON" value="false" />
|
||||
<option name="PRE_TESTED_COMMIT" value="true" />
|
||||
<option name="FILTER_BY_STATUS" value="false" />
|
||||
<option name="FILTER_MARKED_AS_FIXED" value="false" />
|
||||
<option name="TOOL_WINDOW_SELECTED_CONTENT_INDEX" value="0" />
|
||||
</component>
|
||||
</project>
|
8
.idea/.idea.sanAntonioSeniorGolf/.idea/sshConfigs.xml
generated
Normal file
8
.idea/.idea.sanAntonioSeniorGolf/.idea/sshConfigs.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SshConfigs">
|
||||
<configs>
|
||||
<sshConfig host="192.168.1.52" id="e58264ea-75c0-4f9e-aa5c-b6ece113fffb" keyPath="$USER_HOME$/.ssh/dotnet" port="22" nameFormat="DESCRIPTIVE" username="dotnet" />
|
||||
</configs>
|
||||
</component>
|
||||
</project>
|
6
.idea/.idea.sanAntonioSeniorGolf/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.sanAntonioSeniorGolf/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
22
sanAntonioSeniorGolf.sln
Normal file
22
sanAntonioSeniorGolf.sln
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "website", "website\website.csproj", "{C7F3B4B2-2224-40CA-B12F-E56905F7A59A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "unitTests", "unitTests\unitTests.csproj", "{089ACCAD-8117-4C24-9429-56A394AC4734}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C7F3B4B2-2224-40CA-B12F-E56905F7A59A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C7F3B4B2-2224-40CA-B12F-E56905F7A59A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C7F3B4B2-2224-40CA-B12F-E56905F7A59A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C7F3B4B2-2224-40CA-B12F-E56905F7A59A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{089ACCAD-8117-4C24-9429-56A394AC4734}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{089ACCAD-8117-4C24-9429-56A394AC4734}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{089ACCAD-8117-4C24-9429-56A394AC4734}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{089ACCAD-8117-4C24-9429-56A394AC4734}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
6
sanAntonioSeniorGolf.sln.DotSettings.user
Normal file
6
sanAntonioSeniorGolf.sln.DotSettings.user
Normal file
@ -0,0 +1,6 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=d51071ba_002D6946_002D464f_002Db1ff_002D8183035b48e5/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Test1" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||
<TestAncestor>
|
||||
<TestId>NUnit3x::089ACCAD-8117-4C24-9429-56A394AC4734::net5.0::unitTests.Tests.Test1</TestId>
|
||||
</TestAncestor>
|
||||
</SessionState></s:String></wpf:ResourceDictionary>
|
14
unitTests/EventTests.cs
Normal file
14
unitTests/EventTests.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using NUnit.Framework;
|
||||
using website.Controllers;
|
||||
|
||||
namespace unitTests
|
||||
{
|
||||
public class Tests
|
||||
{
|
||||
[Test]
|
||||
public void getAll() {
|
||||
EventController eventController = new();
|
||||
eventController.get();
|
||||
}
|
||||
}
|
||||
}
|
19
unitTests/unitTests.csproj
Normal file
19
unitTests/unitTests.csproj
Normal file
@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NUnit" Version="3.12.0"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0-release-20210429-01"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\website\website.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
682
website/Controllers/EventController.cs
Normal file
682
website/Controllers/EventController.cs
Normal file
@ -0,0 +1,682 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
313
website/Controllers/SignupController.cs
Normal file
313
website/Controllers/SignupController.cs
Normal file
@ -0,0 +1,313 @@
|
||||
#region
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MySql.Data.MySqlClient;
|
||||
using website.Models.signups;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace website.Controllers {
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class SignupController : ControllerBase {
|
||||
[HttpGet("~/admin/signup/get")]
|
||||
public ActionResult<Signup> get(int signupId) {
|
||||
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 san_antonio_senior_golf.signups WHERE signupId=@signupId", cnn);
|
||||
cmd.Parameters.AddWithValue("@signupId", signupId);
|
||||
MySqlDataReader rdr = cmd.ExecuteReader();
|
||||
|
||||
Signup signup = null;
|
||||
while (rdr.Read())
|
||||
signup = new Signup {
|
||||
signupId = rdr.GetInt32("signupId"),
|
||||
eventId = rdr.GetInt32("eventId"),
|
||||
firstName = rdr.GetString("firstName"),
|
||||
lastName = rdr.GetString("lastName")
|
||||
};
|
||||
|
||||
cnn.Close();
|
||||
return signup == null ? StatusCode(204, null) : StatusCode(200, signup);
|
||||
}
|
||||
|
||||
[HttpGet("~/admin/signup/getAll")]
|
||||
public ActionResult<List<Signup>> getAll() {
|
||||
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 san_antonio_senior_golf.signups", cnn);
|
||||
MySqlDataReader rdr = cmd.ExecuteReader();
|
||||
|
||||
List<Signup> signups = new();
|
||||
while (rdr.Read())
|
||||
signups.Add(new Signup {
|
||||
signupId = rdr.GetInt32("signupId"),
|
||||
eventId = rdr.GetInt32("eventId"),
|
||||
firstName = rdr.GetString("firstName"),
|
||||
lastName = rdr.GetString("lastName")
|
||||
});
|
||||
|
||||
cnn.Close();
|
||||
return signups.Count == 0 ? StatusCode(204, null) : StatusCode(200, signups);
|
||||
}
|
||||
|
||||
[HttpGet("~/admin/signup/getAllCsv.csv")]
|
||||
public string getAllCsv() {
|
||||
MySqlConnection cnn;
|
||||
try {
|
||||
cnn = Utilities.getConnection();
|
||||
}
|
||||
catch (MySqlException e) {
|
||||
Console.WriteLine(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
cnn.Open();
|
||||
}
|
||||
catch (MySqlException e) {
|
||||
Console.WriteLine(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
MySqlCommand cmd =
|
||||
new(
|
||||
"select signupId, e.eventId, date, time, location, firstName, lastName from signups join events e on e.eventId = signups.eventId ",
|
||||
cnn);
|
||||
MySqlDataReader rdr = cmd.ExecuteReader();
|
||||
|
||||
List<SignupCsv> signups = new();
|
||||
while (rdr.Read())
|
||||
signups.Add(new SignupCsv {
|
||||
signupId = rdr.GetInt32("signupId"),
|
||||
eventId = rdr.GetInt32("eventId"),
|
||||
date = rdr.GetDateTime("date"),
|
||||
time = rdr.IsDBNull(3) ? null : rdr.GetTimeSpan("time"),
|
||||
location = rdr.GetString("location"),
|
||||
firstName = rdr.GetString("firstName"),
|
||||
lastName = rdr.GetString("lastName")
|
||||
});
|
||||
|
||||
cnn.Close();
|
||||
string result = "signupId,eventId,date,time,location,firstName,lastName\n" +
|
||||
string.Join("\n", signups.Select(x => x.ToString()).ToArray()) + "\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet("~/admin/signup/getForEvent")]
|
||||
public ActionResult<List<Signup>> getForEvent(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 san_antonio_senior_golf.signups WHERE eventId=@eventId", cnn);
|
||||
cmd.Parameters.AddWithValue("@eventId", eventId);
|
||||
MySqlDataReader rdr = cmd.ExecuteReader();
|
||||
|
||||
List<Signup> signups = new();
|
||||
while (rdr.Read())
|
||||
signups.Add(new Signup {
|
||||
signupId = rdr.GetInt32("signupId"),
|
||||
eventId = rdr.GetInt32("eventId"),
|
||||
firstName = rdr.GetString("firstName"),
|
||||
lastName = rdr.GetString("lastName")
|
||||
});
|
||||
|
||||
cnn.Close();
|
||||
return signups.Count == 0 ? StatusCode(204, null) : StatusCode(200, signups);
|
||||
}
|
||||
|
||||
[HttpGet("~/admin/signup/getForPeople")]
|
||||
public ActionResult<List<Signup>> getForPeople(string firstName, string lastName) {
|
||||
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 san_antonio_senior_golf.signups WHERE firstName=@firstName AND lastName=@lastName",
|
||||
cnn);
|
||||
cmd.Parameters.AddWithValue("@firstName", firstName);
|
||||
cmd.Parameters.AddWithValue("@lastName", lastName);
|
||||
MySqlDataReader rdr = cmd.ExecuteReader();
|
||||
|
||||
List<Signup> signups = new();
|
||||
while (rdr.Read())
|
||||
signups.Add(new Signup {
|
||||
signupId = rdr.GetInt32("signupId"),
|
||||
eventId = rdr.GetInt32("eventId"),
|
||||
firstName = rdr.GetString("firstName"),
|
||||
lastName = rdr.GetString("lastName")
|
||||
});
|
||||
|
||||
cnn.Close();
|
||||
return signups.Count == 0 ? StatusCode(204, null) : StatusCode(200, signups);
|
||||
}
|
||||
|
||||
[HttpPost("~/signup/create")]
|
||||
public ActionResult create([FromBody] Signup signup) {
|
||||
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.signups (eventId, firstName, lastName)VALUES (@eventId, @firstName, @lastName);"
|
||||
, cnn);
|
||||
cmd.Parameters.AddWithValue("@eventId", signup.eventId);
|
||||
cmd.Parameters.AddWithValue("@firstName", signup.firstName);
|
||||
cmd.Parameters.AddWithValue("@lastName", signup.lastName);
|
||||
try {
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (MySqlException) {
|
||||
return StatusCode(434);
|
||||
}
|
||||
|
||||
cnn.Close();
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("~/signup/delete")]
|
||||
public ActionResult delete([FromBody] Signup signup) {
|
||||
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.signups WHERE eventId=@eventId AND firstName=@firstName AND lastName=@lastName;"
|
||||
, cnn);
|
||||
cmd.Parameters.AddWithValue("@eventId", signup.eventId);
|
||||
cmd.Parameters.AddWithValue("@firstName", signup.firstName);
|
||||
cmd.Parameters.AddWithValue("@lastName", signup.lastName);
|
||||
try {
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (MySqlException) {
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
cnn.Close();
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("~/admin/signup/delete")]
|
||||
public IActionResult delete(int signupId) {
|
||||
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.signups WHERE signupId=@signupId;", cnn);
|
||||
cmd.Parameters.AddWithValue("@signupId", signupId);
|
||||
try {
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (MySqlException) {
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
cnn.Close();
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
13
website/Folder.DotSettings.user
Normal file
13
website/Folder.DotSettings.user
Normal file
@ -0,0 +1,13 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">INFO</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/Storage/@EntryValue">ThisComputer</s:String>
|
||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=2bf25faa_002Da027_002D4b81_002D8fda_002D5c8a3658623a/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="test" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||
<TestAncestor>
|
||||
<TestId>NUnit2x::FB4DF0DF-57BA-9BB7-32BA-1A5AB9438AF7::net5.0::tests.Tests.test</TestId>
|
||||
</TestAncestor>
|
||||
</SessionState></s:String>
|
||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=fc180f59_002D3e72_002D4134_002Db831_002Debf5ae243bd9/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="passingTest" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||
<TestAncestor>
|
||||
<TestId>NUnit2x::FB4DF0DF-57BA-9BB7-32BA-1A5AB9438AF7::net5.0::sanAntonioSeniorGolf.Tests.Tests.passingTest</TestId>
|
||||
</TestAncestor>
|
||||
</SessionState></s:String></wpf:ResourceDictionary>
|
6
website/Models/events/EditEventColor.cs
Normal file
6
website/Models/events/EditEventColor.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace website.Models.events {
|
||||
public class EditEventColor {
|
||||
public int? eventId { get; set; }
|
||||
public string? color { get; set; }
|
||||
}
|
||||
}
|
21
website/Models/events/EditEventDate.cs
Normal file
21
website/Models/events/EditEventDate.cs
Normal file
@ -0,0 +1,21 @@
|
||||
#region
|
||||
|
||||
using System;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace website.Models.events {
|
||||
public class EditEventDate {
|
||||
private string _date;
|
||||
public int eventId { get; set; }
|
||||
|
||||
public string date {
|
||||
get => _date;
|
||||
set {
|
||||
if (!Utilities.verifyDate(value))
|
||||
throw new ArgumentException("Date in incorrect format or null");
|
||||
_date = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
6
website/Models/events/EditEventDescription.cs
Normal file
6
website/Models/events/EditEventDescription.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace website.Models.events {
|
||||
public class EditEventDescription {
|
||||
public int? eventId { get; set; }
|
||||
public string? description { get; set; }
|
||||
}
|
||||
}
|
6
website/Models/events/EditEventImageUri.cs
Normal file
6
website/Models/events/EditEventImageUri.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace website.Models.events {
|
||||
public class EditEventImageUri {
|
||||
public int? eventId { get; set; }
|
||||
public string? imageUri { get; set; }
|
||||
}
|
||||
}
|
6
website/Models/events/EditEventLocation.cs
Normal file
6
website/Models/events/EditEventLocation.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace website.Models.events {
|
||||
public class EditEventLocation {
|
||||
public int? eventId { get; set; }
|
||||
public string? location { get; set; }
|
||||
}
|
||||
}
|
6
website/Models/events/EditEventTextColor.cs
Normal file
6
website/Models/events/EditEventTextColor.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace website.Models.events {
|
||||
public class EditEventTextColor {
|
||||
public int? eventId { get; set; }
|
||||
public string? textColor { get; set; }
|
||||
}
|
||||
}
|
20
website/Models/events/EditEventTime.cs
Normal file
20
website/Models/events/EditEventTime.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MySql.Data.Types;
|
||||
|
||||
namespace website.Models.events {
|
||||
|
||||
public class EditEventTime {
|
||||
private string _time;
|
||||
public int eventId { get; set; }
|
||||
public string? time {
|
||||
get => _time;
|
||||
set {
|
||||
if (!Utilities.verifyTime(value))
|
||||
throw new ArgumentException("Time is malformed or is null");
|
||||
_time = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
website/Models/events/Event.cs
Normal file
17
website/Models/events/Event.cs
Normal file
@ -0,0 +1,17 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using MySql.Data.Types;
|
||||
|
||||
namespace website.Models.events {
|
||||
public class Event {
|
||||
public int? eventId { get; set; }
|
||||
public string? location { get; set; }
|
||||
public DateTime date { get; set; }
|
||||
public TimeSpan? time { get; set; }
|
||||
public string? color { get; set; }
|
||||
public string? textColor { get; set; }
|
||||
public string? imageUri { get; set; }
|
||||
public string? description { get; set; }
|
||||
}
|
||||
}
|
84
website/Models/events/PostEvent.cs
Normal file
84
website/Models/events/PostEvent.cs
Normal file
@ -0,0 +1,84 @@
|
||||
#nullable enable
|
||||
|
||||
#region
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.RegularExpressions;
|
||||
using website.Models.events;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace website.Models {
|
||||
/// <summary>
|
||||
/// This method is used due to DateTime and TimeSpan
|
||||
/// being difficult to send in a post request.
|
||||
/// </summary>
|
||||
public class PostEvent {
|
||||
private string _date;
|
||||
private string? _time;
|
||||
public int? eventId { get; set; }
|
||||
[NotNull] public string? location { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// YYYY/MM/DD
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[Required]
|
||||
public string date {
|
||||
get => _date;
|
||||
set {
|
||||
if (Utilities.verifyDate(value)) {
|
||||
_date = value;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new ArgumentException("Date in incorrect format or null");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HH:MM:SS
|
||||
/// </summary>
|
||||
public string? time {
|
||||
get => _time;
|
||||
set {
|
||||
if (value == null) {
|
||||
_time = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Utilities.verifyTime(value)) ;
|
||||
_time = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string? color { get; set; }
|
||||
public string? textColor { get; set; }
|
||||
public string? imageUri { get; set; }
|
||||
public string? description { get; set; }
|
||||
|
||||
public static Event postEventToEvent(PostEvent postEvent) {
|
||||
if (postEvent.time == null)
|
||||
return new Event {
|
||||
eventId = postEvent.eventId,
|
||||
location = postEvent.location,
|
||||
date = Utilities.stringDateToDateTime(postEvent.date),
|
||||
time = null
|
||||
};
|
||||
|
||||
Match match = new Regex("^[0-9]{2}$").Match(postEvent.time);
|
||||
int hours = int.Parse(match.Value);
|
||||
int minutes = int.Parse(match.NextMatch().Value);
|
||||
int seconds = int.Parse(match.NextMatch().Value);
|
||||
|
||||
return new Event {
|
||||
eventId = postEvent.eventId,
|
||||
location = postEvent.location,
|
||||
date = Utilities.stringDateToDateTime(postEvent.date),
|
||||
time = Utilities.stringTimeToTimeSpan(postEvent.time)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
18
website/Models/signups/Signup.cs
Normal file
18
website/Models/signups/Signup.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace website.Models.signups {
|
||||
public class Signup {
|
||||
private string _firstName;
|
||||
private string _lastName;
|
||||
public int? signupId { get; set; }
|
||||
public int? eventId { get; init; }
|
||||
|
||||
public string firstName {
|
||||
get => _firstName;
|
||||
set => _firstName = value.ToUpper().Trim();
|
||||
}
|
||||
|
||||
public string lastName {
|
||||
get => _lastName;
|
||||
set => _lastName = value.ToUpper().Trim();
|
||||
}
|
||||
}
|
||||
}
|
33
website/Models/signups/SignupCsv.cs
Normal file
33
website/Models/signups/SignupCsv.cs
Normal file
@ -0,0 +1,33 @@
|
||||
#region
|
||||
|
||||
using System;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace website.Models.signups {
|
||||
public class SignupCsv {
|
||||
private string _firstName;
|
||||
private string _lastName;
|
||||
public int? signupId { get; set; }
|
||||
public int? eventId { get; init; }
|
||||
public DateTime date { get; set; }
|
||||
public TimeSpan? time { get; set; }
|
||||
public string? location { get; set; }
|
||||
|
||||
|
||||
public string firstName {
|
||||
get => _firstName;
|
||||
set => _firstName = value.ToUpper().Trim();
|
||||
}
|
||||
|
||||
public string lastName {
|
||||
get => _lastName;
|
||||
set => _lastName = value.ToUpper().Trim();
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return signupId + "," + eventId + "," + date.ToString("yyyy-MM-dd") + "," + time + "," + location + "," +
|
||||
_firstName + "," + _lastName;
|
||||
}
|
||||
}
|
||||
}
|
19
website/Program.cs
Normal file
19
website/Program.cs
Normal file
@ -0,0 +1,19 @@
|
||||
#region
|
||||
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace website {
|
||||
public class Program {
|
||||
public static void Main(string[] args) {
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) {
|
||||
return Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
|
||||
}
|
||||
}
|
||||
}
|
31
website/Properties/launchSettings.json
Normal file
31
website/Properties/launchSettings.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:18853",
|
||||
"sslPort": 44359
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"sanAntonioSeniorGolf": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": "true",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/website/index.html",
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
53
website/Startup.cs
Normal file
53
website/Startup.cs
Normal file
@ -0,0 +1,53 @@
|
||||
#region
|
||||
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace website {
|
||||
public class Startup {
|
||||
public Startup(IConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void configureServices(IServiceCollection services) {
|
||||
services.AddControllers();
|
||||
services.AddCors();
|
||||
services.AddSwaggerGen(c => {
|
||||
c.SwaggerDoc("v1", new OpenApiInfo {Title = "website", Version = "v1"});
|
||||
});
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void configure(IApplicationBuilder app, IWebHostEnvironment env) {
|
||||
if (env.IsDevelopment()) {
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseSwagger(c => c.RouteTemplate = "/api/{documentname}/swagger.json");
|
||||
app.UseSwaggerUI(c => {
|
||||
c.SwaggerEndpoint("/api/v1/swagger.json", "website v1");
|
||||
c.RoutePrefix = "api/website";
|
||||
});
|
||||
}
|
||||
|
||||
app.UseCors(builder => {
|
||||
builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
|
||||
});
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
||||
}
|
||||
}
|
||||
}
|
80
website/Utilities.cs
Normal file
80
website/Utilities.cs
Normal file
@ -0,0 +1,80 @@
|
||||
#nullable enable
|
||||
|
||||
#region
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace website {
|
||||
public static class Utilities {
|
||||
private static readonly string MySqlPass =
|
||||
File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "mysql.pass");
|
||||
|
||||
private static readonly string MySqlHost =
|
||||
File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "mysql.host");
|
||||
|
||||
private static readonly string MySqlUser =
|
||||
File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "mysql.user");
|
||||
|
||||
public static MySqlConnection getConnection() {
|
||||
return new MySqlConnection("server=" + MySqlHost + ";pwd=" + MySqlPass + ";uid=" + MySqlUser +
|
||||
";database=san_antonio_senior_golf;Port=5618;Convert Zero Datetime=True;");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify if string date can be converted to DateTime
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <returns>True if date matches "^[0-9]{4}/[0-9]{2}/[0-9]{2}$"</returns>
|
||||
public static bool verifyDate(string? date) {
|
||||
if (date == null)
|
||||
return false;
|
||||
Regex regex = new("^[0-9]{4}/[0-9]{2}/[0-9]{2}$", RegexOptions.IgnoreCase);
|
||||
return regex.IsMatch(date);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if date param is applicable with verifyDate
|
||||
/// </summary>
|
||||
/// <param name="date">Not null string</param>
|
||||
/// <returns>DateTime equivalent of date param</returns>
|
||||
// TODO Creating 3 regex's is inefficient
|
||||
public static DateTime stringDateToDateTime([NotNull] string date) {
|
||||
int year = int.Parse(new Regex("^[0-9]{4}$").Match(date).Value);
|
||||
int month = int.Parse(new Regex("/[0-9]{2}/$").Match(date).Value);
|
||||
int day = int.Parse(new Regex("/[0-9]{2}$").Match(date).NextMatch().Value);
|
||||
return new DateTime(year, month, day);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify if string time can be converted to TimeSpan using stringTimeToTimeSpan
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <returns>True if time matches "^[0-9]{2}:[0-9]{2}:[0-9]{2}$"</returns>
|
||||
public static bool verifyTime(string? time) {
|
||||
if (time == null)
|
||||
return true;
|
||||
Regex regex = new("^[0-9]{2}:[0-9]{2}:[0-9]{2}$", RegexOptions.IgnoreCase);
|
||||
return regex.IsMatch(time);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if time param is applicable with verifyTime
|
||||
/// </summary>
|
||||
/// <param name="time">Not null string</param>
|
||||
/// <returns>TimeSpan equivalent of time string</returns>
|
||||
public static TimeSpan stringTimeToTimeSpan([NotNull] string time) {
|
||||
Match match = new Regex("^[0-9]{2}$").Match(time);
|
||||
int hours = int.Parse(match.Value);
|
||||
int minutes = int.Parse(match.NextMatch().Value);
|
||||
int seconds = int.Parse(match.NextMatch().Value);
|
||||
|
||||
return new TimeSpan(hours, minutes, seconds);
|
||||
}
|
||||
}
|
||||
}
|
9
website/appsettings.Development.json
Normal file
9
website/appsettings.Development.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
10
website/appsettings.json
Normal file
10
website/appsettings.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
21
website/website.csproj
Normal file
21
website/website.csproj
Normal file
@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<GenerateProgramFile>false</GenerateProgramFile>
|
||||
<RootNamespace>sanAntonioSeniorGolf</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MySql.Data" Version="8.0.24"/>
|
||||
<PackageReference Include="Nunit.Framework.TestCaseStorage" Version="1.0.1"/>
|
||||
<PackageReference Include="Sandbox" Version="1.0.55"/>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="mysql.host"/>
|
||||
<None Remove="mysql.pass"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user