This commit is contained in:
Class_Student 2024-11-14 14:24:07 +03:00
parent 06b1f95063
commit 9ba62b2fa2
43 changed files with 862 additions and 598 deletions

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo1.Data.Migrations
{
internal class _20241025085326_InitialCreate
{
}
}

View File

@ -1,44 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo1.Migrations
{
[DbContext(typeof(RemoteDatabaseContext))]
partial class RemoteDatabaseContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupID")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,9 +1,10 @@
// Group.cs в RemoteData/RemoteDataBase/DAO
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
{
public class Group
public class GroupDAO
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public UserDAO User { get; set; }
}
}

View File

@ -3,14 +3,13 @@ using System.ComponentModel.DataAnnotations;
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
{
public class Presence
public class PresenceDAO
{
[Key]
public int PresenceId { get; set; } // Уникальный идентификатор записи
public DateTime ClassDate { get; set; }
public DateTime ClassDate { get; set; } // Дата занятия
public int LessonNumber { get; set; }
public bool WasPresent { get; set; }
public Guid UserId { get; set; }
// Убрать объект Id
}
}

View File

@ -1,12 +1,12 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
{
public class User
public class UserDAO
{
public Guid Id { get; set; }
public Guid UserId { get; set; } // Измените имя на UserId
public string FIO { get; set; } = string.Empty;
public int GroupID { get; set; }
}
}

View File

@ -8,7 +8,7 @@ namespace Demo.Data.RemoteData.RemoteDataBase
public TContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder<TContext>();
builder.UseNpgsql("Host=45.67.56.214;Port=5421;Database=PresenceDB;Username=user5;Password=EtEJqhsf");
builder.UseNpgsql("Host=45.67.56.214;Port=5421;Database=user5;Username=user5;Password=EtEJqhsf");
return CreateNewInstance(builder.Options);
}

View File

@ -1,9 +1,12 @@
using Demo.Data.LocalData.Entity;
using Demo.Data.LocalData.Entity; // Локальные сущности
using Demo.Data.RemoteData.RemoteDataBase.DAO; // DAO классы
using Microsoft.EntityFrameworkCore;
public class RemoteDatabaseContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<User> User { get; set; }
public DbSet<GroupDAO> Group { get; set; } // DbSet для GroupDao
public DbSet<PresenceDAO> Presence { get; set; } // DbSet для PresenceDao
public RemoteDatabaseContext(DbContextOptions<RemoteDatabaseContext> options) : base(options) { }
@ -11,7 +14,31 @@ public class RemoteDatabaseContext : DbContext
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Database=PresenceDB;Username=user5;Password=EtEJqhsf");
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Database=;Username=user5;Password=EtEJqhsf");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<GroupDAO>().HasKey(group => group.Id);
modelBuilder.Entity<GroupDAO>().Property(group => group.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<UserDAO>().HasKey(user => user.UserId);
modelBuilder.Entity<UserDAO>().Property(user => user.UserId).ValueGeneratedOnAdd();
modelBuilder.Entity<PresenceDAO>().HasKey(presence => presence.PresenceId); // Устанавливаем первичный ключ
// Дополнительные настройки для User
modelBuilder.Entity<User>(entity =>
{
entity.ToTable("User"); // Имя таблицы
entity.HasKey(e => e.Id); // Указываем первичный ключ
entity.Property(e => e.FIO)
.IsRequired()
.HasColumnName("FIO");
entity.Property(e => e.GroupID)
.IsRequired()
.HasColumnName("GroupID");
});
}
}

View File

