Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions WebApplicationStart/Controllers/CalculatorController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;

namespace WebApplicationStart.Controllers
{
public class CalculatorController : Controller
{
public string Index(int a = 0, int b = 0, string operation = "+")
{
switch (operation)
{
case "+": return $"{a}+{b}={a + b}";
case "-": return $"{a}-{b}={a - b}";
case "*": return $"{a}*{b}={a * b}";
case "/": return $"{a}/{b}={a / b}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

деление на ноль

default: return "Ошибка: Некорректная операция. Допустимые операции: +, -, *\rПример корректного запроса: https://localhost:5090/calculator/index/1/3/+";
}
}
}

}
15 changes: 14 additions & 1 deletion WebApplicationStart/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ public IActionResult Tasks()

public string Task1()
{
return "Тут решение первой задачи";
int h = DateTime.Now.Hour;
if (h < 6)
{
return "Доброй ночи";
}
if (h < 12)
{
return "Доброе утро";
}
if (h < 18)
{
return "Добрый день";
}
return "Добрый вечер";
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
Expand Down
2 changes: 1 addition & 1 deletion WebApplicationStart/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
pattern: "{controller=Home}/{action=Index}/{a?}/{b?}/{operation?}");

app.Run();
2 changes: 1 addition & 1 deletion WebApplicationStart/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
}

<div class="text-center">
<h1 class="display-4">Тут надо написать свою Фамилию и Имя</h1>
<h1 class="display-4">Наниев Азамат</h1>
<p>Я учу ASP и это мой первый крутой проект.</p>
<div>
<img class="img-fluid" src="images/startdevelopweb.png"> </img>
Expand Down
2 changes: 1 addition & 1 deletion WebApplicationStart/Views/Home/Tasks.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<p>
<ul>
<li> Задача 1. <a href="task1">Время суток</a></li>
<li> Задача 1. <a asp-controller="Home" asp-action="Task1">Время суток</a></li>
<li>Задача 2. Калькулятор</li>
<li>Задача 3. Калькулятор с операцией</li>
<li>Задача 4. Калькулятор с операцией и query параметрами</li>
Expand Down