diff --git a/SimpleNetCoreApp/.gitignore b/SimpleNetCoreApp/.gitignore new file mode 100644 index 00000000..dfa40bc5 --- /dev/null +++ b/SimpleNetCoreApp/.gitignore @@ -0,0 +1,36 @@ +# Compiled binary files +bin/ +obj/ + +# User-specific files +*.user +*.suo +*.userosscache +*.sln.docstates + +# Logs +*.log + +# Visual Studio Code +.vscode/ +/SimpleNetCoreApp/bin +# Build results +*.dll +*.exe +*.app +*.so +*.dylib +*.pdb + +# Temporary files +*.tmp +*.temp +*.cache +*.csproj.user + +# Dependency directories +packages/ +node_modules/ + +# Publish output +publish/ \ No newline at end of file diff --git a/SimpleNetCoreApp/Controllers/AddController.cs b/SimpleNetCoreApp/Controllers/AddController.cs new file mode 100644 index 00000000..d160cd16 --- /dev/null +++ b/SimpleNetCoreApp/Controllers/AddController.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Mvc; +using SimpleNetCoreApp.Models; + +namespace SimpleNetCoreApp.Controllers +{ + public class AddController : Controller + { + // GET: Add + public IActionResult Index() + { + return View(); + } + + // POST: Add + [HttpPost] + public IActionResult Index(ItemModel item) + { + if (ModelState.IsValid) + { + // Logic to add the item (e.g., save to a list or in-memory storage) + // Redirect to the list view or another appropriate action + return RedirectToAction("Index", "List"); + } + return View(item); + } + } +} \ No newline at end of file diff --git a/SimpleNetCoreApp/Controllers/EditController.cs b/SimpleNetCoreApp/Controllers/EditController.cs new file mode 100644 index 00000000..d1488b37 --- /dev/null +++ b/SimpleNetCoreApp/Controllers/EditController.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Mvc; +using SimpleNetCoreApp.Models; + +namespace SimpleNetCoreApp.Controllers +{ + public class EditController : Controller + { + // GET: Edit/5 + public IActionResult Index(int id) + { + // Here you would typically retrieve the item from a data source using the id + // For this example, we'll just create a dummy item + var item = new ItemModel + { + Id = id, + Name = "Sample Item", + Description = "This is a sample item description." + }; + + return View(item); + } + + // POST: Edit/5 + [HttpPost] + public IActionResult Index(ItemModel item) + { + if (ModelState.IsValid) + { + // Here you would typically update the item in a data source + // Redirect to the list or another appropriate action + return RedirectToAction("Index", "List"); + } + + return View(item); + } + } +} \ No newline at end of file diff --git a/SimpleNetCoreApp/Controllers/HomeController.cs b/SimpleNetCoreApp/Controllers/HomeController.cs new file mode 100644 index 00000000..24fb5656 --- /dev/null +++ b/SimpleNetCoreApp/Controllers/HomeController.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; + +namespace SimpleNetCoreApp.Controllers +{ + public class HomeController : Controller + { + public IActionResult Index() + { + return View(); + } + } +} \ No newline at end of file diff --git a/SimpleNetCoreApp/Controllers/ListController.cs b/SimpleNetCoreApp/Controllers/ListController.cs new file mode 100644 index 00000000..8498d748 --- /dev/null +++ b/SimpleNetCoreApp/Controllers/ListController.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using SimpleNetCoreApp.Models; +using System.Collections.Generic; + +namespace SimpleNetCoreApp.Controllers +{ + public class ListController : Controller + { + private static List items = new List + { + new ItemModel { Id = 1, Name = "Item 1", Description = "Description for Item 1" }, + new ItemModel { Id = 2, Name = "Item 2", Description = "Description for Item 2" } + }; + + public IActionResult Index() + { + return View(items); + } + } +} \ No newline at end of file diff --git a/SimpleNetCoreApp/Models/ItemModel.cs b/SimpleNetCoreApp/Models/ItemModel.cs new file mode 100644 index 00000000..553d0dd4 --- /dev/null +++ b/SimpleNetCoreApp/Models/ItemModel.cs @@ -0,0 +1,9 @@ +namespace SimpleNetCoreApp.Models +{ + public class ItemModel + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/SimpleNetCoreApp/Program.cs b/SimpleNetCoreApp/Program.cs new file mode 100644 index 00000000..897d9f95 --- /dev/null +++ b/SimpleNetCoreApp/Program.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +public class Program +{ + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + + +} diff --git a/SimpleNetCoreApp/README.md b/SimpleNetCoreApp/README.md new file mode 100644 index 00000000..729ffea4 --- /dev/null +++ b/SimpleNetCoreApp/README.md @@ -0,0 +1,55 @@ +# Simple .NET Core Application + +This is a simple .NET Core application that demonstrates basic CRUD operations without a database. The application includes functionality for listing, adding, and editing items through a web interface. + +## Project Structure + +- **Controllers**: Contains the logic for handling requests. + - `HomeController.cs`: Manages the home page. + - `ListController.cs`: Handles the display of the item list. + - `AddController.cs`: Manages the addition of new items. + - `EditController.cs`: Handles the editing of existing items. + +- **Models**: Contains the data structures used in the application. + - `ItemModel.cs`: Represents an item with properties such as Id, Name, and Description. + +- **Views**: Contains the Razor views for rendering the UI. + - `Home/Index.cshtml`: The home page view. + - `List/Index.cshtml`: The view for displaying the list of items. + - `Add/Index.cshtml`: The view for the add item form. + - `Edit/Index.cshtml`: The view for the edit item form. + +- **wwwroot**: Contains static files such as CSS, JavaScript, and third-party libraries. + - `css`: Stylesheets for the application. + - `js`: JavaScript files for client-side functionality. + - `lib`: Third-party libraries (e.g., jQuery, Bootstrap). + +- **Configuration Files**: + - `appsettings.json`: Configuration settings for the application. + - `Program.cs`: The entry point of the application. + - `Startup.cs`: Configures services and the request pipeline. + +## Setup Instructions + +1. Clone the repository to your local machine. +2. Open the project in your preferred IDE. +3. Restore the dependencies using the command: + ``` + dotnet restore + ``` +4. Run the application using the command: + ``` + dotnet run + ``` +5. Open your web browser and navigate to `http://localhost:5000` to access the application. + +## Usage + +- Navigate to the home page to see an overview of the application. +- Use the "List" option to view all items. +- Use the "Add" option to create a new item. +- Use the "Edit" option to modify an existing item. + +## Troubleshooting + +If you encounter issues with certificates, try closing and reopening your IDE. \ No newline at end of file diff --git a/SimpleNetCoreApp/SimpleNetCoreApp.csproj b/SimpleNetCoreApp/SimpleNetCoreApp.csproj new file mode 100644 index 00000000..9d334dfd --- /dev/null +++ b/SimpleNetCoreApp/SimpleNetCoreApp.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + enable + enable + + + + + + + + + diff --git a/SimpleNetCoreApp/SimpleNetCoreApp.sln b/SimpleNetCoreApp/SimpleNetCoreApp.sln new file mode 100644 index 00000000..8d1ca1ad --- /dev/null +++ b/SimpleNetCoreApp/SimpleNetCoreApp.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleNetCoreApp", "SimpleNetCoreApp.csproj", "{7FD36F7C-CCEA-471A-817C-C63AEF0D40CF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7FD36F7C-CCEA-471A-817C-C63AEF0D40CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FD36F7C-CCEA-471A-817C-C63AEF0D40CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FD36F7C-CCEA-471A-817C-C63AEF0D40CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FD36F7C-CCEA-471A-817C-C63AEF0D40CF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/SimpleNetCoreApp/Startup.cs b/SimpleNetCoreApp/Startup.cs new file mode 100644 index 00000000..229aafaa --- /dev/null +++ b/SimpleNetCoreApp/Startup.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +public class Startup +{ + public void ConfigureServices(IServiceCollection services) + { + services.AddControllersWithViews(); + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseExceptionHandler("/Home/Error"); + app.UseHsts(); + } + + app.UseHttpsRedirection(); + app.UseStaticFiles(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllerRoute( + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); + }); + } +} \ No newline at end of file diff --git a/SimpleNetCoreApp/Views/Add/Index.cshtml b/SimpleNetCoreApp/Views/Add/Index.cshtml new file mode 100644 index 00000000..d8162c79 --- /dev/null +++ b/SimpleNetCoreApp/Views/Add/Index.cshtml @@ -0,0 +1,20 @@ +@model SimpleNetCoreApp.Models.ItemModel + + +

