This commit is contained in:
1billy17 2024-10-17 15:35:14 +03:00
parent eb0d6782ec
commit 7603d4fbad
10 changed files with 121 additions and 28 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -19,11 +19,10 @@ namespace Demo.Data.Repository
public GroupLocalEntity? UpdateGroupName(GroupLocalEntity groupUpdateLocalEntity) {
GroupLocalEntity? groupLocal = GetAllGroups
.Where(x => x.Id == groupUpdateLocalEntity.Id).FirstOrDefault();
if (groupLocal == null) return null;
groupLocal.Name = groupUpdateLocalEntity.Name;
return groupLocal;
int index = GetAllGroups.FindIndex(x => x.Id == groupUpdateLocalEntity.Id);
if (index == -1) return null;
GetAllGroups[index].Name = groupUpdateLocalEntity.Name;
return GetAllGroups[index];
}
public GroupLocalEntity? CreateGroup(GroupLocalEntity groupCreateLocalEntity) {

View File

@ -35,13 +35,11 @@ namespace Demo.Data.Repository
}
public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEntity) {
UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.Guid == userUpdateLocalEntity.Guid).FirstOrDefault();
if (userLocal == null) return null;
userLocal.FIO = userUpdateLocalEntity.FIO;
userLocal.GroupID = userUpdateLocalEntity.GroupID;
return userLocal;
int index = GetAllUsers.FindIndex(x => x.Guid == userUpdateLocalEntity.Guid);
if (index == -1) return null;
GetAllUsers[index].FIO = userUpdateLocalEntity.FIO;
GetAllUsers[index].GroupID = userUpdateLocalEntity.GroupID;
return GetAllUsers[index];
}
}
}

View File

@ -10,5 +10,10 @@ namespace Demo.domain.Models
{
public required int Id { get; set; }
public required string Name { get; set; }
public static Group Parse(string input){
string[] words = input.Split(" ");
return new Group{Id = Convert.ToInt32(words[0]), Name = words[1]};
}
}
}

View File

@ -12,5 +12,11 @@ namespace Demo.domain.Models
public Guid Guid { get; set; }
public required Group Group { get; set; }
public static User Parse(string input){
string[] words = input.Split(" ");
return new User{FIO = words[0], Guid = Guid.Parse(words[1]), Group = new Group{Id = Convert.ToInt32(words[2]), Name = words[3]}};
}
}
}

View File

@ -23,22 +23,30 @@ namespace Demo.Domain.UseCase
public Group UpdateGroupName(Group group) {
GroupLocalEntity? groupLocalEntity = new GroupLocalEntity { Id = group.Id, Name = group.Name };
GroupLocalEntity? updatedGroupEntity = _repositoryGroupImpl.UpdateGroupName(groupLocalEntity);
if (updatedGroupEntity == null) throw new Exception("");
return new Group { Id = updatedGroupEntity.Id, Name = updatedGroupEntity.Name};
GroupLocalEntity groupLocalEntity = new GroupLocalEntity
{
Id = group.Id,
Name = group.Name
};
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroupName(groupLocalEntity);
if (result == null)
{
throw new Exception("");
}
return new Group
{
Id = result.Id,
Name = result.Name
};
}
public Group CreateGroup(Group group) {
public bool CreateGroup(Group group) {
GroupLocalEntity? groupLocalEntity = new GroupLocalEntity{Id = group.Id, Name = group.Name};
GroupLocalEntity? createdGroupEntity = _repositoryGroupImpl.CreateGroup(groupLocalEntity);
if (createdGroupEntity == null) throw new Exception("");
return new Group { Id = createdGroupEntity.Id, Name = createdGroupEntity.Name};
_repositoryGroupImpl.CreateGroup(groupLocalEntity);
if (groupLocalEntity != null) return false;
return true;
}
}
}

View File

@ -8,4 +8,4 @@ UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl();
UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl);
GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl);
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase);
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase);

46
UI/GroupConsole.cs Normal file
View File

@ -0,0 +1,46 @@
using Demo.Domain.UseCase;
using Demo.domain.Models;
using System.Text;
namespace Demo.UI
{
public class GroupConsoleUI
{
GroupUseCase _groupUseCase;
public GroupConsoleUI(GroupUseCase groupUseCase) {
_groupUseCase = groupUseCase;
}
public void UpdateGroupName(Group group)
{
try
{
Group output = _groupUseCase.UpdateGroupName(group);
StringBuilder groupOutput = new StringBuilder();
groupOutput.AppendLine($"Обновленная группа: {output.Id}\t{output.Name}");
Console.WriteLine(groupOutput);
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при обновлении группы: {ex.Message}");
}
}
public void CreateNewGroup(Group group){
string output = _groupUseCase.CreateGroup(group) ? "Пользователь создан" : "Пользователь не создан";
}
public void DisplayAllGroups()
{
StringBuilder groupOutput = new StringBuilder();
foreach (var group in _groupUseCase.GetAllGroups())
{
groupOutput.AppendLine($"{group.Id}\t {group.Name}\t");
}
Console.WriteLine(groupOutput);
}
}
}

View File

@ -1,4 +1,5 @@
using Demo.Domain.UseCase;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,9 +12,11 @@ namespace Demo.UI
{
UserConsoleUI _userConsoleUI;
GroupConsoleUI _groupConsoleUI;
public MainMenuUI(UserUseCase userUseCase) {
public MainMenuUI(UserUseCase userUseCase, GroupUseCase groupUseCase) {
_userConsoleUI = new UserConsoleUI(userUseCase);
_groupConsoleUI = new GroupConsoleUI(groupUseCase);
DisplayMenu();
}
@ -25,6 +28,11 @@ namespace Demo.UI
{
case "1": _userConsoleUI.DisplayAllUsers(); break;
case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
case "3": _userConsoleUI.UpdateUser(User.Parse(Console.ReadLine())); break;
case "4": _userConsoleUI.GetUserByGuid(Guid.Parse(Console.ReadLine())); break;
case "5": _groupConsoleUI.DisplayAllGroups(); break;
case "6": _groupConsoleUI.CreateNewGroup(Group.Parse(Console.ReadLine())); break;
case "7": _groupConsoleUI.UpdateGroupName(Group.Parse(Console.ReadLine())); break;
default: DisplayMenu();
break;

View File

@ -1,4 +1,5 @@
using Demo.Domain.UseCase;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -29,5 +30,27 @@ namespace Demo.UI
}
Console.WriteLine(userOutput);
}
public void UpdateUser(User user)
{
try
{
User output = _userUseCase.UpdateUser(user);
StringBuilder userOutput = new StringBuilder();
userOutput.AppendLine($"Обновленный пользователь: {output.Guid}\t{output.FIO}\t{output.Group.Name}");
Console.WriteLine(userOutput);
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка при обновлении пользователя: {ex.Message}");
}
}
public void GetUserByGuid(Guid guid){
User output = _userUseCase.GetUserByGuid(guid);
StringBuilder userOutput = new StringBuilder();
userOutput.AppendLine($"{output.Guid}\t{output.FIO}\t{output.Group.Name}");
Console.WriteLine(userOutput);
}
}
}