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