Add New Item

+ +
+
+ + + +
+
+ + +
+ +
+ +Back to List \ No newline at end of file diff --git a/SimpleNetCoreApp/Views/Edit/Index.cshtml b/SimpleNetCoreApp/Views/Edit/Index.cshtml new file mode 100644 index 00000000..53e32bf5 --- /dev/null +++ b/SimpleNetCoreApp/Views/Edit/Index.cshtml @@ -0,0 +1,27 @@ +@model SimpleNetCoreApp.Models.ItemModel + + +

Edit Item

+ +
+ + +
+ + + +
+ +
+ + + +
+ + + Cancel +
+ +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} \ No newline at end of file diff --git a/SimpleNetCoreApp/Views/Home/Index.cshtml b/SimpleNetCoreApp/Views/Home/Index.cshtml new file mode 100644 index 00000000..3cf654d9 --- /dev/null +++ b/SimpleNetCoreApp/Views/Home/Index.cshtml @@ -0,0 +1,17 @@ + + + + + + Home + + + +
+

Welcome to the Simple .NET Core App

+

This is the home page of your application.

+ View Items + Add New Item +
+ + \ No newline at end of file diff --git a/SimpleNetCoreApp/Views/List/Index.cshtml b/SimpleNetCoreApp/Views/List/Index.cshtml new file mode 100644 index 00000000..25e9eab0 --- /dev/null +++ b/SimpleNetCoreApp/Views/List/Index.cshtml @@ -0,0 +1,41 @@ + + + + + + Item List + + + +
+

