Commit de48ab66 authored by Alexey Goikolov's avatar Alexey Goikolov

Удалил старые миграции. Создал новую миграцию. Добавил поиск в контроллере Phone…

Удалил старые миграции. Создал новую миграцию. Добавил поиск в контроллере Phone в экшене Index. Добавил форму поиска в представление Index.cshtml
parent af15bbaa
......@@ -19,11 +19,13 @@ namespace Lesson49.Controllers
}
// GET
public IActionResult Index() //Phones/Create
public IActionResult Index(string searchString) //Phones/Create
{
List<Phone> phones = _db.Phones
.Include(p => p.Brand)
.ToList();
if (!string.IsNullOrEmpty(searchString))
phones = phones.Where(p => p.Name.Contains(searchString, StringComparison.OrdinalIgnoreCase)).ToList();
return View(phones);
}
......
......@@ -18,10 +18,6 @@
<_ContentIncludedByDefault Remove="Views\Home\Privacy.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations" />
</ItemGroup>
<ItemGroup>
<None Update="Files\book.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
......
// <auto-generated />
using Lesson49.Models.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Lesson49.Migrations
{
[DbContext(typeof(MobileContext))]
[Migration("20210331134706_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.13");
modelBuilder.Entity("Lesson49.Models.Brand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("IsActive")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("WebSite")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Brands");
});
modelBuilder.Entity("Lesson49.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Address")
.HasColumnType("TEXT");
b.Property<string>("ContactPhone")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<int>("PhoneId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("PhoneId");
b.ToTable("Orders");
});
modelBuilder.Entity("Lesson49.Models.Phone", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("BrandId")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<double>("Price")
.HasColumnType("REAL");
b.HasKey("Id");
b.HasIndex("BrandId");
b.ToTable("Phones");
});
modelBuilder.Entity("Lesson49.Models.Order", b =>
{
b.HasOne("Lesson49.Models.Phone", "Phone")
.WithMany()
.HasForeignKey("PhoneId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Lesson49.Models.Phone", b =>
{
b.HasOne("Lesson49.Models.Brand", "Brand")
.WithMany()
.HasForeignKey("BrandId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}
......@@ -2,7 +2,7 @@
namespace Lesson49.Migrations
{
public partial class AddBrand : Migration
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
......
......@@ -7,8 +7,14 @@
<h2>Phones List</h2>
<h3>@ViewData["key"]</h3>
<div class="row">
<a class="col-2" asp-action="Add" asp-controller="Phones">Add phone</a>
<form class="col-7" asp-action="Index" asp-controller="Phones" method="get">
<input class="col-8" type="text" name="searchString" placeholder="Введите название модели">
<input type="submit" class="btn btn-info" value="Поиск">
</form>
</div>
<a asp-action="Add" asp-controller="Phones">Add phone</a>
<div class="table-section">
@if (Model.Count == 0)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment