using System.Linq;
using HeIsBadMvc.Code;
using HeIsBadMvc.Models;
using Microsoft.AspNetCore.Mvc;
namespace HeIsBadMvc.Controllers
{
/// <summary>
/// Адресный контроллер. Занимается всеми вопросами связанными с адресами, регионами и прочим.
/// </summary>
[Route("api/address")]
[ApiController]
public class AddressController : Controller
{
private static readonly Country[] _countryes = new Country[]
{
new Country{Id = 643,
Alpha2 = "RU",
Alpha3 = "RUS",
Name = "Russia"},
};
private readonly Region[] _regions = RegionsSinglton.Instance.Items;
private readonly City[] _cityes = CityesSinglton.Instance.Items;
/// <summary>
/// Список стран в системе.
/// </summary>
/// <returns></returns>
[HttpGet]
[ResponseCache(Location = ResponseCacheLocation.Any, Duration = 86000)]
public IActionResult Get()
{
return Ok(_countryes);
}
/// <summary>
///
/// </summary>
/// <param name="country"></param>
/// <returns></returns>
[HttpGet("{country}")]
[ResponseCache(Location = ResponseCacheLocation.Any, Duration = 86000)]
public ActionResult<Country> Get(string country)
{
var res = _countryes.FirstOrDefault(x => x.Alpha2 == country.ToUpper());
if (res == null)
return NotFound(new { error = "Not found country" });
return res;
}
/// <summary>
/// Список регионов для страны.
/// </summary>
/// <param name="country"></param>
/// <returns></returns>
[HttpGet("{country}/regions")]
[ResponseCache(Location = ResponseCacheLocation.Any, Duration = 86000)]
public ActionResult GetRegions(string country)
{
var res = _countryes.FirstOrDefault(x => x.Alpha2 == country.ToUpper());
if (res == null)
return NotFound(new { error = "Not found country" });
if (res.Alpha2 == "RU")
return Ok(_regions);
return NoContent();
}
/// <summary>
/// Список городов для страны. Только Россия. Первым идет спецобьект "Вся Россия", потом Москва и Санк-Петербург, дальше сортировка по коду.
/// </summary>
/// <param name="country">Код страны, ru</param>
/// <param name="query">Поисковая фраза, по умолчанию все</param>
/// <param name="limit">Лимит для запроса</param>
/// <returns></returns>
[HttpGet("{country}/cityes")]
[ResponseCache(Location = ResponseCacheLocation.Any, Duration = 86000)]
public ActionResult GetCityes(string country, [FromQuery]string query = "", [FromQuery]int limit = 10)
{
var res = _countryes.FirstOrDefault(x => x.Alpha2 == country.ToUpper());
if (res == null)
return NotFound(new { error = "Not found country" });
if (res.Alpha2 == "RU")
{
return Ok(GetFilteredCityList(query, limit));
}
return NoContent();
}
/// <summary>
/// Отдает лимитированное количество городов.
/// </summary>
/// <param name="query">Если строка не пустая то применяется фильтр</param>
/// <param name="limit"></param>
/// <returns></returns>
private City[] GetFilteredCityList(string query, int limit)
{
if (string.IsNullOrEmpty(query))
return _cityes.Take(limit).ToArray();
query = query.ToLower();
return _cityes.Where(x => x.Name.ToLower().Contains(query) || x.Slug.ToLower().Contains(query))
.Take(limit)
.ToArray();
}
}
}
$(this).parents().find('span').text(textOption);
$(this).parent().siblings('span').text(textOption);
* {
box-sizing: border-box;
}
:focus {
outline: 0;
}
img {
max-width: 100%;
vertical-align: middle;
}
.wrapper {
margin-bottom: 50%;
}
.photo {
position: relative;
display: inline-block;
margin-bottom: 5px;
}
.photo > img{
width: 400px;
height:400px;
}
.slider {
width: 400px;
}
const items = [];
items["one"]=1;
items["two"]=1;
if(items["one"]) console.log("Есть"); else console.log("Нет");
delete items["one"];
if(items["one"]) console.log("Есть"); else console.log("Нет");
// либо
items["one"]=0;
if(items["one"]) console.log("Есть"); else console.log("Нет");
Мне нужно сделать так, что если человек постоянно кликает по кнопке, то обновлять таймер
if (index > 0) {
$(this).remove();
}
if (items[name]) return;
if (items[name]) return;
if (items[name]) {
// остановка анимации таймера и запуск заново
} else {
// код первого запуска таймера.
}
/Первая форма/
<form method="post" class="contacts-form">
<input type="text" name="name" placeholder="Имя" class="form-text" id="name">
<input type="tel" name="phone" placeholder="Телефон" class="form-text" id="phone">
<button type="submit" class="btn-send">Отправить</button>
</form>
/Вторая форма/
<form method="post" class="contacts-form">
<input type="text" name="name" placeholder="Имя" class="form-text" id="name">
<input type="tel" name="phone" placeholder="Телефон" class="form-text" id="phone">
<textarea name="message" id="message" placeholder="Сообщение" class="form-message"></textarea>
<button type="submit" class="btn-send">Отправить</button>
</form>
$(document).on('submit', '.contacts-form', function(e) {
e.preventDefault();
var send = $(this).serialize().trim();
if (($(this).find('input[name="name"]').val().length >= 3) && ($(this).find('input[name="phone"]').inputmask('isComplete')) && ($(this).find('input[name="message"]').val().length >= 9)) {
$.ajax({
type: "POST",
url: "mailer/Sendmail.php",
data: send,
success: function(data) {
},
error: function(xhr){
alert('Возникла ошибка: ' + xhr.responseCode);
}
});
}
return false;
});
});
function loadScripts(arrScr) {
arrScr.forEach((src) => {
var scr = document.createElement('script');
scr.src = src;
document.body.appendChild(scr);
})
}
if (window.location.href.indexOf('index') != -1) {
loadScripts(['js/scripts.js', 'js/scripts2.js']);
}
if ($('#name').val().length >= 3) {
$(this).find('#name').css("border", "1px solid rgb(169, 169, 169)");
} else if ($('#email').val().length > 10 && $('#email').val().search(pattern) == 0) {
$(this).find('#email').css("border", "1px solid rgb(169, 169, 169)");
}
if ($('#name').val().length >= 3) {
$(this).find('#name').css("border", "1px solid rgb(169, 169, 169)");
}
if ($('#email').val().length > 10 && $('#email').val().search(pattern) == 0) {
$(this).find('#email').css("border", "1px solid rgb(169, 169, 169)");
}