This commit is contained in:
alex 2024-10-18 16:23:16 +03:00
parent 6012168a59
commit e96bb672bf
14 changed files with 74 additions and 56 deletions

View File

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

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Demo.domain.Models namespace Demo.Domain.Models
{ {
internal class PresenceLocalEntity internal class PresenceLocalEntity
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Demo.domain.Models namespace Demo.Domain.Models
{ {
public class UserLocalEnity : IEquatable<UserLocalEnity> public class UserLocalEnity : IEquatable<UserLocalEnity>
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<Group> _groups = new List<Group>();
private int _nextId;
public IEnumerable<Group> 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;
}
}
}

View File

@ -1,46 +1,44 @@
using Demo.Data.Repository; using Demo.Data.Repository;
using Demo.domain.Models; using Demo.Domain.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Demo.Domain.UseCase
{
public class UserUseCase public class UserUseCase
{ {
private UserRepositoryImpl _repositoryUserImpl; private List<User> _users = new List<User>();
private GroupRepositoryImpl _repositoryGroupImpl; private UserRepositoryImpl userRepositoryImpl;
private GroupRepositoryImpl groupRepositoryImpl;
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) public UserUseCase(UserRepositoryImpl userRepositoryImpl, GroupRepositoryImpl groupRepositoryImpl)
{ {
_repositoryUserImpl = repositoryImpl; this.userRepositoryImpl = userRepositoryImpl;
_repositoryGroupImpl = repositoryGroupImpl; this.groupRepositoryImpl = groupRepositoryImpl;
} }
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups() public IEnumerable<User> GetAllUsers() => _users;
.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) { public User FindUserByGuid(Guid id) => _users.FirstOrDefault(u => u. Guid == id);
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
} public void DeleteUserByGuid(Guid id)
public User UpdateUser(User user) { {
UserLocalEnity userLocalEnity = new UserLocalEnity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid }; var user = _users.FirstOrDefault(u => u.Guid == id);
UserLocalEnity? result = _repositoryUserImpl.UpdateUser(userLocalEnity); if (user != null)
if (result == null) throw new Exception(""); _users.Remove(user);
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 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();
} }
} }

View File

@ -1,6 +1,5 @@
 
using Demo.Data.Repository; using Demo.Data.Repository;
using Demo.Domain.UseCase;
using Demo.UI; using Demo.UI;
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();

View File

@ -1,11 +1,4 @@
using Demo.Domain.UseCase; namespace Demo.UI
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.UI
{ {
public class MainMenuUI public class MainMenuUI
{ {

View File

@ -1,9 +1,4 @@
using Demo.Domain.UseCase; using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.UI namespace Demo.UI
{ {