changed to sqlrepositories

This commit is contained in:
Dasha06 2024-11-06 07:10:09 +03:00
parent 0705829116
commit bc674c9649
19 changed files with 281 additions and 205 deletions

View File

@ -7,7 +7,7 @@ namespace Posechaemost.Data.RemoteData.RemoteDataBase.DAO
{
public class GroupDao
{
public required int Id {get; set;}
public int Id {get; set;}
public required string Name {get; set;}
public IEnumerable<UserDao> Users {get; set;}

View File

@ -10,6 +10,8 @@ namespace Posechaemost.Data.RemoteData.RemoteDataBase.DAO
public required DateOnly Date {get; set;}
public int ClassNumber {get; set;}
public bool IsAttendence {get; set;} = true;
public int UserId {get; set;}
public required UserDao User {get; set;}
public int GroupId {get; set;}
}
}

View File

@ -8,7 +8,9 @@ namespace Posechaemost.Data.RemoteData.RemoteDataBase.DAO
public class UserDao
{
public required string FIO {get; set; }
public Guid Guid {get; set;}
public required GroupDao Group {get; set;}
public int UserId { get; set; }
public required int GroupId {get; set;}
public GroupDao Group {get; set;}
}
}

View File

@ -10,15 +10,15 @@ namespace Posechaemost.Data.RemoteData.RemoteDataBase
public class RemoteDataBaseContext: DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder){
optionsBuilder.UseNpgsql();
optionsBuilder.UseNpgsql("Host=localhost; Database=presencedb; Username=postgres; Password=123");
}
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.Entity<GroupDao>().HasKey(group => group.Id);
modelBuilder.Entity<GroupDao>().Property(group => group.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<UserDao>().HasKey(user => user.Guid);
modelBuilder.Entity<UserDao>().Property(user => user.Guid).ValueGeneratedOnAdd();
modelBuilder.Entity<UserDao>().HasKey(user => user.UserId);
modelBuilder.Entity<UserDao>().Property(user => user.UserId).ValueGeneratedOnAdd();
modelBuilder.Entity<PresenceDao>().HasKey(presence => new {
presence.User,
presence.Date,
@ -28,8 +28,8 @@ namespace Posechaemost.Data.RemoteData.RemoteDataBase
}
public DbSet<GroupDao> groups{ get; set; }
public DbSet<UserDao> users{ get; set; }
public DbSet<PresenceDao> presences{ get; set; }
public DbSet<GroupDao> Groups{ get; set; }
public DbSet<UserDao> Users{ get; set; }
public DbSet<PresenceDao> Presences{ get; set; }
}
}

View File

