Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
Webinar_51
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexey Goikolov
Webinar_51
Commits
6f377840
Commit
6f377840
authored
Mar 31, 2021
by
Alexey Goikolov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил свойство IsDeleted в модель Phone. Создал миграцию. Поменял выборку из БД в экшене Index
parent
de87b539
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
141 additions
and
2 deletions
+141
-2
PhonesController.cs
Lesson49/Controllers/PhonesController.cs
+3
-2
20210331141323_AddIsDeletedFieldInPhones.Designer.cs
...ions/20210331141323_AddIsDeletedFieldInPhones.Designer.cs
+110
-0
20210331141323_AddIsDeletedFieldInPhones.cs
...49/Migrations/20210331141323_AddIsDeletedFieldInPhones.cs
+23
-0
MobileContextModelSnapshot.cs
Lesson49/Migrations/MobileContextModelSnapshot.cs
+3
-0
Phone.cs
Lesson49/Models/Phone.cs
+2
-0
No files found.
Lesson49/Controllers/PhonesController.cs
View file @
6f377840
...
@@ -22,7 +22,7 @@ namespace Lesson49.Controllers
...
@@ -22,7 +22,7 @@ namespace Lesson49.Controllers
public
IActionResult
Index
(
string
searchString
)
//Phones/Create
public
IActionResult
Index
(
string
searchString
)
//Phones/Create
{
{
List
<
Phone
>
phones
=
_db
.
Phones
List
<
Phone
>
phones
=
_db
.
Phones
.
Include
(
p
=>
p
.
Brand
)
.
Include
(
p
=>
p
.
Brand
)
.
Where
(
p
=>
p
.
IsDeleted
==
false
)
.
ToList
();
.
ToList
();
if
(!
string
.
IsNullOrEmpty
(
searchString
))
if
(!
string
.
IsNullOrEmpty
(
searchString
))
phones
=
phones
.
Where
(
p
=>
p
.
Name
.
Contains
(
searchString
,
StringComparison
.
OrdinalIgnoreCase
)).
ToList
();
phones
=
phones
.
Where
(
p
=>
p
.
Name
.
Contains
(
searchString
,
StringComparison
.
OrdinalIgnoreCase
)).
ToList
();
...
@@ -66,7 +66,8 @@ namespace Lesson49.Controllers
...
@@ -66,7 +66,8 @@ namespace Lesson49.Controllers
Phone
phone
=
_db
.
Phones
.
FirstOrDefault
(
p
=>
p
.
Id
==
id
);
Phone
phone
=
_db
.
Phones
.
FirstOrDefault
(
p
=>
p
.
Id
==
id
);
if
(
phone
!=
null
)
if
(
phone
!=
null
)
{
{
_db
.
Phones
.
Remove
(
phone
);
phone
.
IsDeleted
=
true
;
_db
.
Phones
.
Update
(
phone
);
_db
.
SaveChanges
();
_db
.
SaveChanges
();
return
RedirectToAction
(
"Index"
);
return
RedirectToAction
(
"Index"
);
}
}
...
...
Lesson49/Migrations/20210331141323_AddIsDeletedFieldInPhones.Designer.cs
0 → 100644
View file @
6f377840
// <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
(
"20210331141323_AddIsDeletedFieldInPhones"
)]
partial
class
AddIsDeletedFieldInPhones
{
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
<
bool
>(
"IsDeleted"
)
.
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
}
}
}
Lesson49/Migrations/20210331141323_AddIsDeletedFieldInPhones.cs
0 → 100644
View file @
6f377840
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
Lesson49.Migrations
{
public
partial
class
AddIsDeletedFieldInPhones
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
AddColumn
<
bool
>(
name
:
"IsDeleted"
,
table
:
"Phones"
,
nullable
:
false
,
defaultValue
:
false
);
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropColumn
(
name
:
"IsDeleted"
,
table
:
"Phones"
);
}
}
}
Lesson49/Migrations/MobileContextModelSnapshot.cs
View file @
6f377840
...
@@ -69,6 +69,9 @@ namespace Lesson49.Migrations
...
@@ -69,6 +69,9 @@ namespace Lesson49.Migrations
b
.
Property
<
int
>(
"BrandId"
)
b
.
Property
<
int
>(
"BrandId"
)
.
HasColumnType
(
"INTEGER"
);
.
HasColumnType
(
"INTEGER"
);
b
.
Property
<
bool
>(
"IsDeleted"
)
.
HasColumnType
(
"INTEGER"
);
b
.
Property
<
string
>(
"Name"
)
b
.
Property
<
string
>(
"Name"
)
.
HasColumnType
(
"TEXT"
);
.
HasColumnType
(
"TEXT"
);
...
...
Lesson49/Models/Phone.cs
View file @
6f377840
...
@@ -8,5 +8,7 @@
...
@@ -8,5 +8,7 @@
public
int
BrandId
{
get
;
set
;
}
public
int
BrandId
{
get
;
set
;
}
public
Brand
Brand
{
get
;
set
;
}
public
Brand
Brand
{
get
;
set
;
}
public
double
Price
{
get
;
set
;
}
public
double
Price
{
get
;
set
;
}
public
bool
IsDeleted
{
get
;
set
;
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment