db presence
This commit is contained in:
parent
48479e25a5
commit
1835f76d68
@ -1,15 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
namespace Demo.Domain.Models
|
||||
{
|
||||
public class GroupLocalEntity
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
|
||||
public required int ID {get; set; }
|
||||
public required string Name{get; set; }
|
||||
}
|
||||
}
|
@ -1,16 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
{
|
||||
public class PresenceLocalEntity
|
||||
{
|
||||
public required Guid UserGuid { get; set; }
|
||||
namespace Demo.Domain.Models{
|
||||
public class PresenceLocalEntity{
|
||||
public required Guid UserGuid{get; set; }
|
||||
public bool IsAttedance { get; set; } = true;
|
||||
public required DateOnly Date { get; set; }
|
||||
|
||||
public required int LessonNumber { get; set; }
|
||||
}
|
||||
}
|
@ -1,24 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
{
|
||||
public class UserLocalEntity : IEquatable<UserLocalEntity>
|
||||
{
|
||||
public required string FIO { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
|
||||
public required int GroupID { get; set; }
|
||||
|
||||
|
||||
namespace Demo.Domain.Models{
|
||||
public class UserLocalEntity :IEquatable<UserLocalEntity>{
|
||||
public required string FIO{get; set; }
|
||||
public Guid Guid {get; set; }
|
||||
public required int GroupID{get; set; }
|
||||
|
||||
public bool Equals(UserLocalEntity? other)
|
||||
{
|
||||
if (other == null) return false;
|
||||
return this.Guid.Equals(other.Guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +1,14 @@
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Data.LocalData
|
||||
{
|
||||
public static class LocalStaticData
|
||||
public class LocalStaticData
|
||||
{
|
||||
public static List<GroupLocalEntity> groups => new List<GroupLocalEntity>
|
||||
|
||||
{
|
||||
new GroupLocalEntity{ Id = 1, Name = "ИП1-21" },
|
||||
new GroupLocalEntity{ Id = 2, Name = "ИП1-22" },
|
||||
new GroupLocalEntity{ Id = 3, Name = "ИП1-23" },
|
||||
new GroupLocalEntity{ID = 1, Name = "ИП1-21"},
|
||||
new GroupLocalEntity{ID = 2, Name = "ИП1-22"},
|
||||
new GroupLocalEntity{ID = 3, Name = "ИП1-23"},
|
||||
};
|
||||
|
||||
public static List<UserLocalEntity> users => new List<UserLocalEntity>
|
||||
|
@ -1,10 +1,9 @@
|
||||
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
{
|
||||
public class GroupDao {
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<UserDao> User { get; set; }
|
||||
public class GroupDAO
|
||||
{
|
||||
public int ID {get; set; }
|
||||
public string Name{get; set; }
|
||||
public IEnumerable<UserDAO> Users {get; set; }
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO {
|
||||
|
||||
public class PresenceDao {
|
||||
|
||||
public Guid UserGuid { get; set; }
|
||||
public bool IsAttedance { get; set; }
|
||||
public DateOnly Date { get; set; }
|
||||
public int LessonNumber { get; set; }
|
||||
public UserDao userDao { get; set; }
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
{
|
||||
public class PresenceDAO
|
||||
{
|
||||
public Guid UserGuid {get; set; }
|
||||
public bool IsAttedance {get; set; }
|
||||
public DateOnly Date {get; set; }
|
||||
public int LessonNumber {get; set; }
|
||||
public UserDAO userDAO {get; set; }
|
||||
}
|
||||
}
|
@ -2,11 +2,11 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
{
|
||||
public class UserDao
|
||||
public class UserDAO
|
||||
{
|
||||
public string FIO { get; set; }
|
||||
public string FIO { get; set; }
|
||||
public Guid Guid {get; set; }
|
||||
public int GroupID {get; set;}
|
||||
public GroupDao Group {get; set; }
|
||||
public GroupDAO Group {get; set; }
|
||||
}
|
||||
}
|
@ -1,33 +1,28 @@
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Data.RemoteData.RemoteDataBase.DAO
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase
|
||||
{
|
||||
|
||||
public class RemoteDatabaseContext: DbContext {
|
||||
|
||||
public DbSet<GroupDao> Groups { get; set; }
|
||||
public DbSet<UserDao> Users { get; set; }
|
||||
public DbSet<PresenceDao> PresenceDaos { get; set; }
|
||||
public class RemoteDatabaseContext: DbContext
|
||||
{
|
||||
public DbSet<GroupDAO> Groups {get; set; }
|
||||
public DbSet<UserDAO> Users {get; set;}
|
||||
public DbSet<PresenceDAO> PresenceDaos{get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=localhost;" +
|
||||
"Port=5432;" +
|
||||
"Username=postgres;" +
|
||||
"Password=1234;" +
|
||||
"Database=postgres");
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Username=myuser;Password=mypassword;Database=mydatabase");
|
||||
}
|
||||
|
||||
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<PresenceDao>().HasKey(presence => new {
|
||||
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<PresenceDAO>().HasKey(presence => new {
|
||||
presence.UserGuid,
|
||||
presence.Date,
|
||||
presence.IsAttedance,
|
||||
presence.LessonNumber
|
||||
});
|
||||
}
|
||||
|
@ -1,64 +1,55 @@
|
||||
using Demo.Domain.Models;
|
||||
using Demo.Data.LocalData;
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public class SQLGroupRepositoryImpl : IGroupRepository
|
||||
{
|
||||
|
||||
private readonly RemoteDatabaseContext _remoteDatabaseContext;
|
||||
|
||||
public SQLGroupRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) {
|
||||
|
||||
public SQLGroupRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext){
|
||||
_remoteDatabaseContext = remoteDatabaseContext;
|
||||
GetAllGroups = _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, Id = x.Id}).ToList();
|
||||
GetAllGroups = _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, ID = x.ID}).ToList();
|
||||
}
|
||||
|
||||
public List<GroupLocalEntity> GetAllGroups
|
||||
{ get; set; }
|
||||
|
||||
public List<GroupLocalEntity> GetAllGroup()
|
||||
{
|
||||
return _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, Id = x.Id}).ToList();
|
||||
return _remoteDatabaseContext.Groups.Select(x => new GroupLocalEntity{Name = x.Name, ID = x.ID}).ToList();
|
||||
}
|
||||
|
||||
public GroupLocalEntity? UpdateGroupName(GroupLocalEntity groupUpdateLocalEntity) {
|
||||
public GroupLocalEntity? GetGroupById(int ID){
|
||||
var groupDAO = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.ID == ID);
|
||||
return new GroupLocalEntity{Name = groupDAO.Name, ID = groupDAO.ID};
|
||||
}
|
||||
|
||||
var group = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupUpdateLocalEntity.Id);
|
||||
public GroupLocalEntity? CreateGroup(string Name) {
|
||||
GroupDAO groupDAO = new GroupDAO{Name = Name};
|
||||
var result = _remoteDatabaseContext.Groups.Add(groupDAO);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return new GroupLocalEntity{Name = groupDAO.Name, ID = groupDAO.ID};
|
||||
}
|
||||
|
||||
public GroupLocalEntity? UpdateGroup(GroupLocalEntity updatedGroup){
|
||||
var group = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.ID == updatedGroup.ID);
|
||||
if (group == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
group.Name = groupUpdateLocalEntity.Name;
|
||||
group.Name = updatedGroup.Name;
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return new GroupLocalEntity{Name = group.Name, Id = group.Id};
|
||||
return new GroupLocalEntity{Name = group.Name, ID = group.ID};
|
||||
}
|
||||
|
||||
public GroupLocalEntity? CreateGroup(string Name) {
|
||||
|
||||
GroupDao groupDAO = new GroupDao{Name = Name};
|
||||
var result = _remoteDatabaseContext.Groups.Add(groupDAO);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return new GroupLocalEntity{Name = groupDAO.Name, Id = groupDAO.Id};
|
||||
}
|
||||
|
||||
public bool RemoveGroupById(int groupID)
|
||||
{
|
||||
var groupDao = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupID);
|
||||
_remoteDatabaseContext.Groups.Remove(groupDao);
|
||||
public bool RemoveGroupByID(int ID){
|
||||
var groupDAO = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.ID == ID);
|
||||
_remoteDatabaseContext.Groups.Remove(groupDAO);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
|
||||
public GroupLocalEntity? GetGroupById(int groupId) {
|
||||
var groupDao = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Id == groupId);
|
||||
return new GroupLocalEntity{Name = groupDao.Name, Id = groupDao.Id};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,13 @@
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public interface IGroupRepository
|
||||
{
|
||||
List<GroupLocalEntity> GetAllGroup();
|
||||
bool RemoveGroupById(int groupID);
|
||||
GroupLocalEntity? UpdateGroupName(GroupLocalEntity updatedGroup);
|
||||
GroupLocalEntity? GetGroupById(int groupID);
|
||||
GroupLocalEntity? GetGroupById(int ID);
|
||||
bool RemoveGroupByID(int groupId);
|
||||
GroupLocalEntity? UpdateGroup(GroupLocalEntity updatedGroup);
|
||||
GroupLocalEntity? CreateGroup(string Name);
|
||||
}
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
using Demo.domain.Models;
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public interface IPresenceRepository
|
||||
{
|
||||
List<PresenceLocalEntity> GetPresences();
|
||||
List<PresenceLocalEntity> GetPresencesByGroup();
|
||||
List<PresenceLocalEntity> GetPresencesByGroupAndDate();
|
||||
List<PresenceLocalEntity> GetAllPresences();
|
||||
void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid);
|
||||
List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities);
|
||||
void UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid);
|
||||
}
|
||||
}
|
@ -1,17 +1,12 @@
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public interface IUserRepository
|
||||
{
|
||||
List<UserLocalEntity> GetAllUser();
|
||||
bool RemoveUserByGuid(Guid userGuid);
|
||||
UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEntity);
|
||||
UserLocalEntity? GetUserByGuid(Guid userGuid);
|
||||
UserLocalEntity? GetUserByGuid(Guid guid);
|
||||
bool RemoveUserByGuid(Guid guid);
|
||||
UserLocalEntity? UpdateUser(UserLocalEntity updatedUser);
|
||||
}
|
||||
}
|
@ -1,45 +1,33 @@
|
||||
using Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Data.LocalData;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.domain.Models;
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public class SQLPresenceRepositoryImpl : IPresenceRepository
|
||||
{
|
||||
|
||||
private readonly RemoteDatabaseContext _remoteDatabaseContext;
|
||||
|
||||
public SQLPresenceRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext){
|
||||
_remoteDatabaseContext = remoteDatabaseContext;
|
||||
GetAllPresence = _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
|
||||
}
|
||||
|
||||
public List<PresenceLocalEntity> GetAllPresence = new List<PresenceLocalEntity>{};
|
||||
|
||||
public List<PresenceLocalEntity> GetPresences()
|
||||
{
|
||||
return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
|
||||
}
|
||||
|
||||
public List<PresenceLocalEntity> GetPresencesByGroup()
|
||||
{
|
||||
return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
|
||||
}
|
||||
|
||||
public List<PresenceLocalEntity> GetPresencesByGroupAndDate()
|
||||
{
|
||||
public List<PresenceLocalEntity> GetAllPresences(){
|
||||
return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
|
||||
}
|
||||
|
||||
public List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities)
|
||||
{
|
||||
var presences = presenceLocalEntities.Select(x => new PresenceDao
|
||||
var presences = presenceLocalEntities.Select(x => new PresenceDAO
|
||||
{
|
||||
UserGuid = x.UserGuid,
|
||||
IsAttedance = x.IsAttedance,
|
||||
LessonNumber = x.LessonNumber,
|
||||
Date = x.Date,
|
||||
userDao = _remoteDatabaseContext.Users.FirstOrDefault(u => u.Guid == x.UserGuid)
|
||||
userDAO = _remoteDatabaseContext.Users.FirstOrDefault(u => u.Guid == x.UserGuid)
|
||||
}).ToList();
|
||||
|
||||
_remoteDatabaseContext.PresenceDaos.AddRange(presences);
|
||||
@ -48,7 +36,7 @@ namespace Demo.Data.Repository
|
||||
return presenceLocalEntities;
|
||||
}
|
||||
|
||||
public void UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
||||
public void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
||||
var presencesToUpdate = _remoteDatabaseContext.PresenceDaos
|
||||
.Where(x => x.LessonNumber >= firstLesson
|
||||
&& x.LessonNumber <= lastLesson
|
||||
@ -62,5 +50,6 @@ namespace Demo.Data.Repository
|
||||
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +1,45 @@
|
||||
using Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Domain.Models;
|
||||
using Demo.Data.LocalData;
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public class SQLUserRepositoryImpl:IUserRepository
|
||||
public class SQLUserRepositoryImpl : IUserRepository
|
||||
{
|
||||
|
||||
private readonly RemoteDatabaseContext _remoteDatabaseContext;
|
||||
|
||||
public SQLUserRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext) {
|
||||
|
||||
public SQLUserRepositoryImpl(RemoteDatabaseContext remoteDatabaseContext){
|
||||
_remoteDatabaseContext = remoteDatabaseContext;
|
||||
GetAllUsers = _remoteDatabaseContext.Users.Select(x => new UserLocalEntity{FIO = x.FIO, Guid = x.Guid, GroupID = x.GroupID}).ToList();
|
||||
}
|
||||
|
||||
public List<UserLocalEntity> GetAllUsers
|
||||
{ get; set; }
|
||||
|
||||
public List<UserLocalEntity> GetAllUser()
|
||||
{
|
||||
public List<UserLocalEntity> GetAllUser(){
|
||||
return _remoteDatabaseContext.Users.Select(x => new UserLocalEntity{FIO = x.FIO, Guid = x.Guid, GroupID = x.GroupID}).ToList();
|
||||
}
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid)
|
||||
{
|
||||
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid);
|
||||
public UserLocalEntity? GetUserByGuid(Guid guid){
|
||||
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == guid);
|
||||
return new UserLocalEntity{FIO = userDAO.FIO, GroupID = userDAO.GroupID, Guid = guid};
|
||||
}
|
||||
|
||||
public bool RemoveUserByGuid(Guid guid){
|
||||
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == guid);
|
||||
_remoteDatabaseContext.Users.Remove(userDAO);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
|
||||
public UserLocalEntity? GetUserByGuid(Guid userGuid) {
|
||||
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userGuid);
|
||||
return new UserLocalEntity{FIO = userDAO.FIO, GroupID = userDAO.GroupID, Guid = userGuid};
|
||||
}
|
||||
|
||||
public UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEntity) {
|
||||
var user = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == userUpdateLocalEntity.Guid);
|
||||
public UserLocalEntity? UpdateUser(UserLocalEntity updatedUser){
|
||||
var user = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == updatedUser.Guid);
|
||||
if (user == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
user.FIO = userUpdateLocalEntity.FIO;
|
||||
user.GroupID = userUpdateLocalEntity.GroupID;
|
||||
user.FIO = updatedUser.FIO;
|
||||
user.GroupID = updatedUser.GroupID;
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return new UserLocalEntity{FIO = user.FIO, Guid = user.Guid, GroupID = user.GroupID};
|
||||
}
|
||||
|
@ -1,19 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
namespace Demo.Domain.Models
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
public required int Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
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]};
|
||||
return new Group{ID = Convert.ToInt32(words[0]), Name = words[1]};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
namespace Demo.Domain.Models
|
||||
{
|
||||
public class Presence
|
||||
{
|
||||
|
||||
public required User User { get; set; }
|
||||
public required User User{get; set; }
|
||||
public bool IsAttedance { get; set; } = true;
|
||||
public required DateOnly Date { get; set; }
|
||||
|
||||
|
@ -1,22 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.domain.Models
|
||||
namespace Demo.Domain.Models
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public required string FIO { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
public required string FIO{get; set; }
|
||||
public Guid Guid{get; set; }
|
||||
public required Group Group{get; set; }
|
||||
|
||||
public required Group Group { get; set; }
|
||||
|
||||
|
||||
public static User Parse(string input){
|
||||
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]}};
|
||||
|
||||
if (words.Length < 4)
|
||||
{
|
||||
throw new FormatException("Input string does not have the expected number of elements.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new User
|
||||
{
|
||||
FIO = words[0],
|
||||
Guid = Guid.Parse(words[1]),
|
||||
Group = new Group
|
||||
{
|
||||
ID = Convert.ToInt32(words[2]),
|
||||
Name = words[3]
|
||||
}
|
||||
};
|
||||
}
|
||||
catch (FormatException ex)
|
||||
{
|
||||
Console.WriteLine("Error parsing input: " + ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +1,54 @@
|
||||
using Demo.Domain.Models;
|
||||
using Demo.Data.Repository;
|
||||
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 GroupUseCase:IGroupUseCase
|
||||
public class GroupUseCase : IGroupUseCase
|
||||
{
|
||||
|
||||
private readonly IUserRepository _repositoryUserImpl;
|
||||
private readonly IGroupRepository _repositoryGroupImpl;
|
||||
|
||||
public GroupUseCase(IGroupRepository groupRepository, IUserRepository repositoryUserImpl)
|
||||
public GroupUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl)
|
||||
{
|
||||
_repositoryGroupImpl = groupRepository;
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
_repositoryUserImpl = repositoryUserImpl;
|
||||
}
|
||||
|
||||
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
|
||||
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
|
||||
|
||||
public Group UpdateGroupName(Group group) {
|
||||
|
||||
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
|
||||
};
|
||||
.Select(it => new Group{ID = it.ID, Name = it.Name}).ToList();
|
||||
|
||||
public Group GetGroupById(int groupID)
|
||||
{
|
||||
GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupID);
|
||||
if (groupLocalEntity == null) throw new Exception("bello");
|
||||
return new Group{ID = groupID, Name = groupLocalEntity.Name};
|
||||
}
|
||||
|
||||
public bool RemoveGroupById(int groupId) {
|
||||
|
||||
return _repositoryGroupImpl.RemoveGroupById(groupId);
|
||||
}
|
||||
|
||||
public bool CreateGroup(string Name) {
|
||||
|
||||
public bool CreateGroup(string Name){
|
||||
_repositoryGroupImpl.CreateGroup(Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Group GetGroupById(int groupId) {
|
||||
public Group UpdateGroup(Group group)
|
||||
{
|
||||
GroupLocalEntity groupLocalEntity = new GroupLocalEntity
|
||||
{
|
||||
ID = group.ID,
|
||||
Name = group.Name
|
||||
};
|
||||
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity);
|
||||
if (result == null)
|
||||
{
|
||||
throw new Exception("Не удалось обновить пользователя: пользователь не найден.");
|
||||
}
|
||||
return new Group
|
||||
{
|
||||
ID = result.ID,
|
||||
Name = result.Name
|
||||
};
|
||||
}
|
||||
|
||||
GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupId);
|
||||
if (groupLocalEntity == null) throw new Exception("bello");
|
||||
return new Group{Id = groupId, Name = groupLocalEntity.Name};
|
||||
public bool RemoveGroupByID(int userID) {
|
||||
return _repositoryGroupImpl.RemoveGroupByID(userID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,12 @@
|
||||
using Demo.domain.Models;
|
||||
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 interface IGroupUseCase
|
||||
{
|
||||
List<Group> GetAllGroups();
|
||||
bool RemoveGroupById(int groupId);
|
||||
Group UpdateGroupName(Group group);
|
||||
bool RemoveGroupByID(int groupID);
|
||||
Group UpdateGroup(Group group);
|
||||
Group GetGroupById(int groupID);
|
||||
bool CreateGroup(string Name);
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
using Demo.domain.Models;
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
public interface IPresenceUseCase
|
||||
{
|
||||
List<Presence> GetPresencesByGroup(int groupId);
|
||||
List<Presence> GetPresencesByGroupAndDate(int groupId, DateOnly date);
|
||||
bool UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid);
|
||||
bool GeneratePresence(int firstLesson, int lastLesson, int groupId, DateOnly date);
|
||||
bool GenerateWeekPresence(int firstLesson, int lastLesson, int groupId, DateOnly date);
|
||||
List<Presence> GetPresenceByGroup(int groupID);
|
||||
List<Presence> GetPresenceByGroupByTime(int groupID, DateOnly date);
|
||||
bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid);
|
||||
bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date);
|
||||
bool GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date);
|
||||
}
|
||||
}
|
@ -1,18 +1,12 @@
|
||||
using Demo.domain.Models;
|
||||
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 interface IUserUseCase
|
||||
{
|
||||
List<Group> GetAllGroups();
|
||||
List<User> GetAllUsers();
|
||||
User GetUserByGuid(Guid userGuid);
|
||||
bool RemoveUserByGuid(Guid userGuid);
|
||||
User UpdateUser(User user);
|
||||
User GetUserByGuid(Guid userGuid);
|
||||
}
|
||||
}
|
@ -1,34 +1,57 @@
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Demo.Data.Repository;
|
||||
using Demo.domain.Models;
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
public class PresenceUseCase : IPresenceUseCase
|
||||
{
|
||||
private readonly IUserRepository _repositoryUserImpl;
|
||||
private readonly IUserRepository _repositoryUserImpl;
|
||||
private readonly IPresenceRepository _repositoryPresenceImpl;
|
||||
private readonly IGroupRepository _repositoryGroupImpl;
|
||||
|
||||
public PresenceUseCase(IPresenceRepository presenceRepository, IUserRepository repositoryUserImpl, IGroupRepository repositoryGroupImpl)
|
||||
public PresenceUseCase(IPresenceRepository repositoryPresenceImpl, IUserRepository repositoryUserImpl, IGroupRepository repositoryGroupImpl)
|
||||
{
|
||||
_repositoryPresenceImpl = presenceRepository;
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
_repositoryPresenceImpl = repositoryPresenceImpl;
|
||||
_repositoryUserImpl = repositoryUserImpl;
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
}
|
||||
|
||||
public List<Presence> GetPresencesByGroup(int groupId)
|
||||
{
|
||||
public List<Presence> GetPresenceByGroup(int groupID){
|
||||
var usersByGroup = _repositoryUserImpl.GetAllUser()
|
||||
.Where(user => user.GroupID == groupId).ToList();
|
||||
.Where(user => user.GroupID == groupID).ToList();
|
||||
|
||||
var presenceByGroup = _repositoryPresenceImpl.GetPresencesByGroup()
|
||||
var presenceByGroup = _repositoryPresenceImpl.GetAllPresences()
|
||||
.Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid))
|
||||
.Select(presence => new Presence{
|
||||
User = new User{
|
||||
Guid = presence.UserGuid,
|
||||
Group = new Group{
|
||||
Id = groupId,
|
||||
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name
|
||||
ID = groupID,
|
||||
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name
|
||||
},
|
||||
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
|
||||
},
|
||||
LessonNumber = presence.LessonNumber,
|
||||
Date = presence.Date,
|
||||
IsAttedance = presence.IsAttedance
|
||||
}).ToList();
|
||||
|
||||
return presenceByGroup;
|
||||
}
|
||||
|
||||
public List<Presence> GetPresenceByGroupByTime(int groupID, DateOnly date){
|
||||
var usersByGroup = _repositoryUserImpl.GetAllUser()
|
||||
.Where(user => user.GroupID == groupID).ToList();
|
||||
|
||||
var presenceByGroup = _repositoryPresenceImpl.GetAllPresences()
|
||||
.Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid && x.Date == date))
|
||||
.Select(presence => new Presence{
|
||||
User = new User{
|
||||
Guid = presence.UserGuid,
|
||||
Group = new Group{
|
||||
ID = groupID,
|
||||
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name
|
||||
},
|
||||
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
|
||||
},
|
||||
@ -40,56 +63,43 @@ namespace Demo.Domain.UseCase
|
||||
return presenceByGroup;
|
||||
}
|
||||
|
||||
public List<Presence> GetPresencesByGroupAndDate(int groupId, DateOnly date)
|
||||
{
|
||||
var usersByGroup = _repositoryUserImpl.GetAllUser()
|
||||
.Where(user => user.GroupID == groupId).ToList();
|
||||
|
||||
var presenceByGroupAndDate = _repositoryPresenceImpl.GetPresencesByGroup()
|
||||
.Where(x => usersByGroup.Any(user => user.Guid == x.UserGuid && x.Date == date))
|
||||
.Select(presence => new Presence{
|
||||
User = new User{
|
||||
Guid = presence.UserGuid,
|
||||
Group = new Group{
|
||||
Id = groupId,
|
||||
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name
|
||||
},
|
||||
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
|
||||
},
|
||||
LessonNumber = presence.LessonNumber,
|
||||
Date = presence.Date,
|
||||
IsAttedance = presence.IsAttedance
|
||||
}).ToList();
|
||||
|
||||
return presenceByGroupAndDate;
|
||||
}
|
||||
|
||||
public bool UpdateAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
||||
_repositoryPresenceImpl.UpdateAttedance(firstLesson, lastLesson, date, UserGuid);
|
||||
public bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
||||
_repositoryPresenceImpl.IsAttedance(firstLesson, lastLesson, date, UserGuid);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool GeneratePresence(int firstLesson, int lastLesson, int groupId, DateOnly date){
|
||||
List<Presence> presenceList = new List<Presence>{};
|
||||
var usersByGroup = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupId);
|
||||
for (int i = firstLesson; i <= lastLesson; i++){
|
||||
foreach(UserLocalEntity user in usersByGroup){
|
||||
presenceList.Add(new Presence{
|
||||
User = new User{
|
||||
Group = new Group{
|
||||
Id = groupId,
|
||||
Name = _repositoryGroupImpl.GetAllGroup().First(group => group.Id == groupId).Name
|
||||
public bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date)
|
||||
{
|
||||
var usersByGroup = _repositoryUserImpl.GetAllUser().Where(x => x.GroupID == groupID).ToList();
|
||||
var groupName = _repositoryGroupImpl.GetAllGroup().First(group => group.ID == groupID).Name;
|
||||
|
||||
List<Presence> presenceList = new List<Presence>();
|
||||
|
||||
for (int i = firstLesson; i <= lastLesson; i++)
|
||||
{
|
||||
foreach (UserLocalEntity user in usersByGroup)
|
||||
{
|
||||
presenceList.Add(new Presence
|
||||
{
|
||||
User = new User
|
||||
{
|
||||
Group = new Group
|
||||
{
|
||||
ID = groupID,
|
||||
Name = groupName
|
||||
},
|
||||
FIO = user.FIO,
|
||||
Guid = user.Guid
|
||||
},
|
||||
FIO = usersByGroup.First(user2 => user2.Guid == user.Guid).FIO,
|
||||
Guid = user.Guid
|
||||
},
|
||||
IsAttedance = true,
|
||||
Date = date,
|
||||
LessonNumber = i});
|
||||
IsAttedance = true,
|
||||
Date = date,
|
||||
LessonNumber = i
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var presenceLocalEntity = presenceList.Select(x => new PresenceLocalEntity{
|
||||
var presenceLocalEntity = presenceList.Select(x => new PresenceLocalEntity
|
||||
{
|
||||
UserGuid = x.User.Guid,
|
||||
IsAttedance = x.IsAttedance,
|
||||
LessonNumber = x.LessonNumber,
|
||||
@ -101,9 +111,9 @@ namespace Demo.Domain.UseCase
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool GenerateWeekPresence(int firstLesson, int lastLesson, int groupId, DateOnly date){
|
||||
public bool GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){
|
||||
for (int i = 0; i < 8; i++){
|
||||
GeneratePresence(firstLesson, lastLesson, groupId, date.AddDays(i));
|
||||
GeneratePresence(firstLesson, lastLesson, groupID, date.AddDays(i));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,73 +1,70 @@
|
||||
using Demo.Domain.Models;
|
||||
using Demo.Data.Repository;
|
||||
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 : IUserUseCase
|
||||
{
|
||||
private readonly IUserRepository _repositoryUserImpl;
|
||||
private readonly IGroupRepository _repositoryGroupImpl;
|
||||
private readonly IUserRepository _repositoryUserImpl;
|
||||
private readonly IGroupRepository _repositoryGroupImpl;
|
||||
|
||||
public UserUseCase(IUserRepository userRepository, IGroupRepository groupRepository)
|
||||
public UserUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl)
|
||||
{
|
||||
_repositoryUserImpl = userRepository;
|
||||
_repositoryGroupImpl = groupRepository;
|
||||
_repositoryGroupImpl = repositoryGroupImpl;
|
||||
_repositoryUserImpl = repositoryUserImpl;
|
||||
}
|
||||
|
||||
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroup()
|
||||
.Select(it => new Group{Id = it.Id, Name = it.Name}).ToList();
|
||||
.Select(it => new Group{ID = it.ID, Name = it.Name}).ToList();
|
||||
|
||||
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUser()
|
||||
.Join(_repositoryGroupImpl.GetAllGroup(),
|
||||
user => user.GroupID,
|
||||
group => group.Id,
|
||||
group => group.ID,
|
||||
(user, group) => new User{
|
||||
FIO = user.FIO,
|
||||
Guid = user.Guid,
|
||||
Group = new Group{
|
||||
Id = group.Id,
|
||||
ID = group.ID,
|
||||
Name = group.Name}
|
||||
}
|
||||
).ToList();
|
||||
|
||||
public User GetUserByGuid(Guid userGuid) {
|
||||
public User GetUserByGuid(Guid userGuid){
|
||||
UserLocalEntity? userLocalEntity = _repositoryUserImpl.GetUserByGuid(userGuid);
|
||||
if (userLocalEntity == null) throw new Exception("bello");
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => userLocalEntity.GroupID == it.Id);
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => userLocalEntity.GroupID == it.ID);
|
||||
if (group == null) throw new Exception("bello");
|
||||
return new User{
|
||||
FIO = userLocalEntity.FIO,
|
||||
Guid = userLocalEntity.Guid,
|
||||
Group = new Group{
|
||||
Id = group.Id,
|
||||
ID = group.ID,
|
||||
Name = group.Name}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
public bool RemoveUserByGuid(Guid userGuid) {
|
||||
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
||||
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
||||
}
|
||||
public User UpdateUser(User user) {
|
||||
|
||||
public User UpdateUser(User user)
|
||||
{
|
||||
UserLocalEntity userLocalEntity = new UserLocalEntity
|
||||
{
|
||||
FIO = user.FIO,
|
||||
Guid = user.Guid,
|
||||
GroupID = user.Group.Id
|
||||
GroupID = user.Group.ID
|
||||
};
|
||||
UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEntity);
|
||||
if (result == null)
|
||||
{
|
||||
throw new Exception("");
|
||||
throw new Exception("Не удалось обновить пользователя: пользователь не найден.");
|
||||
}
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => result.GroupID == it.Id);
|
||||
Group? group = GetAllGroups().FirstOrDefault(it => result.GroupID == it.ID);
|
||||
if (group == null)
|
||||
{
|
||||
throw new Exception("");
|
||||
throw new Exception("Не удалось обновить пользователя: группа не найдена.");
|
||||
}
|
||||
return new User
|
||||
{
|
||||
@ -75,6 +72,6 @@ namespace Demo.Domain.UseCase
|
||||
Guid = result.Guid,
|
||||
Group = group
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace Demo.Migrations
|
||||
{
|
||||
[DbContext(typeof(RemoteDatabaseContext))]
|
||||
[Migration("20241024202926_InitialCreate")]
|
||||
[Migration("20241028031712_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -25,24 +25,24 @@ namespace Demo.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b =>
|
||||
{
|
||||
b.Property<Guid>("UserGuid")
|
||||
.HasColumnType("uuid");
|
||||
@ -50,23 +50,23 @@ namespace Demo.Migrations
|
||||
b.Property<DateOnly>("Date")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<bool>("IsAttedance")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("LessonNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("userDaoGuid")
|
||||
b.Property<bool>("IsAttedance")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<Guid>("userDAOGuid")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("UserGuid", "Date", "IsAttedance", "LessonNumber");
|
||||
b.HasKey("UserGuid", "Date", "LessonNumber");
|
||||
|
||||
b.HasIndex("userDaoGuid");
|
||||
b.HasIndex("userDAOGuid");
|
||||
|
||||
b.ToTable("PresenceDaos");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b =>
|
||||
{
|
||||
b.Property<Guid>("Guid")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -86,21 +86,21 @@ namespace Demo.Migrations
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b =>
|
||||
{
|
||||
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", "userDao")
|
||||
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", "userDAO")
|
||||
.WithMany()
|
||||
.HasForeignKey("userDaoGuid")
|
||||
.HasForeignKey("userDAOGuid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("userDao");
|
||||
b.Navigation("userDAO");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b =>
|
||||
{
|
||||
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", "Group")
|
||||
.WithMany("User")
|
||||
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", "Group")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("GroupID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
@ -108,9 +108,9 @@ namespace Demo.Migrations
|
||||
b.Navigation("Group");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
|
||||
{
|
||||
b.Navigation("User");
|
||||
b.Navigation("Users");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
@ -16,13 +16,13 @@ namespace Demo.Migrations
|
||||
name: "Groups",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
ID = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Groups", x => x.Id);
|
||||
table.PrimaryKey("PK_Groups", x => x.ID);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
@ -40,7 +40,7 @@ namespace Demo.Migrations
|
||||
name: "FK_Users_Groups_GroupID",
|
||||
column: x => x.GroupID,
|
||||
principalTable: "Groups",
|
||||
principalColumn: "Id",
|
||||
principalColumn: "ID",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
@ -49,26 +49,26 @@ namespace Demo.Migrations
|
||||
columns: table => new
|
||||
{
|
||||
UserGuid = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
IsAttedance = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Date = table.Column<DateOnly>(type: "date", nullable: false),
|
||||
LessonNumber = table.Column<int>(type: "integer", nullable: false),
|
||||
userDaoGuid = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
IsAttedance = table.Column<bool>(type: "boolean", nullable: false),
|
||||
userDAOGuid = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PresenceDaos", x => new { x.UserGuid, x.Date, x.IsAttedance, x.LessonNumber });
|
||||
table.PrimaryKey("PK_PresenceDaos", x => new { x.UserGuid, x.Date, x.LessonNumber });
|
||||
table.ForeignKey(
|
||||
name: "FK_PresenceDaos_Users_userDaoGuid",
|
||||
column: x => x.userDaoGuid,
|
||||
name: "FK_PresenceDaos_Users_userDAOGuid",
|
||||
column: x => x.userDAOGuid,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Guid",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PresenceDaos_userDaoGuid",
|
||||
name: "IX_PresenceDaos_userDAOGuid",
|
||||
table: "PresenceDaos",
|
||||
column: "userDaoGuid");
|
||||
column: "userDAOGuid");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Users_GroupID",
|
@ -1,6 +1,6 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
@ -22,24 +22,24 @@ namespace Demo.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b =>
|
||||
{
|
||||
b.Property<Guid>("UserGuid")
|
||||
.HasColumnType("uuid");
|
||||
@ -47,23 +47,23 @@ namespace Demo.Migrations
|
||||
b.Property<DateOnly>("Date")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<bool>("IsAttedance")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("LessonNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("userDaoGuid")
|
||||
b.Property<bool>("IsAttedance")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<Guid>("userDAOGuid")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("UserGuid", "Date", "IsAttedance", "LessonNumber");
|
||||
b.HasKey("UserGuid", "Date", "LessonNumber");
|
||||
|
||||
b.HasIndex("userDaoGuid");
|
||||
b.HasIndex("userDAOGuid");
|
||||
|
||||
b.ToTable("PresenceDaos");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b =>
|
||||
{
|
||||
b.Property<Guid>("Guid")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -83,21 +83,21 @@ namespace Demo.Migrations
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b =>
|
||||
{
|
||||
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", "userDao")
|
||||
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", "userDAO")
|
||||
.WithMany()
|
||||
.HasForeignKey("userDaoGuid")
|
||||
.HasForeignKey("userDAOGuid")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("userDao");
|
||||
b.Navigation("userDAO");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b =>
|
||||
{
|
||||
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", "Group")
|
||||
.WithMany("User")
|
||||
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", "Group")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("GroupID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
@ -105,9 +105,9 @@ namespace Demo.Migrations
|
||||
b.Navigation("Group");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDao", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
|
||||
{
|
||||
b.Navigation("User");
|
||||
b.Navigation("Users");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
|
10
Program.cs
10
Program.cs
@ -1,5 +1,4 @@
|
||||
|
||||
using Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.UI;
|
||||
@ -7,7 +6,8 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
IServiceCollection services = new ServiceCollection();
|
||||
|
||||
services
|
||||
services
|
||||
|
||||
.AddDbContext<RemoteDatabaseContext>()
|
||||
.AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>()
|
||||
.AddSingleton<IUserRepository, SQLUserRepositoryImpl>()
|
||||
@ -18,6 +18,6 @@ services
|
||||
.AddSingleton<UserConsoleUI>()
|
||||
.AddSingleton<MainMenuUI>();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
MainMenuUI? mainMenuUI = serviceProvider.GetService<MainMenuUI>();
|
||||
MainMenuUI? mainMenuUI = serviceProvider.GetService<MainMenuUI>();
|
||||
|
@ -1,60 +0,0 @@
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.domain.Models;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
public class GroupConsoleUI
|
||||
{
|
||||
IGroupUseCase _groupUseCase;
|
||||
|
||||
public GroupConsoleUI(IGroupUseCase 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(string Name){
|
||||
string output = _groupUseCase.CreateGroup(Name) ? "Группа создана" : "Группа не создана";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void DisplayAllGroups()
|
||||
{
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
foreach (var group in _groupUseCase.GetAllGroups())
|
||||
{
|
||||
userOutput.AppendLine($"{group.Id}\t{group.Name}");
|
||||
}
|
||||
Console.WriteLine(userOutput);
|
||||
}
|
||||
|
||||
public void RemoveGroupById(int ID){
|
||||
string output = _groupUseCase.RemoveGroupById(ID) ? "Группа удалена" : "Группа не удалена";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void DisplayGroupByID(int ID){
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
var group = _groupUseCase.GetGroupById(ID);
|
||||
{
|
||||
userOutput.AppendLine($"{group.Id}\t{group.Name}");
|
||||
}
|
||||
Console.WriteLine(userOutput);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,11 @@
|
||||
using Demo.Domain.Models;
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
public class MainMenuUI
|
||||
{
|
||||
|
||||
|
||||
UserConsoleUI _userConsoleUI;
|
||||
GroupConsoleUI _groupConsoleUI;
|
||||
PresenceConsoleUI _presenceConsoleUI;
|
||||
@ -28,29 +23,28 @@ namespace Demo.UI
|
||||
{
|
||||
switch (Console.ReadLine())
|
||||
{
|
||||
case "1": _groupConsoleUI.DisplayAllGroups(); break;
|
||||
case "2": _groupConsoleUI.CreateNewGroup(Console.ReadLine()); break;
|
||||
case "3": _groupConsoleUI.UpdateGroupName(Group.Parse(Console.ReadLine())); break;
|
||||
case "4": _groupConsoleUI.DisplayGroupByID(Convert.ToInt32(Console.ReadLine())); break;
|
||||
case "5": _groupConsoleUI.RemoveGroupByID(Convert.ToInt32(Console.ReadLine())); break;
|
||||
|
||||
case "1": _userConsoleUI.DisplayAllUsers(); break;
|
||||
case "2": _userConsoleUI.GetUserByGuid(Guid.Parse(Console.ReadLine())); break;
|
||||
case "3": _userConsoleUI.UpdateUser(User.Parse(Console.ReadLine())); break;
|
||||
case "4": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
|
||||
|
||||
case "5": _groupConsoleUI.DisplayAllGroups(); break;
|
||||
case "6": _groupConsoleUI.CreateNewGroup(Console.ReadLine()); break;
|
||||
case "7": _groupConsoleUI.UpdateGroupName(Group.Parse(Console.ReadLine())); break;
|
||||
case "8": _groupConsoleUI.DisplayGroupByID(Convert.ToInt32(Console.ReadLine())); break;
|
||||
case "9": _groupConsoleUI.RemoveGroupById(Convert.ToInt32(Console.ReadLine())); break;
|
||||
case "6": _userConsoleUI.DisplayAllUsers(); break;
|
||||
case "7": _userConsoleUI.DisplayUserByGuid(Guid.Parse(Console.ReadLine())); break;
|
||||
case "8": _userConsoleUI.UpdateUserByGuid(User.Parse(Console.ReadLine())); break;
|
||||
case "9": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
|
||||
|
||||
case "10": Console.WriteLine("писяпопакака"); break;
|
||||
|
||||
case "10": _presenceConsoleUI.DisplayPresenceByGroup(Convert.ToInt32(Console.ReadLine())); break;
|
||||
case "11": _presenceConsoleUI.DisplayPresenceByGroupAndDate(Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break;
|
||||
case "12": _presenceConsoleUI.GeneratePresence(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break;
|
||||
case "13": _presenceConsoleUI.GeneratePresenceWeek(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break;
|
||||
case "14": _presenceConsoleUI.IsAttedance(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine())), Guid.Parse(Console.ReadLine())); break;
|
||||
case "11": _presenceConsoleUI.DisplayPresenceByGroup(Convert.ToInt32(Console.ReadLine())); break;
|
||||
case "12": _presenceConsoleUI.DisplayPresenceByGroupByTime(Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break;
|
||||
case "13": _presenceConsoleUI.GeneratePresence(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break;
|
||||
case "14": _presenceConsoleUI.GeneratePresenceWeek(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine()))); break;
|
||||
case "15": _presenceConsoleUI.IsAttedance(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()), DateOnly.FromDateTime(Convert.ToDateTime(Console.ReadLine())), Guid.Parse(Console.ReadLine())); break;
|
||||
|
||||
default: DisplayMenu();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,46 +0,0 @@
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.domain.Models;
|
||||
using System.Text;
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
|
||||
public class PresenceConsoleUI {
|
||||
|
||||
IPresenceUseCase _presenceUseCase;
|
||||
public PresenceConsoleUI (IPresenceUseCase presenceUseCase){
|
||||
_presenceUseCase = presenceUseCase;
|
||||
}
|
||||
|
||||
public void DisplayPresenceByGroup(int groupID){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach(Presence presence in _presenceUseCase.GetPresencesByGroup(groupID)){
|
||||
stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}");
|
||||
}
|
||||
Console.WriteLine(stringBuilder);
|
||||
}
|
||||
|
||||
public void DisplayPresenceByGroupAndDate(int groupID, DateOnly date){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach(Presence presence in _presenceUseCase.GetPresencesByGroupAndDate(groupID, date)){
|
||||
stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}");
|
||||
}
|
||||
Console.WriteLine(stringBuilder);
|
||||
}
|
||||
|
||||
public void GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date){
|
||||
string output = _presenceUseCase.GeneratePresence(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){
|
||||
string output = _presenceUseCase.GenerateWeekPresence(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
||||
string output = _presenceUseCase.UpdateAttedance(firstLesson, lastLesson, date, UserGuid) ? "Обновлено" : "Не обновлено";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,6 @@
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Demo.Domain.Models;
|
||||
using Demo.Domain.UseCase;
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
@ -15,12 +11,6 @@ namespace Demo.UI
|
||||
_userUseCase = userUseCase;
|
||||
}
|
||||
|
||||
public void RemoveUserByGuid(Guid guidUser) {
|
||||
|
||||
string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void DisplayAllUsers()
|
||||
{
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
@ -31,7 +21,13 @@ namespace Demo.UI
|
||||
Console.WriteLine(userOutput);
|
||||
}
|
||||
|
||||
public void UpdateUser(User user)
|
||||
public void RemoveUserByGuid(Guid guidUser) {
|
||||
|
||||
string output = _userUseCase.RemoveUserByGuid(guidUser) ? "Пользователь удален" : "Пользователь не удален";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void UpdateUserByGuid(User user)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -46,11 +42,100 @@ namespace Demo.UI
|
||||
}
|
||||
}
|
||||
|
||||
public void GetUserByGuid(Guid guid){
|
||||
public void DisplayUserByGuid(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);
|
||||
}
|
||||
}
|
||||
|
||||
public class GroupConsoleUI
|
||||
{
|
||||
IGroupUseCase _groupUseCase;
|
||||
public GroupConsoleUI(IGroupUseCase groupUseCase){
|
||||
_groupUseCase = groupUseCase;
|
||||
}
|
||||
|
||||
public void DisplayAllGroups(){
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
foreach (var group in _groupUseCase.GetAllGroups())
|
||||
{
|
||||
userOutput.AppendLine($"{group.ID}\t{group.Name}");
|
||||
}
|
||||
Console.WriteLine(userOutput);
|
||||
}
|
||||
|
||||
public void DisplayGroupByID(int ID){
|
||||
StringBuilder userOutput = new StringBuilder();
|
||||
var group = _groupUseCase.GetGroupById(ID);
|
||||
{
|
||||
userOutput.AppendLine($"{group.ID}\t{group.Name}");
|
||||
}
|
||||
Console.WriteLine(userOutput);
|
||||
}
|
||||
|
||||
public void CreateNewGroup(string Name){
|
||||
string output = _groupUseCase.CreateGroup(Name) ? "Группа создана" : "Группа не создана";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void UpdateGroupName(Group group)
|
||||
{
|
||||
try
|
||||
{
|
||||
Group output = _groupUseCase.UpdateGroup(group);
|
||||
StringBuilder groupOutput = new StringBuilder();
|
||||
groupOutput.AppendLine($"Обновленная группа: {output.ID}\t{output.Name}");
|
||||
Console.WriteLine(groupOutput);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка при обновлении группы: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveGroupByID(int ID){
|
||||
string output = _groupUseCase.RemoveGroupByID(ID) ? "Группа удалена" : "Группа не удалена";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
}
|
||||
|
||||
public class PresenceConsoleUI{
|
||||
IPresenceUseCase _presenceUseCase;
|
||||
public PresenceConsoleUI (IPresenceUseCase presenceUseCase){
|
||||
_presenceUseCase = presenceUseCase;
|
||||
}
|
||||
|
||||
public void DisplayPresenceByGroup(int groupID){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach(Presence presence in _presenceUseCase.GetPresenceByGroup(groupID)){
|
||||
stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}");
|
||||
}
|
||||
Console.WriteLine(stringBuilder);
|
||||
}
|
||||
|
||||
public void DisplayPresenceByGroupByTime(int groupID, DateOnly date){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach(Presence presence in _presenceUseCase.GetPresenceByGroupByTime(groupID, date)){
|
||||
stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}");
|
||||
}
|
||||
Console.WriteLine(stringBuilder);
|
||||
}
|
||||
|
||||
public void GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date){
|
||||
string output = _presenceUseCase.GeneratePresence(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){
|
||||
string output = _presenceUseCase.GeneratePresenceWeek(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
|
||||
public void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
|
||||
string output = _presenceUseCase.IsAttedance(firstLesson, lastLesson, date, UserGuid) ? "Обновлено" : "Не обновлено";
|
||||
Console.WriteLine(output);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user