@ -1,77 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Posechaemost.Data.LocalData;
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Data.RemoteData.RemoteDataBase;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
namespace Posechaemost.Data.Repository
{
public class GroupRepositoryImpl: IGroupRepository
public class SQLGroupRepositoryImpl : IGroupRepository
{
private readonly RemoteDataBaseContext _remoteDatabaseContext;
public bool AddGroup(String name, String id)
public SQLGroupRepositoryImpl(RemoteDataBaseContext remoteDatabaseContext)
{
GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault();
// GroupLocalEntity? group = new GroupLocalEntity();
groupLocal.Name = name;
groupLocal.Id = int.Parse(id);
return true;
}
public List<GroupLocalEntity> GetAllGroup()
{
return GetAllGroups();
_remoteDatabaseContext = remoteDatabaseContext;
}
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public GroupLocalEntity GetGroupById(int groupID)
public bool AddGroup(GroupDao group)
{
GroupLocalEntity groupLocal = GetAllGroups()
.Where(x => x.Id == groupID).FirstOrDefault();
var groupDao = new GroupDao
{
Name = group.Name
};
_remoteDatabaseContext.Groups.Add(groupDao);
_remoteDatabaseContext.SaveChanges();
return true;
}
public List<GroupDao> GetAllGroup()
{
return _remoteDatabaseContext.Groups
.Include(g => g.Users)
.Select(g => new GroupDao
{
Name = g.Name,
Id = g.Id,
Users = g.Users.Select(u => new UserDao
{
UserId = u.UserId,
FIO = u.FIO,
GroupId = u.GroupId,
}).ToList()
}).ToList();
}
public GroupDao GetGroupById(int groupID)
{
var groupLocal = _remoteDatabaseContext.Groups
.Where(g => g.Id == groupID).FirstOrDefault();
if (groupLocal == null) return null;
return groupLocal;
}
public bool RemoveGroupById(int groupID){
GroupLocalEntity? groupLocal = GetAllGroups()
public bool RemoveGroupById(int groupID)
{
var groupLocal = _remoteDatabaseContext.Groups
.Where(x => x.Id == groupID).FirstOrDefault();
if (groupLocal == null) return false;
return GetAllGroups().Remove(groupLocal);
_remoteDatabaseContext.Groups.Remove(groupLocal);
_remoteDatabaseContext.SaveChanges();
return true;
}
public bool UpdateGroupById(int groupID, String name)
public bool UpdateGroupById(int groupID, string name)
{
GroupLocalEntity? groupLocal = GetAllGroups()
var groupLocal = _remoteDatabaseContext.Groups
.Include(g => g.Users)
.Where(x => x.Id == groupID).FirstOrDefault();
if (groupLocal == null) return false;
groupLocal.Name = name;
groupLocal.Users = _remoteDatabaseContext.Users
.Where(x => x.GroupId == groupLocal.Id)
.Select(user => new UserDao
{
UserId = user.UserId,
FIO = user.FIO,
GroupId = user.GroupId
}).ToList();
_remoteDatabaseContext.SaveChanges();
return true;
}
}
}
// {
// public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
// public GroupLocalEntity? UpdateGroup(String name)
// {
// GroupLocalEntity? groupLocal = GetAllGroups()
// .Where(x => x.Name == name).FirstOrDefault();
// if (groupLocal == null) return null;
// groupLocal.Name = name;
// return groupLocal;
// }
// public GroupLocalEntity? AddGroup(String name, String id)
// {
// GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault();
// // GroupLocalEntity? group = new GroupLocalEntity(name, id);
// groupLocal.Name = name;
// groupLocal.Id = int.Parse(id);
// return groupLocal;
// }
// }

View File

@ -4,15 +4,16 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
namespace Posechaemost.Data.Repository {
public interface IGroupRepository
{
List<GroupLocalEntity> GetAllGroup();
List<GroupDao> GetAllGroup();
bool RemoveGroupById(int groupID);
bool UpdateGroupById(int groupID, String name);
GroupLocalEntity GetGroupById(int groupID);
bool AddGroup(String name, String id);
GroupDao GetGroupById(int groupID);
bool AddGroup(GroupDao group);
List<GroupLocalEntity> GetAllGroups();
}
}

View File

@ -3,16 +3,17 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
using Posechaemost.Domain.Models;
namespace Posechaemost.Data.Repository
{
public interface IPresenceRepository
{
List<PresenceLocalEntity> GetPresenceByGroup(int groupId);
List<PresenceLocalEntity> GetPresenceByGroupAndDate(int groupId, DateOnly date);
bool UncheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid);
void AddPresence(PresenceLocalEntity presence);
List<PresenceDao> GetPresenceByGroup(int groupId);
List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date);
bool UncheckAttendence(int firstClass, int lastClass, DateOnly date, int userId);
bool AddPresence(PresenceDao presence);
}
}

View File

@ -4,14 +4,15 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
namespace Posechaemost.Data.Repository {
public interface IUserRepository
{
List<UserLocalEntity> GetAllUser();
bool RemoveUserByGuid(Guid userGuid);
UserLocalEntity? GetUserByGuid(Guid userGuid);
UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity);
UserLocalEntity? UpdateUserByGuid(Guid userGuid);
List<UserDao> GetAllUser();
bool RemoveUserById(int usesId);
UserDao GetUserById(int userId);
bool UpdateUser(UserDao userUpdate);
bool UpdateUserById(int userId, string fio, int groupId);
}
}

View File

