diff --git a/WebApplicationStart/Controllers/CalcController.cs b/WebApplicationStart/Controllers/CalcController.cs new file mode 100644 index 0000000..ef83209 --- /dev/null +++ b/WebApplicationStart/Controllers/CalcController.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Mvc; +using System.Diagnostics; +using WebApplicationStart.Models; + +namespace WebApplicationStart.Controllers +{ + public class CalcController : Controller + { + private readonly ILogger _logger; + + public CalcController(ILogger logger) + { + _logger = logger; + } + public string Index(double a = 0, double b = 0, string c = "+") + { + if (c == "+") + return $"{a} + {b} = {a + b}"; + else if (c == "-") + return $"{a} - {b} = {a - b}"; + else if (c == "*") + return $"{a} * {b} = {a * b}"; + else if (c == "/") + { + if (b == 0) + return "На ноль делить нельзя!"; + else + return $"{a} / {b} = {a / b}"; + } + else + return "неверный знак, попробуйте снова"; + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + } +} \ No newline at end of file diff --git a/WebApplicationStart/Controllers/CalculatorController.cs b/WebApplicationStart/Controllers/CalculatorController.cs new file mode 100644 index 0000000..3f49e2a --- /dev/null +++ b/WebApplicationStart/Controllers/CalculatorController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; +using System.Diagnostics; +using WebApplicationStart.Models; + +namespace WebApplicationStart.Controllers +{ + public class CalculatorController : Controller + { + private readonly ILogger _logger; + + public CalculatorController(ILogger logger) + { + _logger = logger; + } + public string Index(int first, int second, string sign) + { + switch (sign) + { + case "+": return $"{first} + {second} = {first + second}"; + case "-": return $"{first} - {second} = {first - second}"; + case "*": return $"{first} * {second} = {first * second}"; + default: return "неверный знак, попробуйте снова"; + } + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + } +} \ No newline at end of file diff --git a/WebApplicationStart/Controllers/StartController.cs b/WebApplicationStart/Controllers/StartController.cs new file mode 100644 index 0000000..5482aaa --- /dev/null +++ b/WebApplicationStart/Controllers/StartController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; +using System.Diagnostics; +using WebApplicationStart.Models; + +namespace WebApplicationStart.Controllers +{ + public class StartController : Controller + { + private readonly ILogger _logger; + + public StartController(ILogger logger) + { + _logger = logger; + } + public string Hello() + { + if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour < 6) + return "Доброй ночи"; + if (DateTime.Now.Hour >= 6 && DateTime.Now.Hour < 12) + return "Доброе утро"; + if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 18) + return "Добрый день"; + return "Добрый вечер"; + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + } +} \ No newline at end of file diff --git a/WebApplicationStart/Program.cs b/WebApplicationStart/Program.cs index 3155fc3..782ee59 100644 --- a/WebApplicationStart/Program.cs +++ b/WebApplicationStart/Program.cs @@ -18,6 +18,6 @@ app.MapControllerRoute( name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); + pattern: "{controller=Home}/{action=Index}"); app.Run(); diff --git a/WebApplicationStart/Views/Home/Index.cshtml b/WebApplicationStart/Views/Home/Index.cshtml index 28d6e5f..cef89d4 100644 --- a/WebApplicationStart/Views/Home/Index.cshtml +++ b/WebApplicationStart/Views/Home/Index.cshtml @@ -3,7 +3,7 @@ }
-

Тут надо написать свою Фамилию и Имя

+

Иванов Станислав

Я учу ASP и это мой первый крутой проект.