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}/"); }); } }