Удалить кастомного пользователя.

***
- Удалил класс кастомного пользователя.
- Подключил пакет Identity
***
parent da08ac38
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using PhoneStore.Models;
namespace PhoneStore.Migrations
{
[DbContext(typeof(MobileContext))]
[Migration("20220721200244_RemoveCustomUser")]
partial class RemoveCustomUser
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 63)
.HasAnnotation("ProductVersion", "5.0.17")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("PhoneStore.Models.Basket", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("PhoneId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("PhoneId");
b.ToTable("Baskets");
});
modelBuilder.Entity("PhoneStore.Models.Brand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Brands");
});
modelBuilder.Entity("PhoneStore.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Address")
.HasColumnType("text");
b.Property<string>("ContactPhone")
.HasColumnType("text");
b.Property<int>("PhoneId")
.HasColumnType("integer");
b.Property<string>("UserName")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("PhoneId");
b.ToTable("Orders");
});
modelBuilder.Entity("PhoneStore.Models.Phone", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int?>("BrandId")
.HasColumnType("integer");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<decimal>("Price")
.HasColumnType("numeric");
b.HasKey("Id");
b.HasIndex("BrandId");
b.ToTable("Phones");
});
modelBuilder.Entity("PhoneStore.Models.Basket", b =>
{
b.HasOne("PhoneStore.Models.Phone", "Phone")
.WithMany()
.HasForeignKey("PhoneId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Phone");
});
modelBuilder.Entity("PhoneStore.Models.Order", b =>
{
b.HasOne("PhoneStore.Models.Phone", "Phone")
.WithMany()
.HasForeignKey("PhoneId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Phone");
});
modelBuilder.Entity("PhoneStore.Models.Phone", b =>
{
b.HasOne("PhoneStore.Models.Brand", "Brand")
.WithMany()
.HasForeignKey("BrandId");
b.Navigation("Brand");
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace PhoneStore.Migrations
{
public partial class RemoveCustomUser : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Users");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Age = table.Column<int>(type: "integer", nullable: false),
Name = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
}
}
}
......@@ -103,24 +103,6 @@ namespace PhoneStore.Migrations
b.ToTable("Phones");
});
modelBuilder.Entity("PhoneStore.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("Age")
.HasColumnType("integer");
b.Property<string>("Name")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("PhoneStore.Models.Basket", b =>
{
b.HasOne("PhoneStore.Models.Phone", "Phone")
......
......@@ -8,7 +8,6 @@ namespace PhoneStore.Models
public DbSet<Order> Orders { get; set; }
public DbSet<Basket> Baskets { get; set; }
public DbSet<Brand> Brands { get; set; }
public DbSet<User> Users { get; set; }
public MobileContext(DbContextOptions<MobileContext> options) : base(options)
{
......
using Microsoft.AspNetCore.Identity;
namespace PhoneStore.Models
{
public class User
public class User : IdentityUser<int>
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
public class ApplicationRole : IdentityRole<int>
{
public ApplicationRole() : base()
{
}
public ApplicationRole(string roleName) : base(roleName)
{
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
......
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using PhoneStore.Helpers;
using PhoneStore.Models;
using PhoneStore.Services.Abstractions;
using PhoneStore.ViewModels;
using Order = PhoneStore.Enums.Order;
namespace PhoneStore.Services
{
public class UserService : IUserService
{
private readonly MobileContext _db;
private readonly IUsersSortService _sortService;
private readonly IUsersFilter _usersFilter;
private readonly IPaginationService<User> _paginationService;
private readonly IConfiguration _configuration;
public UserService(
MobileContext db,
IUsersSortService sortService,
IUsersFilter usersFilter,
IPaginationService<User> paginationService,
IConfiguration configuration)
{
_db = db;
_sortService = sortService;
_usersFilter = usersFilter;
_paginationService = paginationService;
_configuration = configuration;
}
public async Task<UsersViewModel> GetAll(Order order, string filterByName, int page)
{
var pageSize = int.Parse(_configuration["UsersPageSize"]);
var users = _db.Users.AsQueryable();
var filteredUsers = _usersFilter.FilterByName(users, filterByName);
var sortedUsers = _sortService.Sort(filteredUsers, order);
var (queryable, count) = await _paginationService.GetABatchOfData(sortedUsers, page, pageSize);
return queryable.MapToUsersViewModel(filterByName, page, count, pageSize);
}
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ namespace PhoneStore
services.AddTransient<IDefaultPhoneImagePathProvider>(_ =>
new DefaultPhoneImagePathProvider(Configuration["PathToDefaultAvatar:Path"]));
services.AddTransient<IPhoneService, PhoneService>();
services.AddTransient<IUserService, UserService>();
// services.AddTransient<IUserService, UserService>();
services.AddTransient<IUsersSortService, UsersSortService>();
services.AddTransient<IUsersFilter, UsersFilter>();
services.AddTransient<IPaginationService<User>, PaginationService<User>>();
......
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