@ -2,49 +2,62 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Posechaemost.Data.LocalData;
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Data.RemoteData.RemoteDataBase;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
using Posechaemost.Domain.Models;
namespace Posechaemost.Data.Repository
{
public class PresenceRepositoryImpl: IPresenceRepository
public class SQLPresenceRepositoryImpl: IPresenceRepository
{
public PresenceRepositoryImpl() {
GetAllPresences = LocalStaticData.presences;
}
public List<PresenceLocalEntity> GetAllPresences
{ get; set; }
private readonly RemoteDataBaseContext _remoteDatabaseContext;
public void AddPresence(PresenceLocalEntity presence)
public SQLPresenceRepositoryImpl(RemoteDataBaseContext remoteDatabaseContext)
{
PresenceLocalEntity? presenceLocal = GetAllPresences.FirstOrDefault();
// GroupLocalEntity? group = new GroupLocalEntity();
presenceLocal.ClassNumber = presence.ClassNumber;
presence.UserGuid = presence.UserGuid;
presenceLocal.Date = presence.Date;
presenceLocal.IsAttendence = presence.IsAttendence;
_remoteDatabaseContext = remoteDatabaseContext;
}
public List<PresenceLocalEntity> GetPresenceByGroup(int groupId)
public bool AddPresence(PresenceDao presence)
{
return GetAllPresences;
var presenceDao = new PresenceDao
{
Date = presence.Date,
ClassNumber = presence.ClassNumber,
UserId = presence.UserId,
User = presence.User
};
_remoteDatabaseContext.Presences.Add(presenceDao);
_remoteDatabaseContext.SaveChanges();
return true;
}
public List<PresenceLocalEntity> GetPresenceByGroupAndDate(int groupId, DateOnly date)
public List<PresenceDao> GetPresenceByGroup(int groupId)
{
return GetAllPresences;
var listPresences = _remoteDatabaseContext.Presences
.Where(x => x.GroupId == groupId).ToList();
return listPresences;
}
public bool UncheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid)
public List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date)
{
var presToUpdate = GetAllPresences
.Where(x => x.UserGuid == userGuid && x.ClassNumber >= firstClass
var listPresences = _remoteDatabaseContext.Presences
.Where(x => x.GroupId == groupId && x.Date == date).ToList();
return listPresences;
}
public bool UncheckAttendence(int firstClass, int lastClass, DateOnly date, int userId)
{
var presToUpdate = _remoteDatabaseContext.Presences
.Where(x => x.UserId == userId && x.ClassNumber >= firstClass
&& x.ClassNumber <= lastClass && x.Date == date).ToList();
foreach (var pres in presToUpdate) {
pres.IsAttendence = false;
}
_remoteDatabaseContext.SaveChanges();
return true;
}
}

View File

@ -3,58 +3,73 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Posechaemost.Data.LocalData;
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Data.RemoteData.RemoteDataBase;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
namespace Posechaemost.Data.Repository
{
public class UserRepositoryImpl: IUserRepository
public class SQLUserRepositoryImpl: IUserRepository
{
public UserRepositoryImpl() {
GetAllUsers = LocalStaticData.users;
private readonly RemoteDataBaseContext _remoteDatabaseContext;
public SQLUserRepositoryImpl(RemoteDataBaseContext remoteDatabaseContext)
{
_remoteDatabaseContext = remoteDatabaseContext;
}
public List<UserLocalEntity> GetAllUser()
public List<UserDao> GetAllUser()
{
return GetAllUsers;
return _remoteDatabaseContext.Users.Select(u => new UserDao
{
FIO = u.FIO,
UserId = u.UserId,
GroupId = u.GroupId
}).ToList();
}
public List<UserLocalEntity> GetAllUsers
{ get; set; }
public bool RemoveUserByGuid(Guid userGuid)
public bool RemoveUserById(int userId)
{
UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.Guid == userGuid).FirstOrDefault();
var userLocal = _remoteDatabaseContext.Users
.Where(x => x.UserId== userId).FirstOrDefault();
if (userLocal == null) return false;
return GetAllUsers.Remove(userLocal);
_remoteDatabaseContext.Users.Remove(userLocal);
_remoteDatabaseContext.SaveChanges();
return true;
}
public UserLocalEntity? GetUserByGuid(Guid userGuid) {
UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.Guid == userGuid).FirstOrDefault();
public UserDao GetUserById (int userId) {
var userLocal = _remoteDatabaseContext.Users
.Where(x => x.UserId == userId).FirstOrDefault();
if (userLocal == null) return null;
return userLocal;
}
public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity) {
UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.Guid == userUpdateLocalEnity.Guid).FirstOrDefault();
if (userLocal == null) return null;
userLocal.FIO = userUpdateLocalEnity.FIO;
userLocal.GroupID = userUpdateLocalEnity.GroupID;
return userLocal;
public bool UpdateUser(UserDao userUpdate) {
var userLocal = _remoteDatabaseContext.Users
.Where(x => x.UserId == userUpdate.UserId).FirstOrDefault();
if (userLocal == null) return false;
userLocal.FIO = userUpdate.FIO;
userLocal.GroupId = userUpdate.GroupId;
_remoteDatabaseContext.SaveChanges();
return true;
}
public UserLocalEntity? UpdateUserByGuid(Guid userGuid) {
UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.Guid == userGuid).FirstOrDefault();
if (userLocal == null) return null;
return userLocal;
public bool UpdateUserById(int userId, string fio, int groupId) {
var userLocal = _remoteDatabaseContext.Users
.Where(x => x.UserId == userId).FirstOrDefault();
if (userLocal == null) return false;
userLocal.FIO = fio;
userLocal.GroupId = groupId;
_remoteDatabaseContext.SaveChanges();
return true;
}
}
}

