diff --git a/Demo/Data/LocalData/Entity/Group.cs b/Demo/Data/LocalData/Entity/Group.cs index 6041311..572faae 100644 --- a/Demo/Data/LocalData/Entity/Group.cs +++ b/Demo/Data/LocalData/Entity/Group.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Demo.domain.Models +namespace Demo.Domain.Models { public class GroupLocalEntity { diff --git a/Demo/Data/LocalData/Entity/Presence.cs b/Demo/Data/LocalData/Entity/Presence.cs index 70b8d1e..79cbb6a 100644 --- a/Demo/Data/LocalData/Entity/Presence.cs +++ b/Demo/Data/LocalData/Entity/Presence.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Demo.domain.Models +namespace Demo.Domain.Models { internal class PresenceLocalEntity { diff --git a/Demo/Data/LocalData/Entity/User.cs b/Demo/Data/LocalData/Entity/User.cs index 5af4881..6415232 100644 --- a/Demo/Data/LocalData/Entity/User.cs +++ b/Demo/Data/LocalData/Entity/User.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Demo.domain.Models +namespace Demo.Domain.Models { public class UserLocalEnity : IEquatable { diff --git a/Demo/Data/LocalData/LocalStaticData.cs b/Demo/Data/LocalData/LocalStaticData.cs index 50e54f7..058fc25 100644 --- a/Demo/Data/LocalData/LocalStaticData.cs +++ b/Demo/Data/LocalData/LocalStaticData.cs @@ -1,4 +1,4 @@ -using Demo.domain.Models; +using Demo.Domain.Models; using System; using System.Collections.Generic; using System.Linq; diff --git a/Demo/Data/Repository/GroupRepositoryImpl.cs b/Demo/Data/Repository/GroupRepositoryImpl.cs index e5b9a29..a21ae9f 100644 --- a/Demo/Data/Repository/GroupRepositoryImpl.cs +++ b/Demo/Data/Repository/GroupRepositoryImpl.cs @@ -1,5 +1,5 @@ using Demo.Data.LocalData; -using Demo.domain.Models; +using Demo.Domain.Models; using System; using System.Collections.Generic; using System.Linq; diff --git a/Demo/Data/Repository/UserRepositoryImpl.cs b/Demo/Data/Repository/UserRepositoryImpl.cs index bf9ae8c..48adfb2 100644 --- a/Demo/Data/Repository/UserRepositoryImpl.cs +++ b/Demo/Data/Repository/UserRepositoryImpl.cs @@ -1,5 +1,5 @@ using Demo.Data.LocalData; -using Demo.domain.Models; +using Demo.Domain.Models; using System; using System.Collections.Generic; using System.Linq; diff --git a/Demo/Domain/Models/Group.cs b/Demo/Domain/Models/Group.cs index ce0914b..90e02ff 100644 --- a/Demo/Domain/Models/Group.cs +++ b/Demo/Domain/Models/Group.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Demo.domain.Models +namespace Demo.Domain.Models { public class Group { diff --git a/Demo/Domain/Models/Presence.cs b/Demo/Domain/Models/Presence.cs index a5fe7a0..127cc34 100644 --- a/Demo/Domain/Models/Presence.cs +++ b/Demo/Domain/Models/Presence.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Demo.domain.Models +namespace Demo.Domain.Models { public class Presence { diff --git a/Demo/Domain/Models/User.cs b/Demo/Domain/Models/User.cs index cffca41..c0fef3a 100644 --- a/Demo/Domain/Models/User.cs +++ b/Demo/Domain/Models/User.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Demo.domain.Models +namespace Demo.Domain.Models { public class User { diff --git a/Demo/Domain/UseCase/GroupUseCase.cs b/Demo/Domain/UseCase/GroupUseCase.cs new file mode 100644 index 0000000..a572fea --- /dev/null +++ b/Demo/Domain/UseCase/GroupUseCase.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Demo.Domain.Models; + +namespace Demo.Domain.UseCase +{ + + + + public class GroupUseCase + { + private List _groups = new List(); + private int _nextId; + + public IEnumerable GetAllGroups() => _groups; + + public void AddGroup(string name) + { + _groups.Add(new Group { Id = _nextId++, Name = name }); + } + + public void UpdateGroupName(Guid id, string newName, bool Id) + { + var group = _groups.FirstOrDefault(g => Id); + if (group != null) + group.Name = newName; + } + } + +} diff --git a/Demo/Domain/UseCase/UserUseCase.cs b/Demo/Domain/UseCase/UserUseCase.cs index f1f44e1..08b7e40 100644 --- a/Demo/Domain/UseCase/UserUseCase.cs +++ b/Demo/Domain/UseCase/UserUseCase.cs @@ -1,46 +1,44 @@ using Demo.Data.Repository; -using Demo.domain.Models; +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 { - public class UserUseCase + private List _users = new List(); + private UserRepositoryImpl userRepositoryImpl; + private GroupRepositoryImpl groupRepositoryImpl; + + public UserUseCase(UserRepositoryImpl userRepositoryImpl, GroupRepositoryImpl groupRepositoryImpl) { - private UserRepositoryImpl _repositoryUserImpl; - private GroupRepositoryImpl _repositoryGroupImpl; + this.userRepositoryImpl = userRepositoryImpl; + this.groupRepositoryImpl = groupRepositoryImpl; + } - public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) - { - _repositoryUserImpl = repositoryImpl; - _repositoryGroupImpl = repositoryGroupImpl; - } + public IEnumerable GetAllUsers() => _users; - public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() - .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); - public List 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 User FindUserByGuid(Guid id) => _users.FirstOrDefault(u => u. Guid == id); - 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 void DeleteUserByGuid(Guid id) + { + var user = _users.FirstOrDefault(u => u.Guid == id); + if (user != null) + _users.Remove(user); + } + + public void UpdateUserByGuid(Guid id, string newName) + { + var user = _users.FirstOrDefault(u => u.Guid == id); + if (user != null) + user.FIO = newName; + } + + internal bool RemoveUserByGuid(Guid guidUser) + { + throw new NotImplementedException(); } } diff --git a/Demo/Program.cs b/Demo/Program.cs index 9ebb621..c3ff9b0 100644 --- a/Demo/Program.cs +++ b/Demo/Program.cs @@ -1,6 +1,5 @@  using Demo.Data.Repository; -using Demo.Domain.UseCase; using Demo.UI; GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); diff --git a/Demo/UI/MainMenu.cs b/Demo/UI/MainMenu.cs index ce13884..d886091 100644 --- a/Demo/UI/MainMenu.cs +++ b/Demo/UI/MainMenu.cs @@ -1,11 +1,4 @@ -using Demo.Domain.UseCase; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Demo.UI +namespace Demo.UI { public class MainMenuUI { diff --git a/Demo/UI/UserConsole.cs b/Demo/UI/UserConsole.cs index 15ec296..605db10 100644 --- a/Demo/UI/UserConsole.cs +++ b/Demo/UI/UserConsole.cs @@ -1,9 +1,4 @@ -using Demo.Domain.UseCase; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Text; namespace Demo.UI {