Item List

+ Add New Item + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
IDNameDescriptionActions
@item.Id@item.Name@item.Description + Edit +
+ +
+
+
+ + \ No newline at end of file diff --git a/SimpleNetCoreApp/appsettings.json b/SimpleNetCoreApp/appsettings.json new file mode 100644 index 00000000..222224e3 --- /dev/null +++ b/SimpleNetCoreApp/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} \ No newline at end of file diff --git a/SimpleNetCoreApp/deploy.json b/SimpleNetCoreApp/deploy.json new file mode 100644 index 00000000..b54928a9 --- /dev/null +++ b/SimpleNetCoreApp/deploy.json @@ -0,0 +1,38 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + { + "type": "Microsoft.Web/sites", + "apiVersion": "2021-02-01", + "name": "[parameters('webAppName')]", + "location": "[resourceGroup().location]", + "properties": { + "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]" + } + }, + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2021-02-01", + "name": "[parameters('appServicePlanName')]", + "location": "[resourceGroup().location]", + "sku": { + "name": "F1", + "tier": "Free" + }, + "properties": { + "reserved": false + } + } + ], + "parameters": { + "webAppName": { + "type": "string", + "defaultValue": "MyMvcApp" + }, + "appServicePlanName": { + "type": "string", + "defaultValue": "MyMvcAppServicePlan" + } + } + } \ No newline at end of file diff --git a/SimpleNetCoreApp/deploy.parameters.json b/SimpleNetCoreApp/deploy.parameters.json new file mode 100644 index 00000000..ec2987bf --- /dev/null +++ b/SimpleNetCoreApp/deploy.parameters.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "webAppName": { + "value": "MyMvcApp" + }, + "appServicePlanName": { + "value": "MyMvcAppServicePlan" + } + } + } \ No newline at end of file diff --git a/SimpleNetCoreApp/wwwroot/css b/SimpleNetCoreApp/wwwroot/css new file mode 100644 index 00000000..ff6c7875 --- /dev/null +++ b/SimpleNetCoreApp/wwwroot/css @@ -0,0 +1 @@ +/* This file is intentionally left blank. */ \ No newline at end of file diff --git a/SimpleNetCoreApp/wwwroot/js b/SimpleNetCoreApp/wwwroot/js new file mode 100644 index 00000000..559825ed --- /dev/null +++ b/SimpleNetCoreApp/wwwroot/js @@ -0,0 +1 @@ +// This file is intentionally left blank. \ No newline at end of file diff --git a/calculator.py b/calculator.py new file mode 100644 index 00000000..c37244d8 --- /dev/null +++ b/calculator.py @@ -0,0 +1,51 @@ +#create a basic calculator that can add, subtract, multiply and divide two numbers +def add(x, y): + """Add two numbers.""" + return x + y +def subtract(x, y): + """Subtract two numbers.""" + return x - y +def multiply(x, y): + """Multiply two numbers.""" + return x * y +def divide(x, y): + """Divide two numbers.""" + if y == 0: + raise ValueError("Cannot divide by zero.") + return x / y +def calculator(): + """A simple calculator that performs basic arithmetic operations.""" + print("Select operation:") + print("1. Add") + print("2. Subtract") + print("3. Multiply") + print("4. Divide") + + while True: + choice = input("Enter choice (1/2/3/4): ") + + if choice in ['1', '2', '3', '4']: + try: + num1 = float(input("Enter first number: ")) + num2 = float(input("Enter second number: ")) + except ValueError: + print("Invalid input. Please enter a number.") + continue + + if choice == '1': + print(f"{num1} + {num2} = {add(num1, num2)}") + elif choice == '2': + print(f"{num1} - {num2} = {subtract(num1, num2)}") + elif choice == '3': + print(f"{num1} * {num2} = {multiply(num1, num2)}") + elif choice == '4': + try: + print(f"{num1} / {num2} = {divide(num1, num2)}") + except ValueError as e: + print(e) + else: + print("Invalid choice. Please select a valid operation.") + + next_calculation = input("Do you want to perform another calculation? (yes/no): ") + if next_calculation.lower() != 'yes': + break \ No newline at end of file diff --git a/card_draw.py b/card_draw.py index 4f4bf631..700876e3 100644 --- a/card_draw.py +++ b/card_draw.py @@ -13,3 +13,5 @@ print("You got:") for i in range(5) print(deck[i][0], "of", deck[i][1] + + diff --git a/hello.py b/hello.py new file mode 100644 index 00000000..cae95c45 --- /dev/null +++ b/hello.py @@ -0,0 +1,2 @@ +print("Hello, World!") + diff --git a/sum_elements.py b/sum_elements.py index 2731a254..5b0b49cc 100644 --- a/sum_elements.py +++ b/sum_elements.py @@ -35,3 +35,5 @@ def main(): if __name__ == "__main__": main() + + diff --git a/weather_script.py b/weather_script.py new file mode 100644 index 00000000..a3c79636 --- /dev/null +++ b/weather_script.py @@ -0,0 +1,37 @@ +import requests + +def fetch_weather(api_key, city): + base_url = "http://api.openweathermap.org/data/2.5/weather" + params = { + "q": city, + "appid": api_key, + "units": "metric" # Use metric units for temperature in Celsius + } + response = requests.get(base_url, params=params) + if response.status_code == 200: + return response.json() + else: + print(f"Error: Unable to fetch weather data (status code: {response.status_code})") + return None + +def display_weather(data): + if data: + city = data.get("name") + temp = data["main"].get("temp") + humidity = data["main"].get("humidity") + weather_condition = data["weather"][0].get("description") + print(f"Weather in {city}:") + print(f"Temperature: {temp}°C") + print(f"Humidity: {humidity}%") + print(f"Condition: {weather_condition.capitalize()}") + else: + print("No data to display.") + +if __name__ == "__main__": + # Replace 'your_api_key_here' with your actual OpenWeatherMap API key + api_key = "your_api_key_here" + city = input("Enter the city name: ") + weather_data = fetch_weather(api_key, city) + display_weather(weather_data) + +