diff --git a/WebApplicationLesson1/Controllers/CalculatorController.cs b/WebApplicationLesson1/Controllers/CalculatorController.cs new file mode 100644 index 0000000..5bed7aa --- /dev/null +++ b/WebApplicationLesson1/Controllers/CalculatorController.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WebApplicationLesson1.Controllers +{ + public class CalculatorController : Controller + { + public string Index(double a, double b, char operation) + { + switch (operation) + { + case '-': + return $"{a} {operation} {b} = {a - b}"; + case '*': + return $"{a} {operation} {b} = {a * b}"; + case '/': + return $"{a} {operation} {b} = {a / b}"; + default: + if (operation != '+' && operation != 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}"); }); } }