From 3e00b667f1c5c3a5428216751cedc06248a5fded Mon Sep 17 00:00:00 2001 From: Tamikon Date: Wed, 3 Apr 2024 01:10:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CalcController.cs | 17 +++++++++++++++++ WebApplicationLesson1/Startup.cs | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 WebApplicationLesson1/Controllers/CalcController.cs diff --git a/WebApplicationLesson1/Controllers/CalcController.cs b/WebApplicationLesson1/Controllers/CalcController.cs new file mode 100644 index 0000000..82e6e78 --- /dev/null +++ b/WebApplicationLesson1/Controllers/CalcController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WebApplicationLesson1.Controllers +{ + public class CalcController : 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}"; + } + } +} \ No newline at end of file diff --git a/WebApplicationLesson1/Startup.cs b/WebApplicationLesson1/Startup.cs index d9a1eb0..5dd4ff9 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}"); }); } }