From 5d7a27b33dc07dde3e125e698e6ad555dc7e9765 Mon Sep 17 00:00:00 2001 From: Kuznec Date: Thu, 4 Apr 2024 17:16:43 +0300 Subject: [PATCH] Kuznecov_lesson2_1_4 --- .../Controllers/CalculatorController.cs | 22 +++++++++++++++++++ WebApplicationLesson1/Startup.cs | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 WebApplicationLesson1/Controllers/CalculatorController.cs diff --git a/WebApplicationLesson1/Controllers/CalculatorController.cs b/WebApplicationLesson1/Controllers/CalculatorController.cs new file mode 100644 index 0000000..aa272c6 --- /dev/null +++ b/WebApplicationLesson1/Controllers/CalculatorController.cs @@ -0,0 +1,22 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WebApplicationLesson1.Controllers +{ + public class CalculatorController : Controller + { + public string Index(double a, double b, char c) + { + if (c == '*') + return $"{a} {c} {b} = {a * b}"; + if (c == '-') + return $"{a} {c} {b} = {a - b}"; + if (c == '/' && b != 0) + return $"{a} {c} {b} = {a / b}"; + if (c == '/' && b == 0) + return "Ошибка: деление на ноль."; + if (c != '+' && c != 0) + return "Некорректная операция."; + return $"{a} + {b} = {a + b}"; + } + } +} diff --git a/WebApplicationLesson1/Startup.cs b/WebApplicationLesson1/Startup.cs index d9a1eb0..442d7c6 100644 --- a/WebApplicationLesson1/Startup.cs +++ b/WebApplicationLesson1/Startup.cs @@ -46,7 +46,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { endpoints.MapControllerRoute( name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); + pattern: "{controller=Home}/{action=Index}/"); }); } }