@ -24,13 +24,13 @@ namespace Demo.Data.Repository
FIO = user.FIO,
GroupID = user.GroupID
};
_context.Users.Add(daoUser);
_context.User.Add(daoUser);
_context.SaveChanges();
}
public IEnumerable<UserDomain> GetAllUsers()
public IEnumerable<UserDomain> GetAllUser()
{
return _context.Users.Select(u => new UserDomain
return _context.User.Select(u => new UserDomain
{
Id = u.Id,
FIO = u.FIO,
@ -40,7 +40,7 @@ namespace Demo.Data.Repository
public UserDomain GetUserById(Guid id)
{
var daoUser = _context.Users.Find(id);
var daoUser = _context.User.Find(id);
if (daoUser == null) return null;
return new UserDomain
@ -53,7 +53,7 @@ namespace Demo.Data.Repository
public void UpdateUser(UserDomain user)
{
var daoUser = _context.Users.Find(user.Id);
var daoUser = _context.User.Find(user.Id);
if (daoUser != null)
{
daoUser.FIO = user.FIO;
@ -64,12 +64,23 @@ namespace Demo.Data.Repository
public void DeleteUser(Guid id)
{
var daoUser = _context.Users.Find(id);
var daoUser = _context.User.Find(id);
if (daoUser != null)
{
_context.Users.Remove(daoUser);
_context.User.Remove(daoUser);
_context.SaveChanges();
}
}
// Реализуем метод GetAllUsers
public IEnumerable<UserDomain> GetAllUsers()
{
return _context.User.Select(u => new UserDomain
{
Id = u.Id,
FIO = u.FIO,
GroupID = u.GroupID
}).ToList();
}
}
}

View File

@ -1,5 +1,5 @@
{
"ConnectionStrings": {
"DefaultConnection": "Host=45.67.56.214;Port=5421;Database=PresenceDB;Username=user5;Password=EtEJqhsf"
"DefaultConnection": "Host=45.67.56.214;Port=5421;Database=user5;Username=user5;Password=EtEJqhsf"
}
}

View File

@ -25,6 +25,7 @@
<ItemGroup>
<Folder Include="Data\RemoteData\RemoteApi\" />
<Folder Include="Migrations\" />
</ItemGroup>
</Project>

View File

@ -1,47 +0,0 @@
// <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;
#nullable disable
namespace Demo1.Migrations
{
[DbContext(typeof(RemoteDatabaseContext))]
[Migration("20241028115815_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupID")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,35 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Demo1.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
FIO = table.Column<string>(type: "text", nullable: false),
GroupID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Users");
}
}
}

View File

@ -0,0 +1,125 @@
// <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;
#nullable disable
namespace Demo1.Migrations
{
[DbContext(typeof(RemoteDatabaseContext))]
[Migration("20241114100437_create")]
partial class create
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Demo.Data.LocalData.Entity.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text")
.HasColumnName("FIO");
b.Property<int>("GroupID")
.HasColumnType("integer")
.HasColumnName("GroupID");
b.HasKey("Id");
b.ToTable("User", (string)null);
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Group");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b =>
{
b.Property<int>("PresenceId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("PresenceId"));
b.Property<DateTime>("ClassDate")
.HasColumnType("timestamp with time zone");
b.Property<int>("LessonNumber")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.Property<bool>("WasPresent")
.HasColumnType("boolean");
b.HasKey("PresenceId");
b.ToTable("Presence");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b =>
{
b.Property<Guid>("UserId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupID")
.HasColumnType("integer");
b.HasKey("UserId");
b.ToTable("UserDAO");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
{
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,99 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo1.Migrations
{
/// <inheritdoc />
public partial class create : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Presence",
columns: table => new
{
PresenceId = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClassDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
LessonNumber = table.Column<int>(type: "integer", nullable: false),
WasPresent = table.Column<bool>(type: "boolean", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Presence", x => x.PresenceId);
});
migrationBuilder.CreateTable(
name: "User",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
FIO = table.Column<string>(type: "text", nullable: false),
GroupID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
});
migrationBuilder.CreateTable(
name: "UserDAO",
columns: table => new
{
UserId = table.Column<Guid>(type: "uuid", nullable: false),
FIO = table.Column<string>(type: "text", nullable: false),
GroupID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserDAO", x => x.UserId);
});
migrationBuilder.CreateTable(
name: "Group",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Group", x => x.Id);
table.ForeignKey(
name: "FK_Group_UserDAO_UserId",
column: x => x.UserId,
principalTable: "UserDAO",
principalColumn: "UserId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Group_UserId",
table: "Group",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Group");
migrationBuilder.DropTable(
name: "Presence");
migrationBuilder.DropTable(
name: "User");
migrationBuilder.DropTable(
name: "UserDAO");
}
}
}

View File

@ -0,0 +1,122 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo1.Migrations
{
[DbContext(typeof(RemoteDatabaseContext))]
partial class RemoteDatabaseContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Demo.Data.LocalData.Entity.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text")
.HasColumnName("FIO");
b.Property<int>("GroupID")
.HasColumnType("integer")
.HasColumnName("GroupID");
b.HasKey("Id");
b.ToTable("User", (string)null);
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Group");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b =>
{
b.Property<int>("PresenceId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("PresenceId"));
b.Property<DateTime>("ClassDate")
.HasColumnType("timestamp with time zone");
b.Property<int>("LessonNumber")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.Property<bool>("WasPresent")
.HasColumnType("boolean");
b.HasKey("PresenceId");
b.ToTable("Presence");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b =>
{
b.Property<Guid>("UserId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupID")
.HasColumnType("integer");
b.HasKey("UserId");
b.ToTable("UserDAO");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
{
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -26,7 +26,7 @@ namespace Demo.UI
{
// Если контекст не предоставлен, создаем новый
var optionsBuilder = new DbContextOptionsBuilder<RemoteDatabaseContext>();
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Database=PresenceDB;Username=user5;Password=EtEJqhsf");
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Database=user5;Username=user5;Password=EtEJqhsf");
_context = new RemoteDatabaseContext(optionsBuilder.Options);
}
else

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Demo1")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ad36f40a574ff1f9c69220e247e17f0f61b8504b")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+06b1f950636c0e6a821db89e32cb6df6c2d4fc5f")]
[assembly: System.Reflection.AssemblyProductAttribute("Demo1")]
[assembly: System.Reflection.AssemblyTitleAttribute("Demo1")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
5c715191160bff39fcd95ea2a88ceccb0dc4e7a144114f272a3a5f3987941750
8046c00cc63f26032cdf9c354ffd58718de497cdf22950b9f6347890d28bab85

View File

@ -1 +1 @@
d655c7cb8cbdb4061a8574767df01e6ea05e59f4d09a28cc7cce78e04174cb6c
a2e9375af416c60c5d5a6c13c3a19ecad9cc79f6c813241ee14a887ff123cd9e

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.