Добавьте файлы проекта.
This commit is contained in:
parent
40b40bfb0c
commit
120f2c3b16
25
123.sln
Normal file
25
123.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", "123\Demo.csproj", "{5A6EDB7C-E5C5-4FCD-B6CE-7E131BD9EDA3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5A6EDB7C-E5C5-4FCD-B6CE-7E131BD9EDA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5A6EDB7C-E5C5-4FCD-B6CE-7E131BD9EDA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5A6EDB7C-E5C5-4FCD-B6CE-7E131BD9EDA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5A6EDB7C-E5C5-4FCD-B6CE-7E131BD9EDA3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {B3D7FA9B-E7AA-4A2B-8D13-416D51577CB6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
14
123/Data/LocalData/Entity/Group.cs
Normal file
14
123/Data/LocalData/Entity/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 _123.Data.LocalData.Entity
|
||||
{
|
||||
public class GroupLocalEntity
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public required string Name { get; set; }
|
||||
}
|
||||
}
|
17
123/Data/LocalData/Entity/Presence.cs
Normal file
17
123/Data/LocalData/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 _123.Data.LocalData.Entity
|
||||
{
|
||||
public 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; }
|
||||
}
|
||||
}
|
21
123/Data/LocalData/Entity/User.cs
Normal file
21
123/Data/LocalData/Entity/User.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.Data.LocalData.Entity
|
||||
{
|
||||
public class UserLocalEntity : IEquatable<UserLocalEntity>
|
||||
{
|
||||
public required string UserFIO { get; set; }
|
||||
public Guid UserGuid { get; set; }
|
||||
|
||||
public required int GroupID { get; set; }
|
||||
public bool Equals(UserLocalEntity? other)
|
||||
{
|
||||
if (other == null) return false;
|
||||
return this.UserGuid.Equals(other.UserGuid);
|
||||
}
|
||||
}
|
||||
}
|
32
123/Data/LocalData/LocalStaticData.cs
Normal file
32
123/Data/LocalData/LocalStaticData.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using _123.Data.LocalData.Entity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.Data.LocalData
|
||||
{
|
||||
public 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<UserLocalEntity> users => new List<UserLocalEntity>
|
||||
{
|
||||
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio", GroupID = 1 },
|
||||
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio1", GroupID = 2 },
|
||||
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio2", GroupID = 3 },
|
||||
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio3", GroupID = 1 },
|
||||
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio4", GroupID = 2 },
|
||||
new UserLocalEntity{UserGuid=Guid.NewGuid(), UserFIO = "RandomFio5", GroupID = 3 },
|
||||
};
|
||||
public static List<PresenceLocalEntity> presences => new List<PresenceLocalEntity>
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
}
|
26
123/Data/ReportsHistory/GroupRepositoty.cs
Normal file
26
123/Data/ReportsHistory/GroupRepositoty.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using _123.Data.LocalData.Entity;
|
||||
using _123.Data.LocalData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.Data.ReportsHistory
|
||||
{
|
||||
|
||||
public class GroupRepositoryImpl
|
||||
{
|
||||
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
|
||||
|
||||
public GroupLocalEntity? UpdateGroup(GroupLocalEntity groupUpdateLocalEntity)
|
||||
{
|
||||
GroupLocalEntity? groupLocal = GetAllGroups()
|
||||
.Where(x => x.ID == groupUpdateLocalEntity.ID).FirstOrDefault();
|
||||
if (groupLocal == null) return null;
|
||||
groupLocal.ID = groupUpdateLocalEntity.ID;
|
||||
groupLocal.Name = groupUpdateLocalEntity.Name;
|
||||
return groupLocal;
|
||||
}
|
||||
}
|
||||
}
|
51
123/Data/ReportsHistory/UserRepositoty.cs
Normal file
51
123/Data/ReportsHistory/UserRepositoty.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using _123.Data.LocalData;
|
||||
using _123.Data.LocalData.Entity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace _123.Data.ReportsHistory
|
||||
{
|
||||
public class UserRepositoryImpl
|
||||
{
|
||||
public UserRepositoryImpl()
|
||||
{
|
||||
|
||||
GetAllUsers = LocalStaticData.users;
|
||||
}
|
||||
public List<UserLocalEntity> GetAllUsers
|
||||
{ get; set; }
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
{
|
||||
UserLocalEntity? userLocal = GetAllUsers
|
||||
.Where(x => x.UserGuid == userGuid).FirstOrDefault();
|
||||
if (userLocal == null) return false;
|
||||
|
||||
return GetAllUsers.Remove(userLocal);
|
||||
}
|
||||
|
||||
public UserLocalEntity? GetUserByGuid(Guid userGuid)
|
||||
{
|
||||
UserLocalEntity? userLocal = GetAllUsers
|
||||
.Where(x => x.UserGuid == userGuid).FirstOrDefault();
|
||||
if (userLocal == null) return null;
|
||||
|
||||
return userLocal;
|
||||
}
|
||||
|
||||
public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity)
|
||||
{
|
||||
UserLocalEntity? userLocal = GetAllUsers
|
||||
.Where(x => x.UserGuid == userUpdateLocalEnity.UserGuid).FirstOrDefault();
|
||||
if (userLocal == null) return null;
|
||||
userLocal.UserFIO = userUpdateLocalEnity.UserFIO;
|
||||
userLocal.GroupID = userUpdateLocalEnity.GroupID;
|
||||
return userLocal;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
15
123/Demo.csproj
Normal file
15
123/Demo.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>_123</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Data\RemoteData\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
14
123/Domain/Models/Group.cs
Normal file
14
123/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 _123.Domain.Models
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public required string Name { get; set; }
|
||||
}
|
||||
}
|
16
123/Domain/Models/Presence.cs
Normal file
16
123/Domain/Models/Presence.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.Domain.Models
|
||||
{
|
||||
public class Presence
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
public int ClassNum { get; set; }
|
||||
public bool IsAttedance { get; set; }
|
||||
public required User User { get; set; }
|
||||
}
|
||||
}
|
16
123/Domain/Models/User.cs
Normal file
16
123/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 _123.Domain.Models
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public required string UserFIO { get; set; }
|
||||
public Guid UserGuid { get; set; }
|
||||
|
||||
public required Group UserGroup { get; set; }
|
||||
}
|
||||
}
|
33
123/Domain/UseCase/GroupUseCase.cs
Normal file
33
123/Domain/UseCase/GroupUseCase.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using _123.Data.ReportsHistory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using _123.Domain.Models;
|
||||
using _123.Data.LocalData.Entity;
|
||||
|
||||
namespace _123.Domain.UseCase
|
||||
{
|
||||
public class GroupUseCase
|
||||
{
|
||||
private GroupRepositoryImpl _repositoryGroupImpl;
|
||||
public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl)
|
||||
{
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
}
|
||||
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
|
||||
.Select(it => new Group { ID = it.ID, Name = it.Name }).ToList();
|
||||
|
||||
public Group UpdateGroupName(Group grou)
|
||||
{
|
||||
GroupLocalEntity groupLocalEntity = new GroupLocalEntity { ID = grou.ID, Name = grou.Name };
|
||||
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity);
|
||||
if (result == null) throw new Exception("");
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => it.ID == result!.ID);
|
||||
if (group == null) throw new Exception("");
|
||||
return new Group { ID = group.ID, Name = group.Name };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
53
123/Domain/UseCase/UserUseCase.cs
Normal file
53
123/Domain/UseCase/UserUseCase.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using _123.Data.LocalData.Entity;
|
||||
using _123.Data.ReportsHistory;
|
||||
using _123.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.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
|
||||
{
|
||||
UserFIO = user.UserFIO,
|
||||
UserGuid = user.UserGuid,
|
||||
UserGroup = new Group { ID = group.ID, Name = group.Name }
|
||||
}
|
||||
).ToList();
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
{
|
||||
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
||||
}
|
||||
public User UpdateUser(User user)
|
||||
{
|
||||
UserLocalEntity userLocalEnity = new UserLocalEntity { UserFIO = user.UserFIO, GroupID = user.UserGroup.ID, UserGuid = user.UserGuid };
|
||||
UserLocalEntity? 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 { UserFIO = user.UserFIO, UserGuid = user.UserGuid, UserGroup = group };
|
||||
}
|
||||
|
||||
}
|
||||
}
|
10
123/Program.cs
Normal file
10
123/Program.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using _123.Data.ReportsHistory;
|
||||
using _123.Domain.UseCase;
|
||||
using _123.UI;
|
||||
|
||||
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();
|
||||
UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl();
|
||||
UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl);
|
||||
GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl);
|
||||
|
||||
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase);
|
26
123/UI/GroupConsole.cs
Normal file
26
123/UI/GroupConsole.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using _123.Domain.UseCase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace _123.UI
|
||||
{
|
||||
public class GroupConsoleUI
|
||||
{
|
||||
GroupUseCase _groupUseCase;
|
||||
public GroupConsoleUI(GroupUseCase groupUseCase)
|
||||
{
|
||||
_groupUseCase = groupUseCase;
|
||||
}
|
||||
public void DisplayAllGroups()
|
||||
{
|
||||
StringBuilder groupOutput = new StringBuilder();
|
||||
foreach (var group in _groupUseCase.GetAllGroups())
|
||||
{
|
||||
groupOutput.AppendLine($"{group.ID}\t{group.Name}");
|
||||
}
|
||||
Console.WriteLine(groupOutput);
|
||||
}
|
||||
}
|
||||
}
|
45
123/UI/MainMenu.cs
Normal file
45
123/UI/MainMenu.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using _123.Domain.UseCase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.UI
|
||||
{
|
||||
public class MainMenuUI
|
||||
{
|
||||
|
||||
UserConsoleUI _userConsoleUI;
|
||||
|
||||
GroupConsoleUI _groupConsoleUI;
|
||||
|
||||
public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase)
|
||||
{
|
||||
_userConsoleUI = new UserConsoleUI(userUseCase);
|
||||
_groupConsoleUI = new GroupConsoleUI(groupUseCase);
|
||||
|
||||
DisplayMenu();
|
||||
|
||||
}
|
||||
|
||||
private void DisplayMenu()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
switch (Console.ReadLine())
|
||||
{
|
||||
case "1": _userConsoleUI.DisplayAllUsers(); break;
|
||||
case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
|
||||
case "3": _groupConsoleUI.DisplayAllGroups(); break;
|
||||
|
||||
default:
|
||||
DisplayMenu();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
36
123/UI/UserConsole.cs
Normal file
36
123/UI/UserConsole.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using _123.Domain.UseCase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _123.UI
|
||||
{
|
||||
public class UserConsoleUI
|
||||
{
|
||||
UserUseCase _userUseCase;
|
||||
public UserConsoleUI(UserUseCase userUseCase)
|
||||
{
|
||||
_userUseCase = userUseCase;
|
||||
}
|
||||
|
||||
public void RemoveUserByGuid(Guid guidUser)
|
||||
{
|
||||
|
||||
string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void DisplayAllUsers()
|
||||
{
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
foreach (var user in _userUseCase.GetAllUsers())
|
||||
{
|
||||
userOutput.AppendLine($"{user.UserGuid}\t{user.UserFIO}\t{user.UserGroup.Name}");
|
||||
}
|
||||
Console.WriteLine(userOutput);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user