final
This commit is contained in:
commit
be7c0f9372
25
Demo.sln
Normal file
25
Demo.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.11.35312.102
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo", "Demo\Demo.csproj", "{983820F6-FF31-4B3A-8593-831BC3904E80}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{983820F6-FF31-4B3A-8593-831BC3904E80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{983820F6-FF31-4B3A-8593-831BC3904E80}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{983820F6-FF31-4B3A-8593-831BC3904E80}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{983820F6-FF31-4B3A-8593-831BC3904E80}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {4F43A963-447C-4FCB-BB78-8D315EC0F1D6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
15
Demo/Data/Entity/Group.cs
Normal file
15
Demo/Data/Entity/Group.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
{
|
||||
public class GroupLocalEntity
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
|
||||
}
|
||||
}
|
17
Demo/Data/Entity/Presence.cs
Normal file
17
Demo/Data/Entity/Presence.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
{
|
||||
internal class PresenceLocalEntity
|
||||
{
|
||||
public required Guid UserGuid { get; set; }
|
||||
public bool IsAttedance { get; set; } = true;
|
||||
public required DateOnly Date { get; set; }
|
||||
|
||||
public required int LessonNumber { get; set; }
|
||||
}
|
||||
}
|
24
Demo/Data/Entity/User.cs
Normal file
24
Demo/Data/Entity/User.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
{
|
||||
public class UserLocalEnity : IEquatable<UserLocalEnity>
|
||||
{
|
||||
public required string FIO { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
|
||||
public required int GroupID { get; set; }
|
||||
|
||||
|
||||
|
||||
public bool Equals(UserLocalEnity? other)
|
||||
{
|
||||
if (other == null) return false;
|
||||
return this.Guid.Equals(other.Guid);
|
||||
}
|
||||
}
|
||||
}
|
31
Demo/Data/LocalData/LocalStaticData.cs
Normal file
31
Demo/Data/LocalData/LocalStaticData.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Data.LocalData
|
||||
{
|
||||
public static class LocalStaticData
|
||||
{
|
||||
public static List<GroupLocalEntity> groups => new List<GroupLocalEntity>
|
||||
|
||||
{
|
||||
new GroupLocalEntity{ Id = 1, Name = "ИП1-21" },
|
||||
new GroupLocalEntity{ Id = 2, Name = "ИП1-22" },
|
||||
new GroupLocalEntity{ Id = 3, Name = "ИП1-23" },
|
||||
};
|
||||
|
||||
public static List<UserLocalEnity> users => new List<UserLocalEnity>
|
||||
{
|
||||
new UserLocalEnity{Guid=Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), FIO = "RandomFio", GroupID = 1 },
|
||||
new UserLocalEnity{Guid=Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), FIO = "RandomFio1", GroupID = 2 },
|
||||
new UserLocalEnity{Guid=Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), FIO = "RandomFio2", GroupID = 3 },
|
||||
new UserLocalEnity{Guid=Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), FIO = "RandomFio3", GroupID = 1 },
|
||||
new UserLocalEnity{Guid=Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), FIO = "RandomFio4", GroupID = 2 },
|
||||
new UserLocalEnity{Guid=Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), FIO = "RandomFio5", GroupID = 3 },
|
||||
};
|
||||
}
|
||||
}
|
40
Demo/Data/Repository/GroupRepositoryImpl.cs
Normal file
40
Demo/Data/Repository/GroupRepositoryImpl.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using Demo.Data.LocalData;
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public class GroupRepositoryImpl : IGroupRepository
|
||||
{
|
||||
public bool AddGroup(GroupLocalEntity newGroup)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<GroupLocalEntity> GetAllGroup()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
|
||||
|
||||
public GroupLocalEntity GetGroupById(int groupID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool RemoveGroupById(int groupID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
18
Demo/Data/Repository/IGroupRepository.cs
Normal file
18
Demo/Data/Repository/IGroupRepository.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public interface IGroupRepository
|
||||
{
|
||||
List<GroupLocalEntity> GetAllGroup();
|
||||
bool RemoveGroupById(int groupID);
|
||||
bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup);
|
||||
GroupLocalEntity GetGroupById(int groupID);
|
||||
bool AddGroup(GroupLocalEntity newGroup);
|
||||
}
|
||||
}
|
47
Demo/Data/Repository/UserRepositoryImpl.cs
Normal file
47
Demo/Data/Repository/UserRepositoryImpl.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using Demo.Data.LocalData;
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public class UserRepositoryImpl
|
||||
{
|
||||
public UserRepositoryImpl() {
|
||||
|
||||
GetAllUsers = LocalStaticData.users;
|
||||
}
|
||||
public List<UserLocalEnity> GetAllUsers
|
||||
{ get; set; }
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
{
|
||||
UserLocalEnity? userLocal = GetAllUsers
|
||||
.Where(x => x.Guid == userGuid).FirstOrDefault();
|
||||
if (userLocal == null) return false;
|
||||
|
||||
return GetAllUsers.Remove(userLocal);
|
||||
}
|
||||
|
||||
public UserLocalEnity? GetUserByGuid(Guid userGuid) {
|
||||
UserLocalEnity? userLocal = GetAllUsers
|
||||
.Where(x => x.Guid == userGuid).FirstOrDefault();
|
||||
if (userLocal == null) return null;
|
||||
|
||||
return userLocal;
|
||||
}
|
||||
|
||||
public UserLocalEnity? UpdateUser(UserLocalEnity userUpdateLocalEnity) {
|
||||
UserLocalEnity? userLocal = GetAllUsers
|
||||
.Where(x => x.Guid == userUpdateLocalEnity.Guid).FirstOrDefault();
|
||||
if (userLocal == null) return null;
|
||||
userLocal.FIO = userUpdateLocalEnity.FIO;
|
||||
userLocal.GroupID = userUpdateLocalEnity.GroupID;
|
||||
return userLocal;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
14
Demo/Domain/Models/Group.cs
Normal file
14
Demo/Domain/Models/Group.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
}
|
||||
}
|
18
Demo/Domain/Models/Presence.cs
Normal file
18
Demo/Domain/Models/Presence.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
{
|
||||
public class Presence
|
||||
{
|
||||
|
||||
public required User User { get; set; }
|
||||
public bool IsAttedance { get; set; } = true;
|
||||
public required DateOnly Date { get; set; }
|
||||
|
||||
public required int LessonNumber { get; set; }
|
||||
}
|
||||
}
|
16
Demo/Domain/Models/User.cs
Normal file
16
Demo/Domain/Models/User.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public required string FIO { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
|
||||
public required Group Group { get; set; }
|
||||
}
|
||||
}
|
64
Demo/Domain/Presence/UseCaseGeneratePresence.cs
Normal file
64
Demo/Domain/Presence/UseCaseGeneratePresence.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using Demo.Data.LocalData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Domain.Presence
|
||||
{
|
||||
|
||||
public class UseCaseGeneratePresence
|
||||
{
|
||||
public List<AttendanceRecord> GenerateDailyAttendance(int firstLesson, int lastLesson, string groupNumber, DateTime currentDate)
|
||||
{
|
||||
List<AttendanceRecord> attendanceRecords = new List<AttendanceRecord>();
|
||||
|
||||
// Проверка на корректность входных данных
|
||||
if (firstLesson < 1 || lastLesson < firstLesson)
|
||||
{
|
||||
throw new ArgumentException("Неверные номера уроков.");
|
||||
}
|
||||
|
||||
for (int lesson = firstLesson; lesson <= lastLesson; lesson++)
|
||||
{
|
||||
attendanceRecords.Add(new AttendanceRecord
|
||||
{
|
||||
LessonNumber = lesson,
|
||||
GroupNumber = groupNumber,
|
||||
Date = currentDate,
|
||||
IsPresent = true
|
||||
});
|
||||
}
|
||||
|
||||
return attendanceRecords;
|
||||
}
|
||||
|
||||
public List<AttendanceRecord> GenerateWeeklyAttendance(int firstLesson, int lastLesson, string groupNumber, DateTime startDate)
|
||||
{
|
||||
List<AttendanceRecord> weeklyAttendanceRecords = new List<AttendanceRecord>();
|
||||
|
||||
// Проверка на корректность входных данных
|
||||
if (firstLesson < 1 || lastLesson < firstLesson)
|
||||
{
|
||||
throw new ArgumentException("Неверные номера уроков.");
|
||||
}
|
||||
|
||||
for (int day = 0; day < 7; day++)
|
||||
{
|
||||
DateTime currentDate = startDate.AddDays(day);
|
||||
weeklyAttendanceRecords.AddRange(GenerateDailyAttendance(firstLesson, lastLesson, groupNumber, currentDate));
|
||||
}
|
||||
|
||||
return weeklyAttendanceRecords;
|
||||
}
|
||||
|
||||
public class AttendanceRecord
|
||||
{
|
||||
public int LessonNumber { get; set; }
|
||||
public string GroupNumber { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public bool IsPresent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
42
Demo/Domain/UseCase/GroupUseCase.cs
Normal file
42
Demo/Domain/UseCase/GroupUseCase.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Demo.Data.LocalData;
|
||||
using Demo.Data.Repository;
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
public class GroupUseCase
|
||||
{
|
||||
private List<GroupLocalEntity> _groups = LocalStaticData.groups; // вывести все группы
|
||||
|
||||
public List<GroupLocalEntity> GetAllGroups() => _groups;
|
||||
|
||||
public void AddGroup(GroupLocalEntity group) //добавить группу
|
||||
{
|
||||
group.Id = _groups.Any() ? _groups.Max(g => g.Id) + 1 : 1;
|
||||
_groups.Add(group);
|
||||
}
|
||||
public void RenameGroup(int groupId, string newName) //переименовать группу
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(newName))
|
||||
{
|
||||
throw new ArgumentException("Новое имя группы не может быть пустым", nameof(newName));
|
||||
}
|
||||
|
||||
var existingGroup = _groups.FirstOrDefault(g => g.Id == groupId);
|
||||
if (existingGroup == null)
|
||||
{
|
||||
throw new KeyNotFoundException($"Группа с ID {groupId} не найдена.");
|
||||
}
|
||||
existingGroup.Name = newName;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
56
Demo/Domain/UseCase/UseCasePresence.cs
Normal file
56
Demo/Domain/UseCase/UseCasePresence.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
public class UseCasePresence
|
||||
{
|
||||
private Dictionary<string, List<DateTime>> attendanceRecords;
|
||||
|
||||
public UseCasePresence()
|
||||
{
|
||||
attendanceRecords = new Dictionary<string, List<DateTime>>();
|
||||
}
|
||||
|
||||
public void MarkAttendance(string group, DateTime date)
|
||||
{
|
||||
if (!attendanceRecords.ContainsKey(group))
|
||||
{
|
||||
attendanceRecords[group] = new List<DateTime>();
|
||||
}
|
||||
attendanceRecords[group].Add(date);
|
||||
}
|
||||
|
||||
public List<DateTime> GetAttendanceByGroup(string group)
|
||||
{
|
||||
if (attendanceRecords.ContainsKey(group))
|
||||
{
|
||||
return attendanceRecords[group];
|
||||
}
|
||||
return new List<DateTime>();
|
||||
}
|
||||
|
||||
public List<DateTime> GetAttendanceByGroupAndDate(string group, DateTime date)
|
||||
{
|
||||
if (attendanceRecords.ContainsKey(group))
|
||||
{
|
||||
return attendanceRecords[group].Where(d => d.Date == date.Date).ToList();
|
||||
}
|
||||
return new List<DateTime>();
|
||||
}
|
||||
|
||||
public void MarkUserAsAbsent(string group, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
if (attendanceRecords.ContainsKey(group))
|
||||
{
|
||||
for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
|
||||
{
|
||||
attendanceRecords[group].Remove(date);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
65
Demo/Domain/UseCase/UserUseCase.cs
Normal file
65
Demo/Domain/UseCase/UserUseCase.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using Demo.Data.Repository;
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
public class UserUseCase
|
||||
{
|
||||
private UserRepositoryImpl _repositoryUserImpl;
|
||||
private GroupRepositoryImpl _repositoryGroupImpl;
|
||||
|
||||
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
|
||||
{
|
||||
_repositoryUserImpl = repositoryImpl;
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
}
|
||||
|
||||
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
|
||||
.Select(it => new Group { Id = it.Id, Name = it.Name }).ToList();
|
||||
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers
|
||||
.Join(_repositoryGroupImpl.GetAllGroups(),
|
||||
user => user.GroupID,
|
||||
group => group.Id,
|
||||
(user, group) =>
|
||||
new User
|
||||
{
|
||||
FIO = user.FIO,
|
||||
Guid = user.Guid,
|
||||
Group = new Group { Id = group.Id, Name = group.Name }
|
||||
}
|
||||
).ToList();
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
{
|
||||
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
||||
}
|
||||
public User UpdateUser(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);
|
||||
if (group == null) throw new Exception("");
|
||||
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
|
||||
}
|
||||
public User FindUserByGuid(Guid userGuid)
|
||||
{
|
||||
Dictionary<Guid, User> users = new Dictionary<Guid, User>();
|
||||
|
||||
if (users.ContainsKey(userGuid))
|
||||
{
|
||||
return users[userGuid];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
10
Demo/Program.cs
Normal file
10
Demo/Program.cs
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.UI;
|
||||
|
||||
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();
|
||||
UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl();
|
||||
UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl);
|
||||
|
||||
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase);
|
44
Demo/UI/GroupConsole.cs
Normal file
44
Demo/UI/GroupConsole.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Demo.domain.Models;
|
||||
using Demo.Domain.UseCase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
public class GroupConsole
|
||||
{
|
||||
|
||||
|
||||
internal class GroupConsoleUI
|
||||
{
|
||||
GroupUseCase _groupUseCase;
|
||||
|
||||
public GroupConsoleUI(GroupUseCase groupUseCase)
|
||||
{
|
||||
_groupUseCase = groupUseCase;
|
||||
}
|
||||
|
||||
|
||||
public void AllGroups()
|
||||
{
|
||||
foreach (var Group in _groupUseCase.GetAllGroups())
|
||||
{
|
||||
Console.WriteLine($"{Group.Id}\t{Group.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateGroup(int groupId, GroupLocalEntity updatedGroup)
|
||||
{
|
||||
if (updatedGroup == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(updatedGroup), "Обновленная группа не может быть null");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
Demo/UI/MainMenu.cs
Normal file
67
Demo/UI/MainMenu.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Demo.Domain.UseCase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
public class MainMenuUI
|
||||
{
|
||||
private UserConsoleUI _userConsoleUI;
|
||||
|
||||
public MainMenuUI(UserUseCase userUseCase)
|
||||
{
|
||||
_userConsoleUI = new UserConsoleUI(userUseCase);
|
||||
DisplayMenu();
|
||||
}
|
||||
|
||||
private void DisplayMenu()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("Главное меню:");
|
||||
Console.WriteLine("1. Показать всех пользователей");
|
||||
Console.WriteLine("2. Удалить пользователя по GUID");
|
||||
Console.WriteLine("0. Выход");
|
||||
|
||||
string choice = Console.ReadLine();
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
case "1":
|
||||
_userConsoleUI.DisplayAllUsers();
|
||||
break;
|
||||
case "2":
|
||||
RemoveUser();
|
||||
break;
|
||||
case "0":
|
||||
return;
|
||||
default:
|
||||
Console.WriteLine("Неверный выбор, попробуйте снова.");
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveUser()
|
||||
{
|
||||
Console.Write("Введите GUID пользователя для удаления: ");
|
||||
string input = Console.ReadLine();
|
||||
|
||||
if (Guid.TryParse(input, out Guid userGuid))
|
||||
{
|
||||
_userConsoleUI.RemoveUserByGuid(userGuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат GUID. Пожалуйста, попробуйте еще раз.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
Demo/UI/PresenceConsole.cs
Normal file
12
Demo/UI/PresenceConsole.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
public class PresenceConsole
|
||||
{
|
||||
}
|
||||
}
|
53
Demo/UI/UserConsole.cs
Normal file
53
Demo/UI/UserConsole.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using Demo.domain.Models;
|
||||
using Demo.Domain.UseCase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
|
||||
public class UserConsoleUI
|
||||
{
|
||||
UserUseCase _userUseCase;
|
||||
public UserConsoleUI(UserUseCase userUseCase)
|
||||
{
|
||||
_userUseCase = userUseCase;
|
||||
}
|
||||
|
||||
public void RemoveUserByGuid(Guid guidUser)
|
||||
{
|
||||
|
||||
string del = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален";
|
||||
Console.WriteLine(del);
|
||||
}
|
||||
|
||||
public void DisplayAllUsers()
|
||||
{
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
foreach (var user in _userUseCase.GetAllUsers())
|
||||
{
|
||||
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.Group.Name}");
|
||||
}
|
||||
Console.WriteLine(userOutput);
|
||||
}
|
||||
|
||||
public void UpdateUserGuid(Guid guidUser)
|
||||
{
|
||||
var user = _userUseCase.FindUserByGuid(guidUser);
|
||||
Console.WriteLine($"Текущие данные: {user.FIO}, {user.Group.Name}");
|
||||
Console.Write("Введите новое ФИО: ");
|
||||
string newFIO = Console.ReadLine();
|
||||
user.FIO = newFIO;
|
||||
_userUseCase.UpdateUser(user);
|
||||
}
|
||||
|
||||
public void GetUserByGuid(Guid guidUser)
|
||||
{
|
||||
var user = _userUseCase.FindUserByGuid(guidUser);
|
||||
Console.WriteLine($"Пользователь найден: {user.Guid}, {user.FIO}, {user.Group.Name}");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user