проект 5 #1

Open
Bricksoul wants to merge 2 commits from develop into master
28 changed files with 831 additions and 89 deletions
Showing only changes of commit 6b9b5a424f - Show all commits

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.domain.Models
namespace Demo.Data.Entity
{
public class GroupLocalEntity
{

View File

@ -4,12 +4,12 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.domain.Models
namespace Demo.Data.Entity
{
public class PresenceLocalEntity
{
public required Guid UserGuid { get; set; }
public bool IsAttedance { get; set; } = true;
public bool IsAttedance { get; set; }
public required DateOnly Date { get; set; }
public required int LessonNumber { get; set; }

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.domain.Models
namespace Demo.Data.Entity
{
public class UserLocalEnity : IEquatable<UserLocalEnity>
{
@ -13,12 +13,12 @@ namespace Demo.domain.Models
public required int GroupID { get; set; }
public bool Equals(UserLocalEnity? other)
{
if (other == null) return false;
return this.Guid.Equals(other.Guid);
return Guid.Equals(other.Guid);
}
}
}

View File

@ -1,4 +1,4 @@
using Demo.domain.Models;
using Demo.Data.Entity;
using System;
using System.Collections.Generic;
using System.Linq;

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
{
public class GroupDao
{
public int Id { get; set; } // Обратите внимание на заглавную букву
public required string Name { get; set; }
public IEnumerable<UserDao> Users { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
{
public class PresenceDao
{
public Guid UserGuid { get; set; }
public bool IsAttedance { get; set; }
public DateOnly Date { get; set; }
public int LessonNumber { get; set; }
public UserDao UserDao { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
{
public class UserDao
{
public required string F10 { get; set; }
public Guid Guid { get; set; }
public required int GroupId { get; set; }
public GroupDao Group { get; set; }
}
}

View File

@ -0,0 +1,39 @@
using System;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
namespace Demo.Data.RemoteData.RemoteDataBase
{
public class RemoteDatabaseContex : DbContext
{
public DbSet<GroupDao> Groups {get; set;}
public DbSet<UserDao> Users {get; set;}
public DbSet<PresenceDao> PresenceDaos {get; set;}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Username=user9;Database=user9;Password=X8C8NTnD;");
}
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.Guid);
modelBuilder.Entity<UserDao>().Property(user => user.Guid).ValueGeneratedOnAdd();
modelBuilder.Entity <PresenceDao>().HasKey(presence =>new
{
presence.UserGuid,
presence.Date,
presence.IsAttedance,
presence.LessonNumber
});
}
}
}

View File

@ -1,4 +1,5 @@
using Demo.Data.LocalData;
using Demo.Data.Entity;
using Demo.Data.LocalData;
using Demo.domain.Models;
using System.Collections.Generic;
using System.Linq;

View File

@ -1,19 +1,13 @@
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Demo.Data.Entity;
namespace Demo.Data.Repository
{
public interface IGroupRepository
{
bool AddGroup(GroupLocalEntity newGroup);
bool AddGroup(GroupLocalEntity newGroup);
List<GroupLocalEntity> GetAllGroup();
GroupLocalEntity GetGroupById(int groupID);
bool RemoveGroupById(int groupID);
bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup);
GroupLocalEntity GetGroupById(int groupId);
bool UpdateGroupById(int groupId, GroupLocalEntity updatedGroup);
bool RemoveGroupById(int groupId);
}
}

View File

@ -0,0 +1,11 @@
using Demo.Data.Entity;
using System.Collections.Generic;
namespace Demo.Data.Repository
{
public interface IPresenceRepository
{
bool AddPresence(PresenceLocalEntity newPresence);
List<PresenceLocalEntity> GetAllPresences();
}
}

View File

@ -0,0 +1,14 @@
using Demo.Data.Entity;
using System.Collections.Generic;
namespace Demo.Data.Repository
{
public interface IUserRepository
{
bool AddUser(UserLocalEnity newUser);
List<UserLocalEnity> GetAllUsers();
UserLocalEnity GetUserById(Guid userID);
bool RemoveUserById(Guid userID);
bool UpdateUserById(Guid userID, UserLocalEnity updatedUser);
}
}

View File

@ -0,0 +1,90 @@
using Demo.Data.Entity;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Data.Repository
{
class SQLGroupRepositoryLmpl : IGroupRepository
{
private readonly RemoteDatabaseContex _remoteDatabaseContext;
public SQLGroupRepositoryLmpl(RemoteDatabaseContex remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
public bool AddGroup(GroupLocalEntity newGroup)
{
GroupDao groupDao = new GroupDao { Name = newGroup.Name };
var result = _remoteDatabaseContext.Groups.Add(groupDao);
_remoteDatabaseContext.SaveChanges();
if (result != null) return true;
return false;
}
public List<GroupLocalEntity> GetAllGroup()
{
var groups = _remoteDatabaseContext.Groups.ToList();
return groups.Select(g => new GroupLocalEntity
{
Id = g.Id,
Name = g.Name
}).ToList();
}
public GroupLocalEntity GetGroupById(int groupID)
{
var group = _remoteDatabaseContext.Groups
.FirstOrDefault(g => g.Id == groupID);
if (group == null)
{
return null;
}
return new GroupLocalEntity
{
Id = group.Id,
Name = group.Name
};
}
public bool RemoveGroupById(int groupID)
{
var group = _remoteDatabaseContext.Groups
.FirstOrDefault(g => g.Id == groupID);
if (group == null)
{
return false;
}
_remoteDatabaseContext.Groups.Remove(group);
_remoteDatabaseContext.SaveChanges();
return true;
}
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
{
var existingGroup = _remoteDatabaseContext.Groups
.FirstOrDefault(g => g.Id == groupID);
if (existingGroup == null)
{
return false;
}
existingGroup.Name = updatedGroup.Name;
_remoteDatabaseContext.SaveChanges();
return true;
}
}
}

View File

@ -0,0 +1,45 @@
using Demo.Data.Entity;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Data.Repository
{
public class SQLPresenceRepositoryImpl : IPresenceRepository
{
private readonly RemoteDatabaseContex _remoteDatabaseContext;
public SQLPresenceRepositoryImpl(RemoteDatabaseContex remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
public bool AddPresence(PresenceLocalEntity newPresence)
{
var presenceDao = new PresenceDao
{
UserGuid = newPresence.UserGuid,
IsAttedance = newPresence.IsAttedance, // Используем IsAttendance
Date = newPresence.Date,
LessonNumber = newPresence.LessonNumber
};
_remoteDatabaseContext.PresenceDaos.Add(presenceDao);
return _remoteDatabaseContext.SaveChanges() > 0; // Возвращаем true, если изменения сохранены
}
public List<PresenceLocalEntity> GetAllPresences()
{
return _remoteDatabaseContext.PresenceDaos
.Select(p => new PresenceLocalEntity
{
UserGuid = p.UserGuid,
IsAttedance = p.IsAttedance, // Обратите внимание на правильное название свойства
Date = p.Date,
LessonNumber = p.LessonNumber
})
.ToList();
}
}
}

View File

@ -0,0 +1,94 @@
using Demo.Data.Entity;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Data.Repository
{
public class SQLUserRepositoryImpl : IUserRepository
{
private readonly RemoteDatabaseContex _remoteDatabaseContext;
public SQLUserRepositoryImpl(RemoteDatabaseContex remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
public bool AddUser(UserLocalEnity newUser)
{
var userDao = new UserDao
{
Guid = Guid.NewGuid(),
F10 = newUser.FIO,
GroupId = newUser.GroupID
};
_remoteDatabaseContext.Users.Add(userDao);
return _remoteDatabaseContext.SaveChanges() > 0;
}
public List<UserLocalEnity> GetAllUsers()
{
return _remoteDatabaseContext.Users
.Select(user => new UserLocalEnity
{
Guid = user.Guid,
FIO = user.F10,
GroupID = user.GroupId
})
.ToList();
}
public UserLocalEnity GetUserById(Guid userID)
{
var user = _remoteDatabaseContext.Users.Find(userID);
if (user == null)
{
return null;
}
return new UserLocalEnity
{
Guid = user.Guid,
GroupID = user.GroupId,
FIO = user.F10
};
}
public bool RemoveUserById(Guid userID)
{
var user = _remoteDatabaseContext.Users.Find(userID);
if (user == null)
{
return false;
}
_remoteDatabaseContext.Users.Remove(user);
_remoteDatabaseContext.SaveChanges();
return true;
}
public bool UpdateUserById(Guid userID, UserLocalEnity updatedUser)
{
var user = _remoteDatabaseContext.Users.Find(userID);
if (user == null)
{
return false;
}
user.GroupId = updatedUser.GroupID;
user.Guid = updatedUser.Guid;
_remoteDatabaseContext.SaveChanges();
return true;
}
}
}

View File

@ -1,5 +1,5 @@
using Demo.Data.LocalData;
using Demo.domain.Models;
using Demo.Data.Entity;
using Demo.Data.LocalData;
using System;
using System.Collections.Generic;
using System.Linq;

View File

@ -8,7 +8,17 @@
</PropertyGroup>
<ItemGroup>
<Folder Include="Data\RemoteData\" />
<Folder Include="Data\RemoteData\RemoteApi\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,5 @@
using Demo.Data.LocalData;
using Demo.Data.Entity;
using Demo.Data.LocalData;
using Demo.Data.Repository;
using Demo.domain.Models;
using System.Collections.Generic;
@ -8,15 +9,15 @@ namespace Demo.Domain.UseCase
{
public class GroupUseCase
{
private GroupRepositoryImpl _repositoryGroupImpl;
private IGroupRepository _repositoryGroupImpl;
public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl)
public GroupUseCase(IGroupRepository repositoryGroupImpl)
{
_repositoryGroupImpl = repositoryGroupImpl;
}
public bool RemoveGroupById(int groupID)
{
var group = _repositoryGroupImpl.GetAllGroups.FirstOrDefault(g => g.Id == groupID);
var group = _repositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == groupID);
if (group != null)
{
_repositoryGroupImpl.RemoveGroupById(groupID);

View File

@ -1,5 +1,5 @@
using Demo.Data.LocalData;
using Demo.domain.Models;
using Demo.Data.Entity;
using Demo.Data.LocalData;
using System.Collections.Generic;
using System.Linq;
@ -32,23 +32,25 @@ namespace Demo.Domain.UseCase
presence.IsAttedance = false;
}
}
public void GenerateDailySchedule(int groupId, int startLesson, int endLesson)
public void GenerateDailySchedule(int groupId, int startLesson, int endLesson, DateTime date)
{
var usersInGroup = LocalStaticData.users
.Where(u => u.GroupID == groupId)
.ToList();
LocalStaticData.presences.RemoveAll(p => usersInGroup.Select(users => users.Guid).Contains(p.UserGuid) && p.Date == DateOnly.FromDateTime(date));
Console.WriteLine($"Расписание для группы {groupId}:");
foreach (var user in usersInGroup)
{
for (int lesson = startLesson; lesson <= endLesson; lesson++)
{
var presence = new PresenceLocalEntity
{
UserGuid = user.Guid,
IsAttedance = true,
Date = DateOnly.FromDateTime(DateTime.Now),
Date = DateOnly.FromDateTime(date),
LessonNumber = lesson
};
@ -57,6 +59,14 @@ namespace Demo.Domain.UseCase
Console.WriteLine($"User: {user.Guid}, Attended: {presence.IsAttedance}, Date: {presence.Date}, Lesson: {presence.LessonNumber}");
}
}
}
public void GenerateWeeklySchedule(int groupId, int startLesson, int endLesson, DateTime date)
{
for(int i = 0; i < 7;i++)
{
GenerateDailySchedule(groupId, startLesson, endLesson, date.AddDays(i));
}
}
}
}

View File

@ -1,4 +1,5 @@
using Demo.Data.Repository;
using Demo.Data.Entity;
using Demo.Data.Repository;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
@ -8,11 +9,11 @@ namespace Demo.Domain.UseCase
{
public class UserUseCase
{
private readonly UserRepositoryImpl _repositoryUserImpl;
private readonly IUserRepository _repositoryUserImpl;
private readonly IGroupRepository _repositoryGroupImpl;
public UserUseCase(UserRepositoryImpl repositoryImpl, IGroupRepository repositoryGroupImpl)
public UserUseCase(IUserRepository repositoryImpl, IGroupRepository repositoryGroupImpl)
{
_repositoryUserImpl = repositoryImpl;
_repositoryGroupImpl = repositoryGroupImpl;
@ -21,7 +22,7 @@ namespace Demo.Domain.UseCase
private List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
.Select(it => new Group { Id = it.Id, Name = it.Name }).ToList();
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers()
.Join(_repositoryGroupImpl.GetAllGroup(),
user => user.GroupID,
group => group.Id,
@ -31,22 +32,22 @@ namespace Demo.Domain.UseCase
public bool RemoveUserByGuid(Guid userGuid)
{
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
return _repositoryUserImpl.RemoveUserById(userGuid);
}
public User UpdateUser(User user)
public User UpdateUser(Guid userGuid,User user)
{
UserLocalEnity userLocalEnity = new UserLocalEnity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid };
UserLocalEnity? result = _repositoryUserImpl.UpdateUser(userLocalEnity);
if (result == null) throw new Exception("");
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.GroupID);
bool result = _repositoryUserImpl.UpdateUserById(userGuid, userLocalEnity);
if (!result) throw new Exception("");
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == user.Group.Id);
if (group == null) throw new Exception("");
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
}
public User? FindUserByGuid(Guid userGuid)
{
var userLocal = _repositoryUserImpl.GetUserByGuid(userGuid);
var userLocal = _repositoryUserImpl.GetUserById(userGuid);
if (userLocal == null) return null;
var group = _repositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == userLocal.GroupID);

View File

@ -0,0 +1,118 @@
// <auto-generated />
using System;
using Demo.Data.RemoteData.RemoteDataBase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo.Migrations
{
[DbContext(typeof(RemoteDatabaseContex))]
[Migration("20241028123800_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.GroupDao", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Groups");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b =>
{
b.Property<Guid>("UserGuid")
.HasColumnType("uuid");
b.Property<DateOnly>("Date")
.HasColumnType("date");
b.Property<bool>("IsAttedance")
.HasColumnType("boolean");
b.Property<int>("LessonNumber")
.HasColumnType("integer");
b.Property<Guid>("UserDaoGuid")
.HasColumnType("uuid");
b.HasKey("UserGuid", "Date", "IsAttedance", "LessonNumber");
b.HasIndex("UserDaoGuid");
b.ToTable("PresenceDaos");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b =>
{
b.Property<Guid>("Guid")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("F10")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupId")
.HasColumnType("integer");
b.HasKey("Guid");
b.HasIndex("GroupId");
b.ToTable("Users");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b =>
{
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", "UserDao")
.WithMany()
.HasForeignKey("UserDaoGuid")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("UserDao");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b =>
{
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", "Group")
.WithMany("Users")
.HasForeignKey("GroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b =>
{
b.Navigation("Users");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,92 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Guid = table.Column<Guid>(type: "uuid", nullable: false),
F10 = table.Column<string>(type: "text", nullable: false),
GroupId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Guid);
table.ForeignKey(
name: "FK_Users_Groups_GroupId",
column: x => x.GroupId,
principalTable: "Groups",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PresenceDaos",
columns: table => new
{
UserGuid = table.Column<Guid>(type: "uuid", nullable: false),
IsAttedance = table.Column<bool>(type: "boolean", nullable: false),
Date = table.Column<DateOnly>(type: "date", nullable: false),
LessonNumber = table.Column<int>(type: "integer", nullable: false),
UserDaoGuid = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PresenceDaos", x => new { x.UserGuid, x.Date, x.IsAttedance, x.LessonNumber });
table.ForeignKey(
name: "FK_PresenceDaos_Users_UserDaoGuid",
column: x => x.UserDaoGuid,
principalTable: "Users",
principalColumn: "Guid",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_PresenceDaos_UserDaoGuid",
table: "PresenceDaos",
column: "UserDaoGuid");
migrationBuilder.CreateIndex(
name: "IX_Users_GroupId",
table: "Users",
column: "GroupId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PresenceDaos");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Groups");
}
}
}

View File

@ -0,0 +1,115 @@
// <auto-generated />
using System;
using Demo.Data.RemoteData.RemoteDataBase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo.Migrations
{
[DbContext(typeof(RemoteDatabaseContex))]
partial class RemoteDatabaseContexModelSnapshot : 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.GroupDao", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Groups");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b =>
{
b.Property<Guid>("UserGuid")
.HasColumnType("uuid");
b.Property<DateOnly>("Date")
.HasColumnType("date");
b.Property<bool>("IsAttedance")
.HasColumnType("boolean");
b.Property<int>("LessonNumber")
.HasColumnType("integer");
b.Property<Guid>("UserDaoGuid")
.HasColumnType("uuid");
b.HasKey("UserGuid", "Date", "IsAttedance", "LessonNumber");
b.HasIndex("UserDaoGuid");
b.ToTable("PresenceDaos");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b =>
{
b.Property<Guid>("Guid")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("F10")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupId")
.HasColumnType("integer");
b.HasKey("Guid");
b.HasIndex("GroupId");
b.ToTable("Users");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b =>
{
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", "UserDao")
.WithMany()
.HasForeignKey("UserDaoGuid")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("UserDao");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b =>
{
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", "Group")
.WithMany("Users")
.HasForeignKey("GroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
});
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b =>
{
b.Navigation("Users");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,17 +1,29 @@
using Demo.Data.Repository;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.Repository;
using Demo.Domain.UseCase;
using Demo.UI;
using Microsoft.Extensions.DependencyInjection;
class Program
{
static void Main(string[] args)
{
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();
UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl();
UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl);
GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl);
UseCasePresence presenceUseCase = new UseCasePresence();
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase, presenceUseCase);
IServiceCollection services = new ServiceCollection();
services.AddDbContext<RemoteDatabaseContex>()
.AddSingleton<IGroupRepository, SQLGroupRepositoryLmpl>()
.AddSingleton<IUserRepository, SQLUserRepositoryImpl>()
.AddSingleton<IPresenceRepository, SQLPresenceRepositoryImpl>()
.AddSingleton<GroupUseCase>()
.AddSingleton<UseCaseGeneratePresence>()
.AddSingleton<UserUseCase>()
.AddSingleton<UseCasePresence>()
.AddSingleton<UserConsoleUI>()
.AddSingleton<PresenceConsoleUI>()
.AddSingleton<GroupConsoleUI>()
.AddSingleton<MainMenuUI>();
var serviceProvaider = services.BuildServiceProvider();
MainMenuUI mainMenuUI= serviceProvaider.GetService<MainMenuUI>();
mainMenuUI.DisplayMenu();
}
}

View File

@ -1,4 +1,5 @@
using Demo.Data.LocalData;
using Demo.Data.Entity;
using Demo.Data.LocalData;
using Demo.domain.Models;
using Demo.Domain.UseCase;
using System;

View File

@ -11,17 +11,15 @@ namespace Demo.UI
private UseCasePresence _presenceUseCase;
private PresenceConsoleUI _presenceConsoleUI;
public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase, UseCasePresence presenceUseCase)
public MainMenuUI(UserConsoleUI userConsoleUI, GroupConsoleUI groupConsoleUI, PresenceConsoleUI presenceConsoleUI)
{
_userConsoleUI = new UserConsoleUI(userUseCase);
_groupConsoleUI = new GroupConsoleUI(groupUseCase);
_presenceUseCase = presenceUseCase;
_presenceConsoleUI = new PresenceConsoleUI(presenceUseCase);
DisplayMenu();
_userConsoleUI = userConsoleUI;
_groupConsoleUI = groupConsoleUI;
_presenceConsoleUI = presenceConsoleUI;
}
private void DisplayMenu()
public void DisplayMenu()
{
while (true)
{
@ -38,6 +36,7 @@ namespace Demo.UI
Console.WriteLine("10 - Вывести посещаемость по группе и дате");
Console.WriteLine("11 - Отметить пользователя как отсутствующего");
Console.WriteLine("12 - Генерация расписания по диапозону");
Console.WriteLine("13 - Генерация расписания по диапозону на неделю");
Console.WriteLine("0 - Выход");
var input = Console.ReadLine();
@ -74,7 +73,7 @@ namespace Demo.UI
Group = new Group { Id = newGroupId, Name = newGroupName }
};
_userConsoleUI.UpdateUser(updatedUser);
_userConsoleUI.UpdateUser(updateGuid, updatedUser);
}
else
{
@ -151,11 +150,42 @@ namespace Demo.UI
}
break;
case "11":
_presenceConsoleUI.MarkUserAsAbsent();
Console.WriteLine("Введите GUID пользователя для отметки отсутствия:");
if (Guid.TryParse(Console.ReadLine(), out var absenceUserGuid))
{
Console.WriteLine("Введите дату (в формате ГГГГ-ММ-ДД):");
if (DateOnly.TryParse(Console.ReadLine(), out var absenceDate))
{
Console.WriteLine("Введите диапазон уроков (например, 2-4):");
var lessonRange = Console.ReadLine().Split('-');
if (lessonRange.Length == 2 &&
int.TryParse(lessonRange[0], out var startLesson) &&
int.TryParse(lessonRange[1], out var endLesson))
{
// Вызов метода для отметки отсутствия
_presenceConsoleUI.MarkUserAsAbsent(absenceUserGuid, absenceDate, startLesson, endLesson);
}
else
{
Console.WriteLine("Некорректный диапазон уроков.");
}
}
else
{
Console.WriteLine("Некорректная дата.");
}
}
else
{
Console.WriteLine("Некорректный GUID.");
}
break;
case "12":
_presenceConsoleUI.GenerateDailySchedule();
break;
case "13":
_presenceConsoleUI.GenerateWeeklySchedule();
break;
case "0":
return;
default:

View File

@ -1,4 +1,7 @@
using Demo.Domain.UseCase;
using Demo.Data.Entity;
using Demo.Data.LocalData;
using Demo.domain.Models;
using Demo.Domain.UseCase;
using System;
namespace Demo.UI
@ -39,33 +42,21 @@ namespace Demo.UI
Console.WriteLine($"User: {presence.UserGuid}, Attended: {presence.IsAttedance}, Lesson: {presence.LessonNumber}");
}
}
public void MarkUserAsAbsent()
public void MarkUserAsAbsent(Guid userGuid, DateOnly date, int startLesson, int endLesson)
{
Console.WriteLine("Введите GUID пользователя:");
if (Guid.TryParse(Console.ReadLine(), out var userGuid))
_useCasePresence.MarkUserAsAbsent(userGuid, startLesson, endLesson);
for (int lesson = startLesson; lesson <= endLesson; lesson++)
{
Console.WriteLine("Введите номер первого занятия:");
if (int.TryParse(Console.ReadLine(), out int startLesson))
var presence = new PresenceLocalEntity
{
Console.WriteLine("Введите номер последнего занятия:");
if (int.TryParse(Console.ReadLine(), out int endLesson))
{
_useCasePresence.MarkUserAsAbsent(userGuid, startLesson, endLesson);
Console.WriteLine("Пользователь отмечен как отсутствующий.");
}
else
{
Console.WriteLine("Некорректный номер последнего занятия.");
}
}
else
{
Console.WriteLine("Некорректный номер первого занятия.");
}
}
else
{
Console.WriteLine("Некорректный GUID.");
UserGuid = userGuid,
IsAttedance = false,
Date = date,
LessonNumber = lesson
};
// Вывод информации о отметке
Console.WriteLine($"User: {userGuid}, Attended: {presence.IsAttedance}, Date: {presence.Date}, Lesson: {presence.LessonNumber}");
}
}
public void GenerateDailySchedule()
@ -79,7 +70,35 @@ namespace Demo.UI
Console.WriteLine("Введите номер последнего урока:");
if (int.TryParse(Console.ReadLine(), out int endLesson))
{
_useCasePresence.GenerateDailySchedule(groupId, startLesson, endLesson);
_useCasePresence.GenerateDailySchedule(groupId, startLesson, endLesson,DateTime.Now);
}
else
{
Console.WriteLine("Некорректный номер последнего урока.");
}
}
else
{
Console.WriteLine("Некорректный номер первого урока.");
}
}
else
{
Console.WriteLine("Некорректный ID группы.");
}
}
public void GenerateWeeklySchedule()
{
Console.WriteLine("Введите ID группы:");
if (int.TryParse(Console.ReadLine(), out int groupId))
{
Console.WriteLine("Введите номер первого урока:");
if (int.TryParse(Console.ReadLine(), out int startLesson))
{
Console.WriteLine("Введите номер последнего урока:");
if (int.TryParse(Console.ReadLine(), out int endLesson))
{
_useCasePresence.GenerateWeeklySchedule(groupId, startLesson, endLesson, DateTime.Now);
}
else
{
@ -97,6 +116,5 @@ namespace Demo.UI
}
}
}
}

View File

@ -43,9 +43,9 @@ namespace Demo.UI
}
}
public void UpdateUser(User updatedUser)
public void UpdateUser(Guid userGuid, User updatedUser)
{
var result = _userUseCase.UpdateUser(updatedUser);
var result = _userUseCase.UpdateUser(userGuid, updatedUser);
if (result != null)
{
Console.WriteLine("Пользователь обновлён.");