View File

@ -1,4 +1,5 @@
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
using Posechaemost.Data.Repository;
using Posechaemost.Domain.Models;
using System;
@ -11,22 +12,22 @@ namespace Posechaemost.Domain.UseCase
{
public class GroupUseCase
{
private GroupRepositoryImpl _repositoryGroupImpl;
private SQLGroupRepositoryImpl _repositoryGroupImpl;
public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl)
public GroupUseCase(SQLGroupRepositoryImpl repositoryGroupImpl)
{
_repositoryGroupImpl = repositoryGroupImpl;
}
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
public List<GroupDao> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new GroupDao { Id = it.Id, Name = it.Name}).ToList();
public bool UpdateGroupName(String id, String name1) {
return _repositoryGroupImpl.UpdateGroupById(int.Parse(id), name1);
}
public bool AddGroup(String name, String id)
{
return _repositoryGroupImpl.AddGroup(name, id);
return _repositoryGroupImpl.AddGroup(new GroupDao { Name = name, Id = int.Parse(id) });
}
}
}

View File

@ -5,6 +5,7 @@ using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
using Posechaemost.Data.Repository;
using Posechaemost.Domain.Models;
@ -12,29 +13,28 @@ namespace Posechaemost.Domain.UseCase
{
public class PresenceUseCase
{
private readonly PresenceRepositoryImpl _repositoryPresenceImpl;
private readonly UserRepositoryImpl _repositoryUserImpl;
private readonly GroupRepositoryImpl _repositoryGroupImpl;
private readonly SQLPresenceRepositoryImpl _repositoryPresenceImpl;
private readonly SQLUserRepositoryImpl _repositoryUserImpl;
private readonly SQLGroupRepositoryImpl _repositoryGroupImpl;
public PresenceUseCase(PresenceRepositoryImpl repositoryImpl, UserRepositoryImpl userRepositoryImpl, GroupRepositoryImpl groupRepositoryImpl) {
public PresenceUseCase(SQLPresenceRepositoryImpl repositoryImpl,
SQLUserRepositoryImpl userRepositoryImpl,
SQLGroupRepositoryImpl groupRepositoryImpl) {
_repositoryPresenceImpl = repositoryImpl;
_repositoryUserImpl = userRepositoryImpl;
_repositoryGroupImpl = groupRepositoryImpl;
}
public List<Presence> GetPresenceByGroup(int groupId) {
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList();
public List<PresenceDao> GetPresenceByGroup(int groupId) {
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupId == groupId).ToList();
var presenceByGroup = _repositoryPresenceImpl.GetPresenceByGroup(groupId)
.Where(x => users.Any(user => user.Guid == x.UserGuid))
.Select(presence => new Presence{
User = new User{
Guid = presence.UserGuid,
GroupId = new Group{
Id = groupId,
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name
},
FIO = users.First(user => user.Guid == presence.UserGuid).FIO,
.Where(x => users.Any(user => user.UserId == x.UserId))
.Select(presence => new PresenceDao{
User = new UserDao{
UserId = presence.UserId,
GroupId = groupId,
FIO = users.First(user => user.UserId == presence.UserId).FIO,
},
ClassNumber = presence.ClassNumber,
Date = presence.Date,
@ -43,19 +43,16 @@ namespace Posechaemost.Domain.UseCase
return presenceByGroup;
}
public List<Presence> GetPresenceByGroupAndDate(int groupId, DateOnly date) {
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupId).ToList();
public List<PresenceDao> GetPresenceByGroupAndDate(int groupId, DateOnly date) {
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupId == groupId).ToList();
var presenceByGroupAndDate = _repositoryPresenceImpl.GetPresenceByGroupAndDate(groupId, date)
.Where(x => users.Any(user => user.Guid == x.UserGuid && x.Date == date))
.Select(presence => new Presence{
User = new User{
Guid = presence.UserGuid,
GroupId = new Group{
Id = groupId,
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name
},
FIO = users.First(user => user.Guid == presence.UserGuid).FIO,
.Where(x => users.Any(user => user.UserId == x.UserId && x.Date == date))
.Select(presence => new PresenceDao{
User = new UserDao{
UserId = presence.UserId,
GroupId = groupId,
FIO = users.First(user => user.UserId == presence.UserId).FIO,
},
ClassNumber = presence.ClassNumber,
Date = presence.Date,
@ -64,17 +61,19 @@ namespace Posechaemost.Domain.UseCase
return presenceByGroupAndDate;
}
public bool UncheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid) {
return _repositoryPresenceImpl.UncheckAttendence(firstClass, lastClass, date, userGuid);
public bool UncheckAttendence(int firstClass, int lastClass, DateOnly date, int userId) {
return _repositoryPresenceImpl.UncheckAttendence(firstClass, lastClass, date, userId);
}
public void AddPresence(int firstClass, int lastClass, int groupId,DateOnly date)
{
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID==groupId).ToList();
List<PresenceLocalEntity> presenceList = new List<PresenceLocalEntity>();
for (int i = firstClass; i < lastClass; i++) {
foreach (var user in users) {
PresenceLocalEntity pres = new PresenceLocalEntity {ClassNumber = i, Date = date, UserGuid = user.Guid};
var users = _repositoryUserImpl.GetAllUser().Where(x => x.GroupId==groupId).ToList();
List<PresenceDao> presenceList = new List<PresenceDao>();
for (int i = firstClass; i < lastClass; i++)
{
foreach (var user in users)
{
PresenceDao pres = new PresenceDao{ClassNumber = i, Date = date, UserId = user.UserId, User = user};
presenceList.Add(pres);
}
}

View File

@ -1,4 +1,5 @@
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
using Posechaemost.Data.Repository;
using Posechaemost.Domain.Models;
using System;
@ -12,50 +13,43 @@ namespace Posechaemost.Domain.UseCase
public class UserUseCase
{
private readonly UserRepositoryImpl _repositoryUserImpl;
private readonly SQLUserRepositoryImpl _repositoryUserImpl;
private readonly IGroupRepository _repositoryGroupImpl;
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
public UserUseCase(SQLUserRepositoryImpl repositoryImpl, SQLGroupRepositoryImpl repositoryGroupImpl)
{
_repositoryUserImpl = repositoryImpl;
_repositoryGroupImpl = repositoryGroupImpl;
}
private List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers
private List<GroupDao> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new GroupDao { Id = it.Id, Name = it.Name}).ToList();
public List<UserDao> GetAllUsers() => _repositoryUserImpl.GetAllUser()
.Join(_repositoryGroupImpl.GetAllGroups(),
user => user.GroupID,
user => user.GroupId,
group => group.Id,
(user, group) =>
new User { FIO = user.FIO,
Guid = user.Guid,
GroupId = new Group {Id = group.Id, Name = group.Name } }
new UserDao { FIO = user.FIO,
UserId = user.UserId,
GroupId = group.Id }
).ToList();
public bool RemoveUserByGuid(Guid userGuid) {
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
public bool RemoveUserById(int userId) {
return _repositoryUserImpl.RemoveUserById(userId);
}
public User UpdateUser(User user) {
UserLocalEntity userLocalEnity = new UserLocalEntity { FIO = user.FIO, GroupID = user.GroupId.Id, Guid = user.Guid };
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 { FIO = user.FIO, Guid = user.Guid, GroupId = group};
public bool UpdateUser(UserDao user) {
UserDao userDao = new UserDao { FIO = user.FIO, GroupId = user.GroupId };
return _repositoryUserImpl.UpdateUser(userDao);
}
public UserLocalEntity GetUserByGuid(Guid userGuid) {
return _repositoryUserImpl.GetUserByGuid(userGuid);
public UserDao GetUserById(int userId) {
return _repositoryUserImpl.GetUserById(userId);
}
public User UpdateUserByGuid(Guid userGuid, String fio, String groupId) {
UserLocalEntity? result = _repositoryUserImpl.UpdateUserByGuid(userGuid);
if (result == null) throw new Exception("");
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == int.Parse(groupId));
if (group == null) throw new Exception("");
return new User { FIO = fio, GroupId = group, Guid = userGuid };
public bool UpdateUserById(int userId, String fio, int groupId) {
UserDao userDao = new UserDao { FIO = fio, GroupId = groupId };
return _repositoryUserImpl.UpdateUser(userDao);
}
}
}

View File

@ -7,13 +7,17 @@ using System.Text.RegularExpressions;
IServiceCollection services = new ServiceCollection();
services
.AddSingleton<IGroupRepository, GroupRepositoryImpl>()
.AddSingleton<UserUseCase>();
.AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>()
.AddSingleton<IUserRepository, SQLUserRepositoryImpl>()
.AddSingleton<IPresenceRepository, SQLPresenceRepositoryImpl>()
.AddSingleton<UserUseCase>()
.AddSingleton<GroupUseCase>()
.AddSingleton<PresenceUseCase>();
var serviceProvider = services.BuildServiceProvider();
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();
UserUseCase userUseCase = serviceProvider.GetService<UserUseCase>();
GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl);
var userUseCase = serviceProvider.GetService<UserUseCase>();
var groupUseCase = serviceProvider.GetService<GroupUseCase>();
var presenceUseCase = serviceProvider.GetService<PresenceUseCase>();
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase);
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase, presenceUseCase);

View File

@ -32,12 +32,16 @@ namespace Posechaemost.UI
switch (Console.ReadLine())
{
case "1": _userConsoleUI.DisplayAllUsers(); break;
case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
case "2": _userConsoleUI.RemoveUserById(int.Parse(Console.ReadLine())); break;
case "3": _groupConsoleUI.DisplayAllGroups(); break;
case "4": _userConsoleUI.GetUserByGuid(Guid.Parse(Console.ReadLine())); break;
case "5": _userConsoleUI.UpdateUserByGuid(Guid.Parse(Console.ReadLine()), Console.ReadLine(), Console.ReadLine()); break;
case "4": _userConsoleUI.GetUserById(int.Parse(Console.ReadLine())); break;
case "5": _userConsoleUI.UpdateUserById(int.Parse(Console.ReadLine()), Console.ReadLine(), int.Parse(Console.ReadLine())); break;
case "6": _groupConsoleUI.UpdateGroupName(Console.ReadLine(), Console.ReadLine()); break;
case "7": _groupConsoleUI.AddGroup(Console.ReadLine(), Console.ReadLine()); break;
case "8": _presenceConsoleUI.GetPresenceByGroup(int.Parse(Console.ReadLine())); break;
case "9": _presenceConsoleUI.GetPresenceByGroupAndDate(int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine())); break;
case "10": _presenceConsoleUI.UncheckAttendence(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine()), int.Parse(Console.ReadLine())); break;
case "11": _presenceConsoleUI.AddPresence(int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), int.Parse(Console.ReadLine()), DateOnly.Parse(Console.ReadLine())); break;
default: DisplayMenu();
break;

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Posechaemost.Domain.UseCase;
@ -9,24 +10,46 @@ namespace Posechaemost.UI
public class PresenceConsoleUI
{
PresenceUseCase _presenceUseCase;
public PresenceConsoleUI(PresenceUseCase presenceUseCase) {
public PresenceConsoleUI(PresenceUseCase presenceUseCase)
{
_presenceUseCase = presenceUseCase;
}
public void GetPresenceByGroup(int groupId) {
public void GetPresenceByGroup(int groupId)
{
StringBuilder presenceOutput = new StringBuilder();
var presence = _presenceUseCase.GetPresenceByGroup(groupId);
foreach (var p in presence)
{
presenceOutput.AppendLine($"{p.User.UserId}\t{p.User.FIO}\t{p.ClassNumber}\t{p.Date}\t{p.IsAttendence}");
}
Console.WriteLine(presenceOutput);
}
public void GetPresenceByGroupAndDate(int groupId, DateOnly date) {
public void GetPresenceByGroupAndDate(int groupId, DateOnly date)
{
StringBuilder presenceOutput = new StringBuilder();
var presence = _presenceUseCase.GetPresenceByGroupAndDate(groupId, date);
foreach (var p in presence)
{
presenceOutput.AppendLine($"{p.User.UserId}\t{p.User.FIO}\t{p.ClassNumber}\t{p.Date}\t{p.IsAttendence}");
}
Console.WriteLine(presenceOutput);
}
public void UncheckAttendence(int firstClass, int lastClass, DateOnly date, Guid userGuid) {
var presence = _presenceUseCase.UncheckAttendence(firstClass, lastClass, date, userGuid);
public void UncheckAttendence(int firstClass, int lastClass, DateOnly date, int userId)
{
string output = _presenceUseCase.UncheckAttendence(firstClass, lastClass, date, userId) ?
"Посещаемость обновлена" : "Посещаемость не обновлена";
Console.WriteLine(output);
}
public void AddPresence(int firstClass, int lastClass, int groupId, DateOnly date) {
public void AddPresence(int firstClass, int lastClass, int groupId, DateOnly date)
{
StringBuilder presenceOutput = new StringBuilder();
_presenceUseCase.AddPresence(firstClass, lastClass, groupId, date);
presenceOutput.AppendLine("Посещаемость добавлена");
Console.WriteLine(presenceOutput);
}
}
}

View File

@ -15,9 +15,9 @@ namespace Posechaemost.UI
_userUseCase = userUseCase;
}
public void RemoveUserByGuid(Guid guidUser) {
public void RemoveUserById(int userId) {
string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален";
string output = _userUseCase.RemoveUserById(userId) ? "Пользователь удален" : "Пользователь не удален";
Console.WriteLine(output);
}
@ -26,22 +26,21 @@ namespace Posechaemost.UI
StringBuilder userOutput = new StringBuilder();
foreach (var user in _userUseCase.GetAllUsers())
{
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupId.Name}");
userOutput.AppendLine($"{user.UserId}\t{user.FIO}\t{user.GroupId}");
}
Console.WriteLine(userOutput);
}
public void GetUserByGuid(Guid userGuid) {
public void GetUserById(int userId) {
StringBuilder userOutput = new StringBuilder();
var user = _userUseCase.GetUserByGuid(userGuid);
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupID}");
var user = _userUseCase.GetUserById(userId);
userOutput.AppendLine($"{user.UserId}\t{user.FIO}\t{user.GroupId}");
Console.WriteLine(userOutput);
}
public void UpdateUserByGuid(Guid userGuid, String name, String groupId) {
public void UpdateUserById(int userId, String name, int groupId) {
StringBuilder userOutput = new StringBuilder();
var user = _userUseCase.UpdateUserByGuid(userGuid, name, groupId);
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupId.Name}");
var user = _userUseCase.UpdateUserById(userId, name, groupId) ? "Пользователь обновлен" : "Пользователь не обновлен";
Console.WriteLine(userOutput);
}
}

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Posechaemost")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+dd18de386525d2859a6db90bb74a2bdc95bc47e3")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0705829116f2c729cee9977f2de521bf54b6e4b1")]
[assembly: System.Reflection.AssemblyProductAttribute("Posechaemost")]
[assembly: System.Reflection.AssemblyTitleAttribute("Posechaemost")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
e484c6d2be3801b673b3b8bec4389b40f150f0a04dc9544c29a279722a7318c6
04d7b3aacea28cffe6e56680c2c82b72f1a837729ee485f47bdc07c464612b47