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.Threading.Tasks;
namespace Demo.domain.Models
namespace Demo.Domain.Models
{
public class GroupLocalEntity
{

View File

@ -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
{

View File

@ -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<UserLocalEnity>
{

View File

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

View File

@ -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;

View File

@ -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;

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

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.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
{
private UserRepositoryImpl _repositoryUserImpl;
private GroupRepositoryImpl _repositoryGroupImpl;
private List<User> _users = new List<User>();
private UserRepositoryImpl userRepositoryImpl;
private GroupRepositoryImpl groupRepositoryImpl;
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
public UserUseCase(UserRepositoryImpl userRepositoryImpl, GroupRepositoryImpl groupRepositoryImpl)
{
_repositoryUserImpl = repositoryImpl;
_repositoryGroupImpl = repositoryGroupImpl;
this.userRepositoryImpl = userRepositoryImpl;
this.groupRepositoryImpl = groupRepositoryImpl;
}
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 IEnumerable<User> GetAllUsers() => _users;
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 id) => _users.FirstOrDefault(u => u. Guid == id);
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();
}
}

View File

@ -1,6 +1,5 @@

using Demo.Data.Repository;
using Demo.Domain.UseCase;
using Demo.UI;
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();

View File

@ -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
{

View File

@ -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
{