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
55 changes: 54 additions & 1 deletion WebApplicationStart/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Diagnostics;
using WebApplicationStart.Models;

Expand Down Expand Up @@ -26,9 +27,61 @@ public IActionResult Tasks()

public string Task1()
Copy link
Contributor

Choose a reason for hiding this comment

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

https://localhost:5001/start/hello
знаю, что своим шаблоном сбила с толку, но нужно переделать

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

[Route("calculator/index/{n1?}/{n2?}")]
public string Task2(int n1 = 0, int n2 = 0)
{
return $"{n1} + {n2} = {n1 + n2}";
}

[Route("calculator/index/{n1?}/{n2?}/{oper?}")]
public string Task3(double n1 = 0, double n2 = 0, string oper = "+")
{
double res = 0;
switch (oper)
{
case "+": res = n1 + n2; break;
case "-": res = n1 - n2; break;
case "*": res = n1 * n2; break;
case "/": res = n1 / n2; break;
default: return "Ошибка: Некорректная операция. Допустимые операции: +, -, *\rПример корректного запроса: https://localhost:7299/calculator/index/1/3/+";
}
return $"{n1} {oper} {n2} = {res}";
}

[Route("calc/index")]
public string Task4(double a = 0, double b = 0, string c = "+")
{
c = System.Net.WebUtility.UrlDecode(c);
double res = 0;
switch (c)
{
case "+": res = a + b; break;
case "-": res = a - b; break;
case "*": res = a * b; break;
case "/": if (b == 0) return "Ошибка: Деление на ноль невозможно"; res = a / b; break;
default: return "Ошибка: Некорректная операция. Допустимые операции: +, -, *, /\rПример: https://localhost:5001/calc/index?a=1&b=3&c=+";
}
return $"{a} {c} {b} = {res}";
}



[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
Expand Down
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