Обновление проекта
This commit is contained in:
parent
9ba62b2fa2
commit
c55e680ab1
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
.vs/
|
||||
bin/
|
||||
obj/
|
||||
*.suo
|
||||
*.user
|
||||
*.log
|
||||
*.cache
|
||||
*.tmp
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,12 +1,23 @@
|
||||
{
|
||||
"Version": 1,
|
||||
"WorkspaceRootPath": "C:\\Users\\class_Student\\source\\repos\\slarny4\\",
|
||||
"WorkspaceRootPath": "C:\\Users\\\u041D\u0430\u0438\u043B\u044C\\source\\repos\\slarny4\\",
|
||||
"Documents": [],
|
||||
"DocumentGroupContainers": [
|
||||
{
|
||||
"Orientation": 0,
|
||||
"VerticalTabListWidth": 256,
|
||||
"DocumentGroups": []
|
||||
"DocumentGroups": [
|
||||
{
|
||||
"DockedWidth": 200,
|
||||
"SelectedChildIndex": -1,
|
||||
"Children": [
|
||||
{
|
||||
"$type": "Bookmark",
|
||||
"Name": "ST:0:0:{aa2115a1-9712-457b-9047-dbb71ca2cdd2}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
75
Demo1/Controllers/AdminController.cs
Normal file
75
Demo1/Controllers/AdminController.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Domain.UseCase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Demo.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class AdminController : ControllerBase
|
||||
{
|
||||
private readonly UserUseCase _userUseCase;
|
||||
private readonly GroupUseCase _groupUseCase;
|
||||
private readonly UseCasePresence _presenceUseCase;
|
||||
|
||||
public AdminController(UserUseCase userUseCase, GroupUseCase groupUseCase, UseCasePresence presenceUseCase)
|
||||
{
|
||||
_userUseCase = userUseCase;
|
||||
_groupUseCase = groupUseCase;
|
||||
_presenceUseCase = presenceUseCase;
|
||||
}
|
||||
|
||||
[HttpPost("addUser")]
|
||||
public IActionResult AddUser([FromBody] User user)
|
||||
{
|
||||
_userUseCase.UpdateUser(user);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPut("updateUser")]
|
||||
public IActionResult UpdateUser([FromBody] User user)
|
||||
{
|
||||
_userUseCase.UpdateUser(user);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpDelete("deleteUser/{id}")]
|
||||
public IActionResult DeleteUser(Guid id)
|
||||
{
|
||||
_userUseCase.DeleteUser(id);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("getUser/{id}")]
|
||||
public IActionResult GetUser(Guid id)
|
||||
{
|
||||
var user = _userUseCase.GetUserById(id);
|
||||
if (user == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Ok(user);
|
||||
}
|
||||
|
||||
[HttpGet("getAllUsers")]
|
||||
public IActionResult GetAllUsers()
|
||||
{
|
||||
var users = _userUseCase.GetAllUsers();
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("getPresenceByUser/{userId}")]
|
||||
public IActionResult GetPresenceByUser(Guid userId)
|
||||
{
|
||||
var presence = _presenceUseCase.GetPresenceByGroup(userId);
|
||||
if (presence == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Ok(presence);
|
||||
}
|
||||
}
|
||||
}
|
59
Demo1/Controllers/PresenceController.cs
Normal file
59
Demo1/Controllers/PresenceController.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Demo.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class PresenceController : ControllerBase
|
||||
{
|
||||
private readonly UseCasePresence _presenceUseCase;
|
||||
|
||||
public PresenceController(UseCasePresence presenceUseCase)
|
||||
{
|
||||
_presenceUseCase = presenceUseCase;
|
||||
}
|
||||
|
||||
[HttpGet("getPresenceByGroup")]
|
||||
public IActionResult GetPresenceByGroup([FromQuery] int groupId)
|
||||
{
|
||||
var presence = _presenceUseCase.GetPresenceByGroup(groupId);
|
||||
return Ok(presence);
|
||||
}
|
||||
|
||||
[HttpPost("addPresence")]
|
||||
public IActionResult AddPresence([FromBody] Demo.Data.RemoteData.RemoteDataBase.DAO.Presence daoPresence)
|
||||
{
|
||||
var domainPresence = new Demo.Domain.Models.Presence
|
||||
{
|
||||
Id = daoPresence.Id,
|
||||
Date = daoPresence.Date,
|
||||
LessonNumber = daoPresence.LessonNumber,
|
||||
IsAttendance = daoPresence.IsAttendance,
|
||||
UserId = daoPresence.UserId
|
||||
};
|
||||
|
||||
_presenceUseCase.PresenceRepository.AddPresence(domainPresence);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPut("markUserAsAbsent")]
|
||||
public IActionResult MarkUserAsAbsent([FromQuery] Guid userId, [FromQuery] int lessonNumber, [FromQuery] DateTime date)
|
||||
{
|
||||
_presenceUseCase.MarkUserAsAbsent(userId, lessonNumber, date);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpDelete("deletePresence")]
|
||||
public IActionResult DeletePresence([FromQuery] Guid id)
|
||||
{
|
||||
_presenceUseCase.PresenceRepository.DeletePresence(id);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,9 @@
|
||||
// C:\Users\adm\Source\Repos\presence1\Demo\Data\Exceptions\GroupNotFoundException.cs
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Demo.Data.Exceptions
|
||||
{
|
||||
public class GroupNotFoundException : Exception
|
||||
{
|
||||
public GroupNotFoundException(int groupId)
|
||||
: base($"Group with ID {groupId} was not found.")
|
||||
{
|
||||
}
|
||||
public GroupNotFoundException(string message) : base(message) { }
|
||||
}
|
||||
}
|
9
Demo1/Data/Exceptions/PresenceNotFoundException.cs
Normal file
9
Demo1/Data/Exceptions/PresenceNotFoundException.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Demo.Data.Exceptions
|
||||
{
|
||||
public class PresenceNotFoundException : Exception
|
||||
{
|
||||
public PresenceNotFoundException(string message) : base(message) { }
|
||||
}
|
||||
}
|
@ -1,13 +1,9 @@
|
||||
// C:\Users\adm\Source\Repos\presence1\Demo\Data\Exceptions\RepositoryException.cs
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Demo.Data.Exceptions
|
||||
{
|
||||
public class RepositoryException : Exception
|
||||
{
|
||||
public RepositoryException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
public RepositoryException(string message) : base(message) { }
|
||||
}
|
||||
}
|
@ -1,13 +1,9 @@
|
||||
// C:\Users\adm\Source\Repos\presence1\Demo\Data\Exceptions\UserNotFoundException.cs
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Demo.Data.Exceptions
|
||||
{
|
||||
public class UserNotFoundException : Exception
|
||||
{
|
||||
public UserNotFoundException(Guid userId)
|
||||
: base($"User with ID {userId} was not found.")
|
||||
{
|
||||
}
|
||||
public UserNotFoundException(string message) : base(message) { }
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
// Group.cs в LocalData/Entity
|
||||
namespace Demo.Data.LocalData.Entity
|
||||
namespace Demo.Data.LocalData.Entity
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty; // Инициализация по умолчанию
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
// C:\Users\class_Student\source\repos\slarny4\Demo1\Data\LocalData\Entity\Presence.cs
|
||||
using System;
|
||||
|
||||
namespace Demo.Data.LocalData.Entity
|
||||
{
|
||||
public class LocalPresence
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public DateTime ClassDate { get; set; }
|
||||
public int LessonNumber { get; set; } // Вместо ClassNumber
|
||||
public bool WasPresent { get; set; } // Вместо IsPresent
|
||||
}
|
||||
}
|
11
Demo1/Data/LocalData/Entity/Presence.cs
Normal file
11
Demo1/Data/LocalData/Entity/Presence.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace Demo.Data.LocalData.Entity
|
||||
{
|
||||
public class Presence
|
||||
{
|
||||
public Guid Id { get; set; } // Убедитесь, что тип Guid
|
||||
public DateTime Date { get; set; }
|
||||
public int LessonNumber { get; set; }
|
||||
public bool IsAttendance { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
}
|
||||
}
|
@ -1,12 +1,9 @@
|
||||
// User.cs в LocalData/Entity
|
||||
using System;
|
||||
|
||||
namespace Demo.Data.LocalData.Entity
|
||||
namespace Demo.Data.LocalData.Entity
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string FIO { get; set; } = string.Empty;
|
||||
public string FIO { get; set; } = string.Empty; // Инициализация по умолчанию
|
||||
public int GroupID { get; set; }
|
||||
}
|
||||
}
|
@ -1,29 +1,22 @@
|
||||
// C:\Users\adm\Source\Repos\presence1\Demo\Data\LocalData\LocalStaticData.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
|
||||
namespace Demo.Data.LocalData
|
||||
namespace Demo.Data.LocalData
|
||||
{
|
||||
public static class LocalStaticData
|
||||
{
|
||||
public static List<User> Users = new List<User>
|
||||
public static List<Entity.User> Users = new List<Entity.User>
|
||||
{
|
||||
new User { Id = Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), FIO = "Иванов Иван Иванович", GroupID = 1 },
|
||||
new User { Id = Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), FIO = "Петров Петр Петрович", GroupID = 2 },
|
||||
new User { Id = Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), FIO = "Мендалиев Наиль", GroupID = 3 },
|
||||
new User { Id = Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), FIO = "Сидоров Сидор Сидорович", GroupID = 1 },
|
||||
new User { Id = Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), FIO = "Кузнецов Алексей Викторович", GroupID = 2 },
|
||||
new User { Id = Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), FIO = "Смирнова Анна Сергеевна", GroupID = 3 }
|
||||
new Entity.User { Id = Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), FIO = "Иванов Иван Иванович", GroupID = 1 },
|
||||
new Entity.User { Id = Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), FIO = "Петров Петр Петрович", GroupID = 2 },
|
||||
new Entity.User { Id = Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), FIO = "Мендалиев Наиль", GroupID = 3 },
|
||||
new Entity.User { Id = Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), FIO = "Сидоров Сидор Сидорович", GroupID = 1 },
|
||||
new Entity.User { Id = Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), FIO = "Кузнецов Алексей Викторович", GroupID = 2 },
|
||||
new Entity.User { Id = Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), FIO = "Смирнова Анна Сергеевна", GroupID = 3 }
|
||||
};
|
||||
|
||||
public static List<Group> Groups = new List<Group>
|
||||
public static List<Entity.Group> Groups = new List<Entity.Group>
|
||||
{
|
||||
new Group { Id = 1, Name = "ИП1-23" },
|
||||
new Group { Id = 2, Name = "ИП1-22" },
|
||||
new Group { Id = 3, Name = "С1-23" }
|
||||
new Entity.Group { Id = 1, Name = "ИП1-23" },
|
||||
new Entity.Group { Id = 2, Name = "ИП1-22" },
|
||||
new Entity.Group { Id = 3, Name = "С1-23" }
|
||||
};
|
||||
|
||||
public static List<LocalPresence> Presences = new List<LocalPresence>();
|
||||
}
|
||||
}
|
10
Demo1/Data/RemoteData/RemoteDataBase/DAO/AttendanceRecord.cs
Normal file
10
Demo1/Data/RemoteData/RemoteDataBase/DAO/AttendanceRecord.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
{
|
||||
public class AttendanceRecord
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
public int LessonNumber { get; set; }
|
||||
public bool IsAttendance { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
}
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
// Group.cs в RemoteData/RemoteDataBase/DAO
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
{
|
||||
public class GroupDAO
|
||||
public class Group
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public UserDAO User { get; set; }
|
||||
public int Id { get; set; } // Убедитесь, что тип int
|
||||
public string Name { get; set; } = string.Empty; // Инициализация по умолчанию
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
{
|
||||
public class GroupAttendanceStatistics
|
||||
{
|
||||
public int GroupId { get; set; }
|
||||
public int TotalLessons { get; set; }
|
||||
public int TotalAttendance { get; set; }
|
||||
public double AttendancePercentage { get; set; }
|
||||
}
|
||||
}
|
@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
{
|
||||
public class PresenceDAO
|
||||
public class Presence
|
||||
{
|
||||
|
||||
public int PresenceId { get; set; } // Уникальный идентификатор записи
|
||||
public DateTime ClassDate { get; set; } // Дата занятия
|
||||
public Guid Id { get; set; } // Убедитесь, что тип Guid
|
||||
public DateTime Date { get; set; }
|
||||
public int LessonNumber { get; set; }
|
||||
public bool WasPresent { get; set; }
|
||||
public bool IsAttendance { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
}
|
||||
}
|
@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
{
|
||||
public class UserDAO
|
||||
public class User
|
||||
{
|
||||
public Guid UserId { get; set; } // Измените имя на UserId
|
||||
public string FIO { get; set; } = string.Empty;
|
||||
public Guid Id { get; set; }
|
||||
public string FIO { get; set; } = string.Empty; // Инициализация по умолчанию
|
||||
public int GroupID { get; set; }
|
||||
}
|
||||
}
|
10
Demo1/Data/RemoteData/RemoteDataBase/DAO/UserAttendance.cs
Normal file
10
Demo1/Data/RemoteData/RemoteDataBase/DAO/UserAttendance.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase.DAO
|
||||
{
|
||||
public class UserAttendance
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public int TotalLessons { get; set; }
|
||||
public int TotalAttendance { get; set; }
|
||||
public double AttendancePercentage { get; set; }
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase
|
||||
{
|
||||
public class DesignTimeDbContextFactory : DesignTimeDbContextFactoryBase<RemoteDatabaseContext>
|
||||
{
|
||||
protected override RemoteDatabaseContext CreateNewInstance(DbContextOptions<RemoteDatabaseContext> options)
|
||||
{
|
||||
return new RemoteDatabaseContext(options);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase
|
||||
{
|
||||
public abstract class DesignTimeDbContextFactoryBase<TContext> : IDesignTimeDbContextFactory<TContext> where TContext : DbContext
|
||||
{
|
||||
public TContext CreateDbContext(string[] args)
|
||||
{
|
||||
var builder = new DbContextOptionsBuilder<TContext>();
|
||||
builder.UseNpgsql("Host=45.67.56.214;Port=5421;Database=user5;Username=user5;Password=EtEJqhsf");
|
||||
|
||||
return CreateNewInstance(builder.Options);
|
||||
}
|
||||
|
||||
protected abstract TContext CreateNewInstance(DbContextOptions<TContext> options);
|
||||
}
|
||||
}
|
@ -1,8 +1,22 @@
|
||||
// C:\Users\adm\Source\Repos\presence1\Demo\Data\RemoteData\RemoteDataBase\RemoteDatabase.cs
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase
|
||||
{
|
||||
public class RemoteDatabase
|
||||
public class RemoteDatabase : DbContext
|
||||
{
|
||||
// Логика подключения к удаленной базе данных
|
||||
public DbSet<DAO.User> Users { get; set; }
|
||||
public DbSet<DAO.Group> Groups { get; set; }
|
||||
public DbSet<DAO.Presence> Presence { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Username=user5;Database=user5;Password=EtEJqhsf");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<DAO.Presence>()
|
||||
.HasKey(p => p.Id); // Указание первичного ключа
|
||||
}
|
||||
}
|
||||
}
|
@ -1,44 +1,26 @@
|
||||
using Demo.Data.LocalData.Entity; // Локальные сущности
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO; // DAO классы
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO; // Используйте правильное пространство имен
|
||||
|
||||
public class RemoteDatabaseContext : DbContext
|
||||
namespace Demo.Data.RemoteData.RemoteDataBase
|
||||
{
|
||||
public DbSet<User> User { get; set; }
|
||||
public DbSet<GroupDAO> Group { get; set; } // DbSet для GroupDao
|
||||
public DbSet<PresenceDAO> Presence { get; set; } // DbSet для PresenceDao
|
||||
|
||||
public RemoteDatabaseContext(DbContextOptions<RemoteDatabaseContext> options) : base(options) { }
|
||||
public class RemoteDatabaseContext : DbContext
|
||||
{
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<Group> Groups { get; set; }
|
||||
public DbSet<Presence> Presence { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Database=;Username=user5;Password=EtEJqhsf");
|
||||
}
|
||||
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Username=user5;Database=user5;Password=EtEJqhsf");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<GroupDAO>().HasKey(group => group.Id);
|
||||
modelBuilder.Entity<GroupDAO>().Property(group => group.Id).ValueGeneratedOnAdd();
|
||||
modelBuilder.Entity<Presence>()
|
||||
.HasKey(p => p.Id); // Указание первичного ключа
|
||||
|
||||
modelBuilder.Entity<UserDAO>().HasKey(user => user.UserId);
|
||||
modelBuilder.Entity<UserDAO>().Property(user => user.UserId).ValueGeneratedOnAdd();
|
||||
|
||||
modelBuilder.Entity<PresenceDAO>().HasKey(presence => presence.PresenceId); // Устанавливаем первичный ключ
|
||||
|
||||
// Дополнительные настройки для User
|
||||
modelBuilder.Entity<User>(entity =>
|
||||
{
|
||||
entity.ToTable("User"); // Имя таблицы
|
||||
entity.HasKey(e => e.Id); // Указываем первичный ключ
|
||||
entity.Property(e => e.FIO)
|
||||
.IsRequired()
|
||||
.HasColumnName("FIO");
|
||||
entity.Property(e => e.GroupID)
|
||||
.IsRequired()
|
||||
.HasColumnName("GroupID");
|
||||
});
|
||||
modelBuilder.Entity<Group>()
|
||||
.HasKey(g => g.Id); // Указание первичного ключа
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
// C:\Users\adm\Source\Repos\presence1\Demo\Data\Repository\GroupRepositoryImpl.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Demo.Data.Exceptions;
|
||||
using Demo.Data.LocalData;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public class GroupRepositoryImpl : IGroupRepository
|
||||
{
|
||||
private RemoteDatabaseContext context;
|
||||
|
||||
public GroupRepositoryImpl(RemoteDatabaseContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void AddGroup(Group group)
|
||||
{
|
||||
if (LocalStaticData.Groups.Any(g => g.Id == group.Id))
|
||||
throw new RepositoryException("Group with the same ID already exists.");
|
||||
LocalStaticData.Groups.Add(group);
|
||||
}
|
||||
|
||||
public void DeleteGroup(int id)
|
||||
{
|
||||
var group = GetGroupById(id);
|
||||
LocalStaticData.Groups.Remove(group);
|
||||
}
|
||||
|
||||
public IEnumerable<Group> GetAllGroups()
|
||||
{
|
||||
return LocalStaticData.Groups;
|
||||
}
|
||||
|
||||
public Group GetGroupById(int id)
|
||||
{
|
||||
var group = LocalStaticData.Groups.FirstOrDefault(g => g.Id == id);
|
||||
if (group == null)
|
||||
throw new GroupNotFoundException(id);
|
||||
return group;
|
||||
}
|
||||
|
||||
public void UpdateGroup(Group group)
|
||||
{
|
||||
var existingGroup = GetGroupById(group.Id);
|
||||
existingGroup.Name = group.Name;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
// C:\Users\adm\Source\Repos\presence1\Demo\Data\Repository\IGroupRepository.cs
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using System.Collections.Generic;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public interface IGroupRepository
|
||||
{
|
||||
IEnumerable<Group> GetAllGroups();
|
||||
Group GetGroupById(int id);
|
||||
void AddGroup(Group group);
|
||||
void UpdateGroup(Group group);
|
||||
void UpdateGroupName(int id, string name);
|
||||
void DeleteGroup(int id);
|
||||
}
|
||||
}
|
@ -1,20 +1,17 @@
|
||||
// IPresenceRepository.cs
|
||||
using Demo.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AttendanceApp.Domain.Models;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public interface IPresenceRepository
|
||||
{
|
||||
IEnumerable<LocalPresence> GetPresencesByGroupAndDate(int groupId, DateTime date);
|
||||
void AddPresence(LocalPresence presence);
|
||||
void UpdatePresence(LocalPresence presence);
|
||||
IEnumerable<LocalPresence> GetAllPresences();
|
||||
IEnumerable<LocalPresence> GetPresenceByGroup(int groupId);
|
||||
void AddPresence(Presence presence);
|
||||
IEnumerable<Presence> GetPresenceByGroup(int groupId);
|
||||
IEnumerable<Presence> GetPresenceByGroupAndDate(int groupId, DateTime date);
|
||||
void MarkUserAsAbsent(Guid userId, int lessonNumber, DateTime date);
|
||||
IEnumerable<Presence> GetAllPresence();
|
||||
void DeletePresence(Guid id);
|
||||
void UpdatePresence(Presence presence);
|
||||
// Удалите этот метод, так как он дублирует GetPresencesByGroupAndDate
|
||||
// IEnumerable<object> GetPresenceByGroupAndDate(int groupId, DateTime date);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
@ -8,8 +8,8 @@ namespace Demo.Data.Repository
|
||||
{
|
||||
IEnumerable<User> GetAllUsers();
|
||||
User GetUserById(Guid id);
|
||||
void AddUser(User user);
|
||||
void UpdateUser(User user);
|
||||
void DeleteUser(Guid id);
|
||||
void AddUser(User user);
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
// C:\Users\adm\Source\Repos\presence1\Demo\Data\Repository\PresenceRepositoryImpl.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AttendanceApp.Domain.Models;
|
||||
using Demo.Data.LocalData;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public class PresenceRepositoryImpl : IPresenceRepository
|
||||
{
|
||||
private RemoteDatabaseContext context;
|
||||
|
||||
public PresenceRepositoryImpl(RemoteDatabaseContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void AddPresence(LocalPresence presence)
|
||||
{
|
||||
LocalStaticData.Presences.Add(presence);
|
||||
}
|
||||
|
||||
public IEnumerable<LocalPresence> GetAllPresences()
|
||||
{
|
||||
return LocalStaticData.Presences;
|
||||
}
|
||||
|
||||
public IEnumerable<object> GetPresenceByGroup(int groupId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<object> GetPresenceByGroupAndDate(int groupId, DateTime date)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<LocalPresence> GetPresencesByGroupAndDate(int groupId, DateTime date)
|
||||
{
|
||||
var usersInGroup = LocalStaticData.Users.Where(u => u.GroupID == groupId).Select(u => u.Id).ToList();
|
||||
return LocalStaticData.Presences.Where(p => usersInGroup.Contains(p.UserId) && p.ClassDate.Date == date.Date);
|
||||
}
|
||||
|
||||
public void UpdatePresence(LocalPresence presence)
|
||||
{
|
||||
var existingPresence = LocalStaticData.Presences.FirstOrDefault(p =>
|
||||
p.UserId == presence.UserId &&
|
||||
p.ClassDate.Date == presence.ClassDate.Date &&
|
||||
p.LessonNumber == presence.LessonNumber);
|
||||
|
||||
if (existingPresence != null)
|
||||
{
|
||||
existingPresence.WasPresent = presence.WasPresent;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePresence(Presence presence)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IEnumerable<LocalPresence> IPresenceRepository.GetPresenceByGroup(int groupId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,48 @@
|
||||
using System;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo1.Data.Repository
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
internal class SQLGroupRepositoryImpl
|
||||
public class SQLGroupRepositoryImpl : IGroupRepository
|
||||
{
|
||||
private readonly DbContext _context;
|
||||
|
||||
public SQLGroupRepositoryImpl(DbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public IEnumerable<Group> GetAllGroups()
|
||||
{
|
||||
return _context.Set<Group>().ToList();
|
||||
}
|
||||
|
||||
public void AddGroup(Group group)
|
||||
{
|
||||
_context.Set<Group>().Add(group);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void UpdateGroupName(int id, string name)
|
||||
{
|
||||
var group = _context.Set<Group>().Find(id);
|
||||
if (group != null)
|
||||
{
|
||||
group.Name = name;
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteGroup(int id)
|
||||
{
|
||||
var group = _context.Set<Group>().Find(id);
|
||||
if (group != null)
|
||||
{
|
||||
_context.Set<Group>().Remove(group);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,120 @@
|
||||
using System;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Demo.Domain.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo1.Data.Repository
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
internal class SQLPresenceRepository
|
||||
public class SQLPresenceRepository : IPresenceRepository
|
||||
{
|
||||
private readonly DbContext _context;
|
||||
|
||||
public SQLPresenceRepository(DbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public void AddPresence(Presence presence)
|
||||
{
|
||||
presence.Date = DateTime.SpecifyKind(presence.Date, DateTimeKind.Utc);
|
||||
_context.Set<RemoteData.RemoteDataBase.DAO.Presence>().Add(new RemoteData.RemoteDataBase.DAO.Presence
|
||||
{
|
||||
Id = presence.Id,
|
||||
Date = presence.Date,
|
||||
LessonNumber = presence.LessonNumber,
|
||||
IsAttendance = presence.IsAttendance,
|
||||
UserId = presence.UserId
|
||||
});
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void AddPresence(RemoteData.RemoteDataBase.DAO.Presence presence)
|
||||
{
|
||||
presence.Date = DateTime.SpecifyKind(presence.Date, DateTimeKind.Utc);
|
||||
_context.Set<RemoteData.RemoteDataBase.DAO.Presence>().Add(presence);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public IEnumerable<Presence> GetPresenceByGroup(int groupId)
|
||||
{
|
||||
return _context.Set<RemoteData.RemoteDataBase.DAO.Presence>()
|
||||
.Where(p => _context.Set<RemoteData.RemoteDataBase.DAO.User>().Any(u => u.Id == p.UserId && u.GroupID == groupId))
|
||||
.Select(p => new Presence
|
||||
{
|
||||
Id = p.Id,
|
||||
Date = p.Date,
|
||||
LessonNumber = p.LessonNumber,
|
||||
IsAttendance = p.IsAttendance,
|
||||
UserId = p.UserId
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<Presence> GetPresenceByGroupAndDate(int groupId, DateTime date)
|
||||
{
|
||||
date = DateTime.SpecifyKind(date, DateTimeKind.Utc);
|
||||
return _context.Set<RemoteData.RemoteDataBase.DAO.Presence>()
|
||||
.Where(p => _context.Set<RemoteData.RemoteDataBase.DAO.User>().Any(u => u.Id == p.UserId && u.GroupID == groupId) && p.Date == date)
|
||||
.Select(p => new Presence
|
||||
{
|
||||
Id = p.Id,
|
||||
Date = p.Date,
|
||||
LessonNumber = p.LessonNumber,
|
||||
IsAttendance = p.IsAttendance,
|
||||
UserId = p.UserId
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void MarkUserAsAbsent(Guid userId, int lessonNumber, DateTime date)
|
||||
{
|
||||
date = DateTime.SpecifyKind(date, DateTimeKind.Utc);
|
||||
var presence = _context.Set<RemoteData.RemoteDataBase.DAO.Presence>()
|
||||
.FirstOrDefault(p => p.UserId == userId && p.LessonNumber == lessonNumber && p.Date == date);
|
||||
if (presence != null)
|
||||
{
|
||||
presence.IsAttendance = false;
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Presence> GetAllPresence()
|
||||
{
|
||||
return _context.Set<RemoteData.RemoteDataBase.DAO.Presence>()
|
||||
.Select(p => new Presence
|
||||
{
|
||||
Id = p.Id,
|
||||
Date = p.Date,
|
||||
LessonNumber = p.LessonNumber,
|
||||
IsAttendance = p.IsAttendance,
|
||||
UserId = p.UserId
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void DeletePresence(Guid id)
|
||||
{
|
||||
var presence = _context.Set<RemoteData.RemoteDataBase.DAO.Presence>().Find(id);
|
||||
if (presence != null)
|
||||
{
|
||||
_context.Set<RemoteData.RemoteDataBase.DAO.Presence>().Remove(presence);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePresence(Presence presence)
|
||||
{
|
||||
var existingPresence = _context.Set<RemoteData.RemoteDataBase.DAO.Presence>().Find(presence.Id);
|
||||
if (existingPresence != null)
|
||||
{
|
||||
existingPresence.Date = presence.Date;
|
||||
existingPresence.LessonNumber = presence.LessonNumber;
|
||||
existingPresence.IsAttendance = presence.IsAttendance;
|
||||
existingPresence.UserId = presence.UserId;
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,86 +1,50 @@
|
||||
using System;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO; // DAO User
|
||||
using UserDomain = Demo.Domain.Models.User; // Доменная модель
|
||||
using UserEntity = Demo.Data.LocalData.Entity.User; // Локальная сущность
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public class SQLUserRepositoryImpl : IUserRepository
|
||||
{
|
||||
private readonly RemoteDatabaseContext _context;
|
||||
private readonly DbContext _context;
|
||||
|
||||
public SQLUserRepositoryImpl(RemoteDatabaseContext context)
|
||||
public SQLUserRepositoryImpl(DbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public void AddUser(UserDomain user)
|
||||
public IEnumerable<User> GetAllUsers()
|
||||
{
|
||||
var daoUser = new UserEntity // Используем локальную сущность
|
||||
return _context.Set<User>().ToList();
|
||||
}
|
||||
|
||||
public User GetUserById(Guid id)
|
||||
{
|
||||
Id = user.Id,
|
||||
FIO = user.FIO,
|
||||
GroupID = user.GroupID
|
||||
};
|
||||
_context.User.Add(daoUser);
|
||||
return _context.Set<User>().Find(id);
|
||||
}
|
||||
|
||||
public void UpdateUser(User user)
|
||||
{
|
||||
_context.Set<User>().Update(user);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public IEnumerable<UserDomain> GetAllUser()
|
||||
{
|
||||
return _context.User.Select(u => new UserDomain
|
||||
{
|
||||
Id = u.Id,
|
||||
FIO = u.FIO,
|
||||
GroupID = u.GroupID
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public UserDomain GetUserById(Guid id)
|
||||
{
|
||||
var daoUser = _context.User.Find(id);
|
||||
if (daoUser == null) return null;
|
||||
|
||||
return new UserDomain
|
||||
{
|
||||
Id = daoUser.Id,
|
||||
FIO = daoUser.FIO,
|
||||
GroupID = daoUser.GroupID
|
||||
};
|
||||
}
|
||||
|
||||
public void UpdateUser(UserDomain user)
|
||||
{
|
||||
var daoUser = _context.User.Find(user.Id);
|
||||
if (daoUser != null)
|
||||
{
|
||||
daoUser.FIO = user.FIO;
|
||||
daoUser.GroupID = user.GroupID;
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteUser(Guid id)
|
||||
{
|
||||
var daoUser = _context.User.Find(id);
|
||||
if (daoUser != null)
|
||||
var user = _context.Set<User>().Find(id);
|
||||
if (user != null)
|
||||
{
|
||||
_context.User.Remove(daoUser);
|
||||
_context.Set<User>().Remove(user);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
// Реализуем метод GetAllUsers
|
||||
public IEnumerable<UserDomain> GetAllUsers()
|
||||
public void AddUser(User user)
|
||||
{
|
||||
return _context.User.Select(u => new UserDomain
|
||||
{
|
||||
Id = u.Id,
|
||||
FIO = u.FIO,
|
||||
GroupID = u.GroupID
|
||||
}).ToList();
|
||||
_context.Set<User>().Add(user);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Demo.Domain.Models;
|
||||
using Demo.Data.LocalData;
|
||||
|
||||
namespace Demo.Data.Repository
|
||||
{
|
||||
public class UserRepositoryImpl : IUserRepository
|
||||
{
|
||||
public IEnumerable<User> GetAllUsers()
|
||||
{
|
||||
return LocalStaticData.Users.Select(u => new User
|
||||
{
|
||||
Id = u.Id,
|
||||
FIO = u.FIO,
|
||||
GroupID = u.GroupID
|
||||
});
|
||||
}
|
||||
|
||||
public User GetUserById(Guid id)
|
||||
{
|
||||
var localUser = LocalStaticData.Users.FirstOrDefault(u => u.Id == id);
|
||||
if (localUser == null)
|
||||
throw new Exception("User not found");
|
||||
|
||||
return new User
|
||||
{
|
||||
Id = localUser.Id,
|
||||
FIO = localUser.FIO,
|
||||
GroupID = localUser.GroupID
|
||||
};
|
||||
}
|
||||
|
||||
public void AddUser(User user)
|
||||
{
|
||||
var localUser = new LocalData.Entity.User
|
||||
{
|
||||
Id = user.Id,
|
||||
FIO = user.FIO,
|
||||
GroupID = user.GroupID
|
||||
};
|
||||
LocalStaticData.Users.Add(localUser);
|
||||
}
|
||||
|
||||
public void UpdateUser(User user)
|
||||
{
|
||||
var localUser = LocalStaticData.Users.FirstOrDefault(u => u.Id == user.Id);
|
||||
if (localUser == null)
|
||||
throw new Exception("User not found");
|
||||
|
||||
localUser.FIO = user.FIO;
|
||||
localUser.GroupID = user.GroupID;
|
||||
}
|
||||
|
||||
public void DeleteUser(Guid id)
|
||||
{
|
||||
var user = LocalStaticData.Users.FirstOrDefault(u => u.Id == id);
|
||||
if (user != null)
|
||||
{
|
||||
LocalStaticData.Users.Remove(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=45.67.56.214;Port=5421;Database=user5;Username=user5;Password=EtEJqhsf"
|
||||
}
|
||||
}
|
36
Demo1/DataInitializer.cs
Normal file
36
Demo1/DataInitializer.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Demo
|
||||
{
|
||||
public class DataInitializer
|
||||
{
|
||||
public static void Initialize(RemoteDatabaseContext context)
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
if (context.Groups.Any() || context.Users.Any())
|
||||
{
|
||||
return; // База данных уже содержит данные
|
||||
}
|
||||
|
||||
context.Users.AddRange(
|
||||
new User { Id = Guid.Parse("e6b9964d-ea9f-420a-84b9-af9633bbfab9"), FIO = "Иванов Иван Иванович", GroupID = 1 },
|
||||
new User { Id = Guid.Parse("8388d931-5bef-41be-a152-78f1aca980ed"), FIO = "Петров Петр Петрович", GroupID = 2 },
|
||||
new User { Id = Guid.Parse("ed174548-49ed-4503-a902-c970cbf27173"), FIO = "Мендалиев Наиль", GroupID = 3 },
|
||||
new User { Id = Guid.Parse("614c0a23-5bd5-43ae-b48e-d5750afbc282"), FIO = "Сидоров Сидор Сидорович", GroupID = 1 },
|
||||
new User { Id = Guid.Parse("efcc1473-c116-4244-b3f7-f2341a5c3003"), FIO = "Кузнецов Алексей Викторович", GroupID = 2 },
|
||||
new User { Id = Guid.Parse("60640fb3-ace2-4cad-81d5-a0a58bc2dbbd"), FIO = "Смирнова Анна Сергеевна", GroupID = 3 }
|
||||
);
|
||||
|
||||
context.Groups.AddRange(
|
||||
new Group { Id = 1, Name = "ИП1-23" },
|
||||
new Group { Id = 2, Name = "ИП1-22" },
|
||||
new Group { Id = 3, Name = "С1-23" }
|
||||
);
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
33
Demo1/Demo1 - Backup.csproj
Normal file
33
Demo1/Demo1 - Backup.csproj
Normal file
@ -0,0 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ClosedXML" Version="0.104.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Data\RemoteData\RemoteApi\" />
|
||||
<Folder Include="Excel\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -8,24 +8,52 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Dockerfile.dockerignore" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ClosedXML" Version="0.104.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.DataAnnotations" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.6.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.6.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Data\RemoteData\RemoteApi\" />
|
||||
<Folder Include="Migrations\" />
|
||||
<Folder Include="Excel\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,5 +1,8 @@
|
||||
public class Group
|
||||
namespace Demo.Domain.Models
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty; // Добавляем значение по умолчанию
|
||||
public string Name { get; set; } = string.Empty; // Инициализация по умолчанию
|
||||
}
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace AttendanceApp.Domain.Models
|
||||
namespace Demo.Domain.Models
|
||||
{
|
||||
public class Presence
|
||||
{
|
||||
public DateTime ClassDate { get; set; }
|
||||
public int ClassNumber { get; set; }
|
||||
public bool IsPresent { get; set; }
|
||||
public Guid Id { get; set; } // Убедитесь, что тип Guid
|
||||
public DateTime Date { get; set; }
|
||||
public int LessonNumber { get; set; }
|
||||
public bool IsAttendance { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public bool WasPresent { get; internal set; }
|
||||
public int LessonNumber { get; internal set; }
|
||||
}
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Demo.Domain.Models
|
||||
namespace Demo.Domain.Models
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string FIO { get; set; } = string.Empty;
|
||||
public string FIO { get; set; } = string.Empty; // Инициализация по умолчанию
|
||||
public int GroupID { get; set; }
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
// C:\Users\class_Student\source\repos\slarny4\Demo1\Domain\UseCase\GroupUseCase.cs
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
using Demo.Data.Repository;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
@ -20,26 +18,19 @@ namespace Demo.Domain.UseCase
|
||||
return _groupRepository.GetAllGroups();
|
||||
}
|
||||
|
||||
public Group GetGroupById(int id)
|
||||
{
|
||||
return _groupRepository.GetGroupById(id);
|
||||
}
|
||||
|
||||
public void AddGroup(Group group)
|
||||
{
|
||||
_groupRepository.AddGroup(group);
|
||||
}
|
||||
|
||||
public void UpdateGroup(Group group)
|
||||
public void UpdateGroupName(int id, string name)
|
||||
{
|
||||
_groupRepository.UpdateGroup(group);
|
||||
_groupRepository.UpdateGroupName(id, name);
|
||||
}
|
||||
|
||||
public void DeleteGroup(int id)
|
||||
{
|
||||
_groupRepository.DeleteGroup(id);
|
||||
}
|
||||
|
||||
// Дополнительные методы, если нужны
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
// C:\Users\class_Student\source\repos\slarny4\Demo1\Domain\UseCase\PresenceUseCase.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
using Demo.Data.Repository;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
public class PresenceUseCase
|
||||
{
|
||||
private readonly IPresenceRepository _presenceRepository;
|
||||
private readonly IGroupRepository _groupRepository;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public PresenceUseCase(IPresenceRepository presenceRepository, IGroupRepository groupRepository, IUserRepository userRepository)
|
||||
{
|
||||
_presenceRepository = presenceRepository;
|
||||
_groupRepository = groupRepository;
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
public IEnumerable<LocalPresence> GetPresencesByGroupAndDate(int groupId, DateTime date)
|
||||
{
|
||||
return _presenceRepository.GetPresencesByGroupAndDate(groupId, date);
|
||||
}
|
||||
|
||||
public void MarkUserAbsent(Guid userId, int lessonNumber, DateTime date)
|
||||
{
|
||||
var presence = _presenceRepository.GetAllPresences();
|
||||
foreach (var p in presence)
|
||||
{
|
||||
if (p.UserId == userId && p.ClassDate.Date == date.Date && p.LessonNumber == lessonNumber)
|
||||
{
|
||||
p.WasPresent = false;
|
||||
_presenceRepository.UpdatePresence(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<LocalPresence> GetAllPresences()
|
||||
{
|
||||
return _presenceRepository.GetAllPresences();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
// C:\Users\adm\Source\Repos\presence1\Demo\Domain\UseCase\UseCaseGeneratePresence.cs
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using Demo.Domain.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Demo.Data.LocalData;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
using Demo.Data.Repository;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
@ -14,46 +13,47 @@ namespace Demo.Domain.UseCase
|
||||
|
||||
public UseCaseGeneratePresence(IPresenceRepository presenceRepository, IUserRepository userRepository)
|
||||
{
|
||||
_presenceRepository = presenceRepository;
|
||||
_userRepository = userRepository;
|
||||
_presenceRepository = presenceRepository ?? throw new ArgumentNullException(nameof(presenceRepository));
|
||||
_userRepository = userRepository ?? throw new ArgumentNullException(nameof(userRepository));
|
||||
}
|
||||
|
||||
public void GenerateDailyPresence(int groupId, int firstLesson, int lastLesson, DateTime date)
|
||||
public void GeneratePresenceForToday(int firstLesson, int lastLesson, int groupId, DateTime date)
|
||||
{
|
||||
var users = _userRepository.GetAllUsers().Where(u => u.GroupID == groupId).ToList();
|
||||
|
||||
date = DateTime.SpecifyKind(date, DateTimeKind.Utc);
|
||||
var users = _userRepository.GetAllUsers().Where(u => u.GroupID == groupId);
|
||||
foreach (var user in users)
|
||||
{
|
||||
for (int lesson = firstLesson; lesson <= lastLesson; lesson++)
|
||||
{
|
||||
var existing = LocalStaticData.Presences.FirstOrDefault(p =>
|
||||
p.UserId == user.Id &&
|
||||
p.ClassDate.Date == date.Date &&
|
||||
p.LessonNumber == lesson);
|
||||
|
||||
if (existing == null)
|
||||
var daoPresence = new Demo.Data.RemoteData.RemoteDataBase.DAO.Presence
|
||||
{
|
||||
var presence = new LocalPresence
|
||||
{
|
||||
UserId = user.Id,
|
||||
ClassDate = date.Date,
|
||||
Id = Guid.NewGuid(),
|
||||
Date = date,
|
||||
LessonNumber = lesson,
|
||||
WasPresent = true
|
||||
IsAttendance = true,
|
||||
UserId = user.Id
|
||||
};
|
||||
_presenceRepository.AddPresence(presence);
|
||||
}
|
||||
|
||||
var domainPresence = new Demo.Domain.Models.Presence
|
||||
{
|
||||
Id = daoPresence.Id,
|
||||
Date = daoPresence.Date,
|
||||
LessonNumber = daoPresence.LessonNumber,
|
||||
IsAttendance = daoPresence.IsAttendance,
|
||||
UserId = daoPresence.UserId
|
||||
};
|
||||
|
||||
_presenceRepository.AddPresence(domainPresence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateWeeklyPresence(int groupId, int firstLesson, int lastLesson, DateTime startDate)
|
||||
public void GeneratePresenceForWeek(int firstLesson, int lastLesson, int groupId, DateTime startDate)
|
||||
{
|
||||
startDate = DateTime.SpecifyKind(startDate, DateTimeKind.Utc);
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
var date = startDate.AddDays(i);
|
||||
if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
|
||||
continue; // Пропускаем выходные
|
||||
GenerateDailyPresence(groupId, firstLesson, lastLesson, date);
|
||||
GeneratePresenceForToday(firstLesson, lastLesson, groupId, startDate.AddDays(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
56
Demo1/Domain/UseCase/UseCasePresence.cs
Normal file
56
Demo1/Domain/UseCase/UseCasePresence.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
public class UseCasePresence
|
||||
{
|
||||
private readonly IPresenceRepository _presenceRepository;
|
||||
|
||||
public UseCasePresence(IPresenceRepository presenceRepository)
|
||||
{
|
||||
_presenceRepository = presenceRepository;
|
||||
}
|
||||
|
||||
public IPresenceRepository PresenceRepository => _presenceRepository;
|
||||
|
||||
public IEnumerable<Presence> GetPresenceByGroup(int groupId)
|
||||
{
|
||||
return _presenceRepository.GetPresenceByGroup(groupId)
|
||||
.Select(p => new Presence
|
||||
{
|
||||
Id = p.Id,
|
||||
Date = p.Date,
|
||||
LessonNumber = p.LessonNumber,
|
||||
IsAttendance = p.IsAttendance,
|
||||
UserId = p.UserId
|
||||
});
|
||||
}
|
||||
|
||||
public IEnumerable<Presence> GetPresenceByGroupAndDate(int groupId, DateTime date)
|
||||
{
|
||||
return _presenceRepository.GetPresenceByGroupAndDate(groupId, date)
|
||||
.Select(p => new Presence
|
||||
{
|
||||
Id = p.Id,
|
||||
Date = p.Date,
|
||||
LessonNumber = p.LessonNumber,
|
||||
IsAttendance = p.IsAttendance,
|
||||
UserId = p.UserId
|
||||
});
|
||||
}
|
||||
|
||||
public void MarkUserAsAbsent(Guid userId, int lessonNumber, DateTime date)
|
||||
{
|
||||
_presenceRepository.MarkUserAsAbsent(userId, lessonNumber, date);
|
||||
}
|
||||
|
||||
internal object GetPresenceByGroup(Guid userId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Demo.Data.LocalData.Entity; // Убедитесь, что это пространство имен присутствует
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo.Domain.UseCase
|
||||
{
|
||||
@ -15,30 +14,26 @@ namespace Demo.Domain.UseCase
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
public IEnumerable<Domain.Models.User> GetAllUsers()
|
||||
public IUserRepository UserRepository => _userRepository;
|
||||
|
||||
public IEnumerable<User> GetAllUsers()
|
||||
{
|
||||
return _userRepository.GetAllUsers();
|
||||
}
|
||||
|
||||
public void AddUser(Domain.Models.User user)
|
||||
{
|
||||
_userRepository.AddUser(user);
|
||||
}
|
||||
|
||||
// Пример исправления
|
||||
public Domain.Models.User GetUserById(Guid id)
|
||||
public User GetUserById(Guid id)
|
||||
{
|
||||
return _userRepository.GetUserById(id);
|
||||
}
|
||||
|
||||
internal void DeleteUser(Guid userId)
|
||||
public void UpdateUser(User user)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_userRepository.UpdateUser(user);
|
||||
}
|
||||
|
||||
internal void UpdateUser(Models.User user)
|
||||
public void DeleteUser(Guid id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_userRepository.DeleteUser(id);
|
||||
}
|
||||
}
|
||||
}
|
BIN
Demo1/Excel/GroupInfo.xlsx
Normal file
BIN
Demo1/Excel/GroupInfo.xlsx
Normal file
Binary file not shown.
@ -1,99 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Demo1.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class create : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Presence",
|
||||
columns: table => new
|
||||
{
|
||||
PresenceId = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ClassDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
LessonNumber = table.Column<int>(type: "integer", nullable: false),
|
||||
WasPresent = table.Column<bool>(type: "boolean", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Presence", x => x.PresenceId);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "User",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
FIO = table.Column<string>(type: "text", nullable: false),
|
||||
GroupID = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_User", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "UserDAO",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
FIO = table.Column<string>(type: "text", nullable: false),
|
||||
GroupID = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_UserDAO", x => x.UserId);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Group",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Group", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Group_UserDAO_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "UserDAO",
|
||||
principalColumn: "UserId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Group_UserId",
|
||||
table: "Group",
|
||||
column: "UserId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Group");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Presence");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "User");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "UserDAO");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
@ -11,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace Demo1.Migrations
|
||||
{
|
||||
[DbContext(typeof(RemoteDatabaseContext))]
|
||||
[Migration("20241114100437_create")]
|
||||
partial class create
|
||||
[Migration("20241123030700_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -24,27 +25,7 @@ namespace Demo1.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Demo.Data.LocalData.Entity.User", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("FIO");
|
||||
|
||||
b.Property<int>("GroupID")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("GroupID");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("User", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.Group", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -56,44 +37,37 @@ namespace Demo1.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Group");
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.Presence", b =>
|
||||
{
|
||||
b.Property<int>("PresenceId")
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
.HasColumnType("uuid");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("PresenceId"));
|
||||
|
||||
b.Property<DateTime>("ClassDate")
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("IsAttendance")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("LessonNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<bool>("WasPresent")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.HasKey("PresenceId");
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Presence");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.User", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
@ -104,20 +78,9 @@ namespace Demo1.Migrations
|
||||
b.Property<int>("GroupID")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("UserId");
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("UserDAO");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
|
||||
{
|
||||
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
b.ToTable("Users");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
70
Demo1/Migrations/20241123030700_InitialCreate.cs
Normal file
70
Demo1/Migrations/20241123030700_InitialCreate.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Demo1.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Groups",
|
||||
columns: table => new
|
||||
{
|
||||
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);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Presence",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
LessonNumber = table.Column<int>(type: "integer", nullable: false),
|
||||
IsAttendance = table.Column<bool>(type: "boolean", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Presence", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
FIO = table.Column<string>(type: "text", nullable: false),
|
||||
GroupID = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Groups");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Presence");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
@ -21,27 +22,7 @@ namespace Demo1.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Demo.Data.LocalData.Entity.User", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("FIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("FIO");
|
||||
|
||||
b.Property<int>("GroupID")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("GroupID");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("User", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.Group", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -53,44 +34,37 @@ namespace Demo1.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Group");
|
||||
b.ToTable("Groups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.PresenceDAO", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.Presence", b =>
|
||||
{
|
||||
b.Property<int>("PresenceId")
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
.HasColumnType("uuid");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("PresenceId"));
|
||||
|
||||
b.Property<DateTime>("ClassDate")
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("IsAttendance")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("LessonNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<bool>("WasPresent")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.HasKey("PresenceId");
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Presence");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", b =>
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.User", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
@ -101,20 +75,9 @@ namespace Demo1.Migrations
|
||||
b.Property<int>("GroupID")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("UserId");
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("UserDAO");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Demo.Data.RemoteData.RemoteDataBase.DAO.GroupDAO", b =>
|
||||
{
|
||||
b.HasOne("Demo.Data.RemoteData.RemoteDataBase.DAO.UserDAO", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
b.ToTable("Users");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
|
@ -1,4 +1,13 @@
|
||||
using Demo.UI;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Domain.UseCase;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Demo.Domain.Models;
|
||||
|
||||
namespace Demo
|
||||
{
|
||||
@ -6,8 +15,78 @@ namespace Demo
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
MainMenu menu = new MainMenu();
|
||||
menu.Show();
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Добавляем сервисы в контейнер
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddScoped<IUserRepository, SQLUserRepositoryImpl>();
|
||||
builder.Services.AddScoped<IGroupRepository, SQLGroupRepositoryImpl>();
|
||||
builder.Services.AddScoped<IPresenceRepository, SQLPresenceRepository>();
|
||||
builder.Services.AddScoped<UserUseCase>();
|
||||
builder.Services.AddScoped<GroupUseCase>();
|
||||
builder.Services.AddScoped<UseCasePresence>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Настройка конвейера обработки запросов
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
|
||||
// Инициализация данных
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var services = scope.ServiceProvider;
|
||||
var dbContext = new RemoteDatabaseContext();
|
||||
DataInitializer.Initialize(dbContext);
|
||||
}
|
||||
|
||||
// Запуск консольного меню
|
||||
var context = new RemoteDatabaseContext();
|
||||
var userRepository = new SQLUserRepositoryImpl(context);
|
||||
var groupRepository = new SQLGroupRepositoryImpl(context);
|
||||
var presenceRepository = new SQLPresenceRepository(context);
|
||||
|
||||
var userUseCase = new UserUseCase(userRepository);
|
||||
var groupUseCase = new GroupUseCase(groupRepository);
|
||||
var presenceUseCase = new UseCasePresence(presenceRepository);
|
||||
|
||||
var userConsole = new UserConsole(userUseCase);
|
||||
var groupConsole = new GroupConsole(groupUseCase);
|
||||
var presenceConsole = new PresenceConsole(presenceUseCase, userUseCase); // Передаем userUseCase
|
||||
var excelExporter = new ExcelExporter();
|
||||
|
||||
// Создаем данные для экспорта
|
||||
var group = new Group { Name = "Group 1" };
|
||||
var users = new List<User> { new User { Id = Guid.NewGuid(), FIO = "User 1" } }; // Используем Guid для Id
|
||||
var presence = new List<Presence> { new Presence { UserId = users[0].Id, IsAttendance = true } };
|
||||
|
||||
// Указываем путь для сохранения файла
|
||||
string directoryPath = @"C:\Users\Наиль\Source\Repos\slarny4\Demo1\Excel";
|
||||
string filePath = Path.Combine(directoryPath, "GroupInfo.xlsx");
|
||||
|
||||
// Проверяем, существует ли директория, и если нет, создаем её
|
||||
if (!Directory.Exists(directoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
|
||||
// Вызываем метод для экспорта данных в Excel
|
||||
excelExporter.ExportGroupInfoToExcel(group, users, presence, filePath);
|
||||
|
||||
var mainMenu = new MainMenu(userConsole, groupConsole, presenceConsole, excelExporter, groupUseCase, userUseCase, presenceUseCase);
|
||||
mainMenu.ShowMenu();
|
||||
|
||||
// Запуск веб-сервера
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
95
Demo1/UI/ExcelExporter.cs
Normal file
95
Demo1/UI/ExcelExporter.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using ClosedXML.Excel;
|
||||
using Demo.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
public class ExcelExporter
|
||||
{
|
||||
public void ExportGroupInfoToExcel(Group group, List<User> users, List<Presence> presence, string filePath)
|
||||
{
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("Group Info");
|
||||
|
||||
worksheet.Cell(1, 1).Value = "Group Name";
|
||||
worksheet.Cell(1, 2).Value = group.Name;
|
||||
|
||||
worksheet.Cell(3, 1).Value = "Student Name";
|
||||
worksheet.Cell(3, 2).Value = "Attended Lessons";
|
||||
worksheet.Cell(3, 3).Value = "Missed Lessons";
|
||||
worksheet.Cell(3, 4).Value = "Attendance Percentage";
|
||||
|
||||
int row = 4;
|
||||
foreach (var user in users)
|
||||
{
|
||||
var userPresence = presence.Where(p => p.UserId == user.Id).ToList();
|
||||
int attended = userPresence.Count(p => p.IsAttendance);
|
||||
int missed = userPresence.Count(p => !p.IsAttendance);
|
||||
double percentage = (attended * 100.0) / (attended + missed);
|
||||
|
||||
worksheet.Cell(row, 1).Value = user.FIO;
|
||||
worksheet.Cell(row, 2).Value = attended;
|
||||
worksheet.Cell(row, 3).Value = missed;
|
||||
worksheet.Cell(row, 4).Value = percentage;
|
||||
|
||||
if (percentage < 40)
|
||||
{
|
||||
worksheet.Row(row).Style.Fill.BackgroundColor = XLColor.Red;
|
||||
}
|
||||
|
||||
row++;
|
||||
}
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
Console.WriteLine($"Отчёт экспортирован в Excel: {filePath}");
|
||||
}
|
||||
|
||||
// Реализация метода для DAO моделей
|
||||
internal void ExportGroupInfoToExcel(Data.RemoteData.RemoteDataBase.DAO.Group groupForExport, List<Data.RemoteData.RemoteDataBase.DAO.User> usersForExport, List<Presence> presenceForExport, string filePath)
|
||||
{
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("Group Info DAO");
|
||||
|
||||
worksheet.Cell(1, 1).Value = "Group Name";
|
||||
worksheet.Cell(1, 2).Value = groupForExport.Name;
|
||||
|
||||
worksheet.Cell(3, 1).Value = "Student Name";
|
||||
worksheet.Cell(3, 2).Value = "Attended Lessons";
|
||||
worksheet.Cell(3, 3).Value = "Missed Lessons";
|
||||
worksheet.Cell(3, 4).Value = "Attendance Percentage";
|
||||
|
||||
int row = 4;
|
||||
foreach (var user in usersForExport)
|
||||
{
|
||||
var userPresence = presenceForExport.Where(p => p.UserId == user.Id).ToList();
|
||||
int attended = userPresence.Count(p => p.IsAttendance);
|
||||
int missed = userPresence.Count(p => !p.IsAttendance);
|
||||
double percentage = (attended * 100.0) / (attended + missed);
|
||||
|
||||
worksheet.Cell(row, 1).Value = user.FIO;
|
||||
worksheet.Cell(row, 2).Value = attended;
|
||||
worksheet.Cell(row, 3).Value = missed;
|
||||
worksheet.Cell(row, 4).Value = percentage;
|
||||
|
||||
if (percentage < 40)
|
||||
{
|
||||
worksheet.Row(row).Style.Fill.BackgroundColor = XLColor.Red;
|
||||
}
|
||||
|
||||
row++;
|
||||
}
|
||||
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
|
||||
Console.WriteLine($"Отчёт экспортирован в Excel: {filePath}");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO; // Используйте правильное пространство имен
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
using Demo.Data.Exceptions;
|
||||
namespace AttendanceApp.UI
|
||||
using System;
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
public class GroupConsole
|
||||
{
|
||||
@ -14,141 +13,25 @@ namespace AttendanceApp.UI
|
||||
_groupUseCase = groupUseCase;
|
||||
}
|
||||
|
||||
public void ShowAllGroups()
|
||||
public void DisplayAllGroups()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Список всех групп ===");
|
||||
var groups = _groupUseCase.GetAllGroups();
|
||||
foreach (var group in groups)
|
||||
{
|
||||
Console.WriteLine($"ID: {group.Id} | Название: {group.Name}");
|
||||
Console.WriteLine($"ID: {group.Id}, Name: {group.Name}");
|
||||
}
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
public void AddGroup()
|
||||
public void AddGroup(Group group)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Добавление новой группы ===");
|
||||
Console.Write("Введите название группы: ");
|
||||
var groupName = Console.ReadLine();
|
||||
if (!string.IsNullOrWhiteSpace(groupName))
|
||||
{
|
||||
var newGroup = new Group
|
||||
{
|
||||
Id = GenerateNewGroupId(),
|
||||
Name = groupName
|
||||
};
|
||||
_groupUseCase.AddGroup(newGroup);
|
||||
Console.WriteLine("Группа успешно добавлена.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Название группы не может быть пустым.");
|
||||
}
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
_groupUseCase.AddGroup(group);
|
||||
Console.WriteLine("Group added.");
|
||||
}
|
||||
|
||||
private int GenerateNewGroupId()
|
||||
public void UpdateGroupName(int id, string name)
|
||||
{
|
||||
var groups = _groupUseCase.GetAllGroups();
|
||||
if (groups != null && groups.Any())
|
||||
{
|
||||
return groups.Max(g => g.Id) + 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void UpdateGroup()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Обновление группы ===");
|
||||
Console.Write("Введите ID группы: ");
|
||||
var input = Console.ReadLine();
|
||||
if (int.TryParse(input, out int groupId))
|
||||
{
|
||||
try
|
||||
{
|
||||
var group = _groupUseCase.GetGroupById(groupId);
|
||||
Console.WriteLine($"Текущее название группы: {group.Name}");
|
||||
Console.Write("Введите новое название группы: ");
|
||||
var newName = Console.ReadLine();
|
||||
if (!string.IsNullOrWhiteSpace(newName))
|
||||
{
|
||||
group.Name = newName;
|
||||
_groupUseCase.UpdateGroup(group);
|
||||
Console.WriteLine("Группа успешно обновлена.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Название группы не может быть пустым.");
|
||||
}
|
||||
}
|
||||
catch (GroupNotFoundException ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ID группы.");
|
||||
}
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
public void DeleteGroup()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Удаление группы ===");
|
||||
Console.Write("Введите ID группы: ");
|
||||
var input = Console.ReadLine();
|
||||
if (int.TryParse(input, out int groupId))
|
||||
{
|
||||
try
|
||||
{
|
||||
_groupUseCase.DeleteGroup(groupId);
|
||||
Console.WriteLine("Группа успешно удалена.");
|
||||
}
|
||||
catch (GroupNotFoundException ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ID группы.");
|
||||
}
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
public void FindGroupById()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Поиск группы по ID ===");
|
||||
Console.Write("Введите ID группы: ");
|
||||
var input = Console.ReadLine();
|
||||
if (int.TryParse(input, out int groupId))
|
||||
{
|
||||
try
|
||||
{
|
||||
var group = _groupUseCase.GetGroupById(groupId);
|
||||
Console.WriteLine($"ID: {group.Id} | Название: {group.Name}");
|
||||
}
|
||||
catch (GroupNotFoundException ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ID группы.");
|
||||
}
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
_groupUseCase.UpdateGroupName(id, name);
|
||||
Console.WriteLine("Group name updated.");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,524 +1,358 @@
|
||||
// C:\Users\class_Student\source\repos\slarny4\Demo1\UI\MainMenu.cs
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Demo.Domain.Models;
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
using Demo.Data.RemoteData.RemoteDataBase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||||
using System.IO;
|
||||
|
||||
namespace Demo.UI
|
||||
{
|
||||
public class MainMenu
|
||||
{
|
||||
private readonly UserUseCase _userUseCase;
|
||||
private readonly UserConsole _userConsole;
|
||||
private readonly GroupConsole _groupConsole;
|
||||
private readonly PresenceConsole _presenceConsole;
|
||||
private readonly ExcelExporter _excelExporter;
|
||||
private readonly GroupUseCase _groupUseCase;
|
||||
private readonly UseCaseGeneratePresence _presenceGenerator;
|
||||
private readonly PresenceUseCase _presenceUseCase;
|
||||
private readonly UserUseCase _userUseCase;
|
||||
private readonly UseCasePresence _presenceUseCase;
|
||||
|
||||
private readonly RemoteDatabaseContext _context;
|
||||
|
||||
public MainMenu(RemoteDatabaseContext context = null)
|
||||
public MainMenu(UserConsole userConsole, GroupConsole groupConsole, PresenceConsole presenceConsole, ExcelExporter excelExporter, GroupUseCase groupUseCase, UserUseCase userUseCase, UseCasePresence presenceUseCase)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
// Если контекст не предоставлен, создаем новый
|
||||
var optionsBuilder = new DbContextOptionsBuilder<RemoteDatabaseContext>();
|
||||
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Database=user5;Username=user5;Password=EtEJqhsf");
|
||||
_context = new RemoteDatabaseContext(optionsBuilder.Options);
|
||||
}
|
||||
else
|
||||
{
|
||||
_context = context;
|
||||
_userConsole = userConsole;
|
||||
_groupConsole = groupConsole;
|
||||
_presenceConsole = presenceConsole;
|
||||
_excelExporter = excelExporter;
|
||||
_groupUseCase = groupUseCase;
|
||||
_userUseCase = userUseCase;
|
||||
_presenceUseCase = presenceUseCase;
|
||||
}
|
||||
|
||||
// Инициализация репозиториев
|
||||
IUserRepository userRepository = new SQLUserRepositoryImpl(_context);
|
||||
IGroupRepository groupRepository = new GroupRepositoryImpl(_context);
|
||||
IPresenceRepository presenceRepository = new PresenceRepositoryImpl(_context);
|
||||
|
||||
// Инициализация use cases
|
||||
_userUseCase = new UserUseCase(userRepository);
|
||||
_groupUseCase = new GroupUseCase(groupRepository);
|
||||
_presenceGenerator = new UseCaseGeneratePresence(presenceRepository, userRepository);
|
||||
_presenceUseCase = new PresenceUseCase(presenceRepository, groupRepository, userRepository);
|
||||
}
|
||||
|
||||
public void Show()
|
||||
public void ShowMenu()
|
||||
{
|
||||
bool exit = false;
|
||||
while (!exit)
|
||||
while (true)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Учёт Посещаемости ===");
|
||||
Console.WriteLine("1. Показать всех пользователей");
|
||||
Console.WriteLine("2. Удалить пользователя по GUID");
|
||||
Console.WriteLine("3. Обновить пользователя");
|
||||
Console.WriteLine("4. Найти пользователя по GUID");
|
||||
Console.WriteLine("5. Показать все группы");
|
||||
Console.WriteLine("6. Добавить группу");
|
||||
Console.WriteLine("7. Обновить группу");
|
||||
Console.WriteLine("8. Удалить группу по ID");
|
||||
Console.WriteLine("9. Найти группу по ID");
|
||||
Console.WriteLine("10. Генерация посещаемости на текущий день");
|
||||
Console.WriteLine("11. Генерация посещаемости на неделю");
|
||||
Console.WriteLine("12. Показать посещаемость по группе и дате");
|
||||
Console.WriteLine("13. Отметить пользователя как отсутствующего");
|
||||
Console.WriteLine("14. Вывести всю посещаемость");
|
||||
Console.WriteLine("0. Выход");
|
||||
Console.Write("Выберите пункт меню: ");
|
||||
|
||||
var input = Console.ReadLine() ?? string.Empty;
|
||||
|
||||
Console.WriteLine("=-= Команды с Пользователями =-=");
|
||||
Console.WriteLine("1. Вывести всех пользователей");
|
||||
Console.WriteLine("2. Удалить пользователя по id");
|
||||
Console.WriteLine("3. Обновить пользователя по id");
|
||||
Console.WriteLine("4. Найти пользователя по id");
|
||||
Console.WriteLine();
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case "1":
|
||||
ShowAllUsers();
|
||||
break;
|
||||
case "2":
|
||||
DeleteUserByGuid();
|
||||
break;
|
||||
case "3":
|
||||
UpdateUser();
|
||||
break;
|
||||
case "4":
|
||||
FindUserByGuid();
|
||||
break;
|
||||
case "5":
|
||||
ShowAllGroups();
|
||||
break;
|
||||
case "6":
|
||||
AddGroup();
|
||||
break;
|
||||
case "7":
|
||||
UpdateGroup();
|
||||
break;
|
||||
case "8":
|
||||
DeleteGroupById();
|
||||
break;
|
||||
case "9":
|
||||
FindGroupById();
|
||||
break;
|
||||
case "10":
|
||||
GenerateDailyPresence();
|
||||
break;
|
||||
case "11":
|
||||
GenerateWeeklyPresence();
|
||||
break;
|
||||
case "12":
|
||||
ShowPresenceByGroupAndDate();
|
||||
break;
|
||||
case "13":
|
||||
MarkUserAbsent();
|
||||
break;
|
||||
case "14":
|
||||
ShowAllPresences();
|
||||
break;
|
||||
case "0":
|
||||
exit = true;
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Неверный выбор. Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine("=-= Команды с Группами =-=");
|
||||
Console.WriteLine("5. Вывести все группы");
|
||||
Console.WriteLine("6. Добавить группу");
|
||||
Console.WriteLine("7. Изменить название группы");
|
||||
Console.WriteLine("8. Поиск группы по ID");
|
||||
Console.WriteLine();
|
||||
|
||||
private void ShowAllUsers()
|
||||
{
|
||||
var users = _userUseCase.GetAllUsers();
|
||||
Console.WriteLine("Список пользователей:");
|
||||
foreach (var user in users)
|
||||
{
|
||||
var group = _groupUseCase.GetGroupById(user.GroupID);
|
||||
Console.WriteLine($"ID: {user.Id} | ФИО: {user.FIO} | Группа: {group?.Name ?? "Неизвестно"}");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
Console.WriteLine("=-= Команды Presence =-=");
|
||||
Console.WriteLine("9. Сгенерировать посещаемость на день");
|
||||
Console.WriteLine("10. Сгенерировать посещаемость на неделю");
|
||||
Console.WriteLine("11. Показать посещаемость");
|
||||
Console.WriteLine("12. Отметить пользователя как отсутствующего");
|
||||
Console.WriteLine("13. Вывести всю посещаемость группы");
|
||||
Console.WriteLine("14. Вывести общую информацию об посещаемости по группе");
|
||||
Console.WriteLine("15. Вывести отчёт в Excel");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("0. Выход");
|
||||
|
||||
private void DeleteUserByGuid()
|
||||
Console.Write("Выберите команду: ");
|
||||
|
||||
if (int.TryParse(Console.ReadLine(), out int choice))
|
||||
{
|
||||
Console.Write("Введите GUID пользователя для удаления: ");
|
||||
var input = Console.ReadLine();
|
||||
if (Guid.TryParse(input, out Guid userId))
|
||||
switch (choice)
|
||||
{
|
||||
try
|
||||
case 1:
|
||||
_userConsole.DisplayAllUsers();
|
||||
break;
|
||||
case 2:
|
||||
Console.Write("Введите id пользователя: ");
|
||||
if (Guid.TryParse(Console.ReadLine(), out Guid userId))
|
||||
{
|
||||
_userUseCase.DeleteUser(userId);
|
||||
Console.WriteLine("Пользователь удалён.");
|
||||
_userConsole.DeleteUser(userId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
Console.WriteLine("Неверный формат id пользователя.");
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
Console.Write("Введите id пользователя: ");
|
||||
if (Guid.TryParse(Console.ReadLine(), out Guid updateUserId))
|
||||
{
|
||||
var userToUpdate = _userUseCase.GetUserById(updateUserId);
|
||||
if (userToUpdate != null)
|
||||
{
|
||||
Console.Write("Введите новое ФИО: ");
|
||||
userToUpdate.FIO = Console.ReadLine();
|
||||
Console.Write("Введите новый GroupID: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int newGroupID))
|
||||
{
|
||||
userToUpdate.GroupID = newGroupID;
|
||||
_userConsole.UpdateUser(userToUpdate);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат GroupID.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат GUID.");
|
||||
Console.WriteLine("Пользователь не найден.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void UpdateUser()
|
||||
else
|
||||
{
|
||||
Console.Write("Введите GUID пользователя для обновления: ");
|
||||
var input = Console.ReadLine();
|
||||
if (Guid.TryParse(input, out Guid userId))
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = _userUseCase.GetUserById(userId);
|
||||
Console.WriteLine($"Текущие данные: ФИО: {user.FIO}, Группа ID: {user.GroupID}");
|
||||
Console.Write("Введите новое ФИО (оставьте пустым, чтобы сохранить текущее): ");
|
||||
var newFIO = Console.ReadLine();
|
||||
Console.Write("Введите новый ID группы (оставьте пустым, чтобы сохранить текущую): ");
|
||||
var groupInput = Console.ReadLine();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(newFIO))
|
||||
{
|
||||
user.FIO = newFIO;
|
||||
Console.WriteLine("Неверный формат id пользователя.");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(groupInput))
|
||||
break;
|
||||
case 4:
|
||||
Console.Write("Введите id пользователя: ");
|
||||
if (Guid.TryParse(Console.ReadLine(), out Guid findUserId))
|
||||
{
|
||||
if (int.TryParse(groupInput, out int newGroupId))
|
||||
_userConsole.FindUser(findUserId);
|
||||
}
|
||||
else
|
||||
{
|
||||
var group = _groupUseCase.GetGroupById(newGroupId);
|
||||
Console.WriteLine("Неверный формат id пользователя.");
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
_groupConsole.DisplayAllGroups();
|
||||
break;
|
||||
case 6:
|
||||
Console.Write("Введите название группы: ");
|
||||
string groupName = Console.ReadLine();
|
||||
var newGroup = new Group { Name = groupName };
|
||||
_groupConsole.AddGroup(newGroup);
|
||||
break;
|
||||
case 7:
|
||||
Console.Write("Введите id группы: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int groupId))
|
||||
{
|
||||
Console.Write("Введите новое название группы: ");
|
||||
string newGroupName = Console.ReadLine();
|
||||
_groupConsole.UpdateGroupName(groupId, newGroupName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат id группы.");
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
Console.Write("Введите id группы: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int searchGroupId))
|
||||
{
|
||||
var group = _groupUseCase.GetAllGroups().FirstOrDefault(g => g.Id == searchGroupId);
|
||||
if (group != null)
|
||||
{
|
||||
user.GroupID = newGroupId;
|
||||
Console.WriteLine($"ID: {group.Id}, Название: {group.Name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Группа с таким ID не найдена. Группа не обновлена.");
|
||||
Console.WriteLine("Группа не найдена.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ID группы. Группа не обновлена.");
|
||||
Console.WriteLine("Неверный формат id группы.");
|
||||
}
|
||||
}
|
||||
|
||||
_userUseCase.UpdateUser(user);
|
||||
Console.WriteLine("Пользователь обновлён.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
break;
|
||||
case 9:
|
||||
Console.Write("Введите номер первого занятия: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int firstLesson))
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
Console.Write("Введите номер последнего занятия: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int lastLesson))
|
||||
{
|
||||
Console.WriteLine("Неверный формат GUID.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void FindUserByGuid()
|
||||
Console.Write("Введите id группы: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int groupIdForPresence))
|
||||
{
|
||||
Console.Write("Введите GUID пользователя для поиска: ");
|
||||
var input = Console.ReadLine();
|
||||
if (Guid.TryParse(input, out Guid userId))
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = _userUseCase.GetUserById(userId);
|
||||
var group = _groupUseCase.GetGroupById(user.GroupID);
|
||||
Console.WriteLine($"ID: {user.Id} | ФИО: {user.FIO} | Группа: {group?.Name ?? "Неизвестно"}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат GUID.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void ShowAllGroups()
|
||||
{
|
||||
var groups = _groupUseCase.GetAllGroups();
|
||||
Console.WriteLine("Список групп:");
|
||||
foreach (var group in groups)
|
||||
{
|
||||
Console.WriteLine($"ID: {group.Id} | Название: {group.Name}");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void AddGroup()
|
||||
{
|
||||
Console.Write("Введите ID группы: ");
|
||||
var idInput = Console.ReadLine();
|
||||
Console.Write("Введите название группы: ");
|
||||
var name = Console.ReadLine() ?? string.Empty;
|
||||
if (int.TryParse(idInput, out int groupId))
|
||||
{
|
||||
var existingGroup = _groupUseCase.GetGroupById(groupId);
|
||||
if (existingGroup != null)
|
||||
{
|
||||
Console.WriteLine("Группа с таким ID уже существует.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var group = new Group
|
||||
{
|
||||
Id = groupId,
|
||||
Name = name
|
||||
};
|
||||
try
|
||||
{
|
||||
_groupUseCase.AddGroup(group);
|
||||
Console.WriteLine("Группа добавлена.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ID группы.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void UpdateGroup()
|
||||
{
|
||||
Console.Write("Введите ID группы для обновления: ");
|
||||
var idInput = Console.ReadLine();
|
||||
if (int.TryParse(idInput, out int groupId))
|
||||
{
|
||||
try
|
||||
{
|
||||
var group = _groupUseCase.GetGroupById(groupId);
|
||||
Console.WriteLine($"Текущие данные: Название: {group.Name}");
|
||||
Console.Write("Введите новое название группы: ");
|
||||
var newName = Console.ReadLine();
|
||||
if (!string.IsNullOrWhiteSpace(newName))
|
||||
{
|
||||
group.Name = newName;
|
||||
_groupUseCase.UpdateGroup(group);
|
||||
Console.WriteLine("Группа обновлена.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Название не может быть пустым. Группа не обновлена.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ID группы.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void DeleteGroupById()
|
||||
{
|
||||
Console.Write("Введите ID группы для удаления: ");
|
||||
var input = Console.ReadLine();
|
||||
if (int.TryParse(input, out int groupId))
|
||||
{
|
||||
try
|
||||
{
|
||||
_groupUseCase.DeleteGroup(groupId);
|
||||
Console.WriteLine("Группа удалена.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ID группы.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void FindGroupById()
|
||||
{
|
||||
Console.Write("Введите ID группы для поиска: ");
|
||||
var input = Console.ReadLine();
|
||||
if (int.TryParse(input, out int groupId))
|
||||
{
|
||||
try
|
||||
{
|
||||
var group = _groupUseCase.GetGroupById(groupId);
|
||||
Console.WriteLine($"ID: {group.Id} | Название: {group.Name}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ID группы.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void GenerateDailyPresence()
|
||||
{
|
||||
Console.Write("Введите номер первой пары: ");
|
||||
var firstLessonInput = Console.ReadLine();
|
||||
Console.Write("Введите номер последней пары: ");
|
||||
var lastLessonInput = Console.ReadLine();
|
||||
Console.Write("Введите ID группы: ");
|
||||
var groupIdInput = Console.ReadLine();
|
||||
Console.Write("Введите дату (yyyy-MM-dd): ");
|
||||
var dateInput = Console.ReadLine();
|
||||
|
||||
if (int.TryParse(firstLessonInput, out int firstLesson) &&
|
||||
int.TryParse(lastLessonInput, out int lastLesson) &&
|
||||
int.TryParse(groupIdInput, out int groupId) &&
|
||||
DateTime.TryParseExact(dateInput, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date))
|
||||
if (DateTime.TryParse(Console.ReadLine(), out DateTime date))
|
||||
{
|
||||
try
|
||||
{
|
||||
_presenceGenerator.GenerateDailyPresence(groupId, firstLesson, lastLesson, date);
|
||||
Console.WriteLine("Посещаемость сгенерирована.");
|
||||
var generatePresenceUseCase = new UseCaseGeneratePresence(_presenceUseCase.PresenceRepository, _userUseCase.UserRepository);
|
||||
generatePresenceUseCase.GeneratePresenceForToday(firstLesson, lastLesson, groupIdForPresence, date);
|
||||
Console.WriteLine("Посещаемость сгенерирована на день.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
Console.WriteLine("Неверный формат даты.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверные входные данные.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void GenerateWeeklyPresence()
|
||||
{
|
||||
Console.Write("Введите номер первой пары: ");
|
||||
var firstLessonInput = Console.ReadLine();
|
||||
Console.Write("Введите номер последней пары: ");
|
||||
var lastLessonInput = Console.ReadLine();
|
||||
Console.Write("Введите ID группы: ");
|
||||
var groupIdInput = Console.ReadLine();
|
||||
Console.Write("Введите начальную дату недели (yyyy-MM-dd): ");
|
||||
var startDateInput = Console.ReadLine();
|
||||
|
||||
if (int.TryParse(firstLessonInput, out int firstLesson) &&
|
||||
int.TryParse(lastLessonInput, out int lastLesson) &&
|
||||
int.TryParse(groupIdInput, out int groupId) &&
|
||||
DateTime.TryParseExact(startDateInput, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime startDate))
|
||||
{
|
||||
try
|
||||
{
|
||||
_presenceGenerator.GenerateWeeklyPresence(groupId, firstLesson, lastLesson, startDate);
|
||||
Console.WriteLine("Посещаемость на неделю сгенерирована.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
Console.WriteLine("Неверный формат id группы.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверные входные данные.");
|
||||
Console.WriteLine("Неверный формат номера последнего занятия.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void ShowPresenceByGroupAndDate()
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат номера первого занятия.");
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
Console.Write("Введите номер первого занятия: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int firstLessonWeek))
|
||||
{
|
||||
Console.Write("Введите номер последнего занятия: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int lastLessonWeek))
|
||||
{
|
||||
Console.Write("Введите id группы: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int groupIdForPresenceWeek))
|
||||
{
|
||||
Console.Write("Введите дату начала недели (yyyy-MM-dd): ");
|
||||
if (DateTime.TryParse(Console.ReadLine(), out DateTime startDateWeek))
|
||||
{
|
||||
var generatePresenceUseCaseWeek = new UseCaseGeneratePresence(_presenceUseCase.PresenceRepository, _userUseCase.UserRepository);
|
||||
generatePresenceUseCaseWeek.GeneratePresenceForWeek(firstLessonWeek, lastLessonWeek, groupIdForPresenceWeek, startDateWeek);
|
||||
Console.WriteLine("Посещаемость сгенерирована на неделю.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат даты.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат id группы.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат номера последнего занятия.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат номера первого занятия.");
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
Console.Write("Введите id группы: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int groupIdForPresenceDisplay))
|
||||
{
|
||||
_presenceConsole.DisplayPresenceByGroup(groupIdForPresenceDisplay);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат id группы.");
|
||||
}
|
||||
break;
|
||||
case 12:
|
||||
Console.Write("Введите id пользователя: ");
|
||||
if (Guid.TryParse(Console.ReadLine(), out Guid userIdForAbsent))
|
||||
{
|
||||
Console.Write("Введите номер занятия: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int lessonNumberForAbsent))
|
||||
{
|
||||
Console.Write("Введите ID группы: ");
|
||||
var groupIdInput = Console.ReadLine();
|
||||
Console.Write("Введите дату (yyyy-MM-dd): ");
|
||||
var dateInput = Console.ReadLine();
|
||||
|
||||
if (int.TryParse(groupIdInput, out int groupId) &&
|
||||
DateTime.TryParseExact(dateInput, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date))
|
||||
if (DateTime.TryParse(Console.ReadLine(), out DateTime dateForAbsent))
|
||||
{
|
||||
try
|
||||
{
|
||||
var presences = _presenceUseCase.GetPresencesByGroupAndDate(groupId, date);
|
||||
var group = _groupUseCase.GetGroupById(groupId);
|
||||
Console.WriteLine($"Посещаемость группы {group?.Name ?? "Неизвестно"} на {date.ToString("yyyy-MM-dd")}:");
|
||||
foreach (var presence in presences)
|
||||
{
|
||||
var user = _userUseCase.GetUserById(presence.UserId);
|
||||
Console.WriteLine($"Пользователь: {user.FIO} | Пара: {presence.LessonNumber} | Был/Не был: {(presence.WasPresent ? "Был" : "Не был")}");
|
||||
_presenceConsole.MarkUserAsAbsent(userIdForAbsent, lessonNumberForAbsent, dateForAbsent);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
Console.WriteLine("Неверный формат даты.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверные входные данные.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void MarkUserAbsent()
|
||||
{
|
||||
Console.Write("Введите GUID пользователя: ");
|
||||
var userIdInput = Console.ReadLine();
|
||||
Console.Write("Введите номер пары: ");
|
||||
var lessonInput = Console.ReadLine();
|
||||
Console.Write("Введите дату (yyyy-MM-dd): ");
|
||||
var dateInput = Console.ReadLine();
|
||||
|
||||
if (Guid.TryParse(userIdInput, out Guid userId) &&
|
||||
int.TryParse(lessonInput, out int lessonNumber) &&
|
||||
DateTime.TryParseExact(dateInput, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date))
|
||||
{
|
||||
try
|
||||
{
|
||||
_presenceUseCase.MarkUserAbsent(userId, lessonNumber, date);
|
||||
Console.WriteLine("Пользователь отмечен как отсутствующий.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
Console.WriteLine("Неверный формат номера занятия.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверные входные данные.");
|
||||
Console.WriteLine("Неверный формат id пользователя.");
|
||||
}
|
||||
Pause();
|
||||
break;
|
||||
case 13:
|
||||
Console.Write("Введите id группы: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int groupIdForPresenceAll))
|
||||
{
|
||||
_presenceConsole.DisplayPresenceByGroup(groupIdForPresenceAll);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат id группы.");
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
Console.Write("Введите id группы: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int groupIdForPresenceInfo))
|
||||
{
|
||||
var groupForInfo = _groupUseCase.GetAllGroups().FirstOrDefault(g => g.Id == groupIdForPresenceInfo);
|
||||
if (groupForInfo != null)
|
||||
{
|
||||
var usersForInfo = _userUseCase.GetAllUsers().Where(u => u.GroupID == groupIdForPresenceInfo).ToList();
|
||||
var presenceForInfo = _presenceUseCase.GetPresenceByGroup(groupIdForPresenceInfo).ToList();
|
||||
Console.WriteLine($"Количество человек в группе: {usersForInfo.Count}");
|
||||
Console.WriteLine($"Количество проведенных занятий: {presenceForInfo.Select(p => p.Date).Distinct().Count()}");
|
||||
Console.WriteLine($"Общий процент посещаемости: {presenceForInfo.Count(p => p.IsAttendance) * 100.0 / presenceForInfo.Count}%");
|
||||
foreach (var user in usersForInfo)
|
||||
{
|
||||
var userPresence = presenceForInfo.Where(p => p.UserId == user.Id).ToList();
|
||||
int attended = userPresence.Count(p => p.IsAttendance);
|
||||
int missed = userPresence.Count(p => !p.IsAttendance);
|
||||
double percentage = (attended * 100.0) / (attended + missed);
|
||||
Console.WriteLine($"ФИО: {user.FIO}, Посещено: {attended}, Пропущено: {missed}, Процент посещаемости: {percentage}%");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Группа не найдена.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат id группы.");
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
Console.Write("Введите id группы: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int groupIdForExport))
|
||||
{
|
||||
var groupForExport = _groupUseCase.GetAllGroups().FirstOrDefault(g => g.Id == groupIdForExport);
|
||||
if (groupForExport != null)
|
||||
{
|
||||
var usersForExport = _userUseCase.GetAllUsers().Where(u => u.GroupID == groupIdForExport).ToList();
|
||||
var presenceForExport = _presenceUseCase.GetPresenceByGroup(groupIdForExport).ToList();
|
||||
|
||||
// Указываем путь для сохранения файла
|
||||
string directoryPath = @"C:\Users\Наиль\Source\Repos\slarny4\Demo1\Excel";
|
||||
string filePath = Path.Combine(directoryPath, "GroupInfo.xlsx");
|
||||
|
||||
// Проверяем, существует ли директория, и если нет, создаем её
|
||||
if (!Directory.Exists(directoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
|
||||
private void ShowAllPresences()
|
||||
{
|
||||
var presences = _presenceUseCase.GetAllPresences();
|
||||
Console.WriteLine("Вся посещаемость:");
|
||||
foreach (var presence in presences)
|
||||
{
|
||||
var user = _userUseCase.GetUserById(presence.UserId);
|
||||
var group = _groupUseCase.GetGroupById(user.GroupID);
|
||||
Console.WriteLine($"Пользователь: {user.FIO} | Группа: {group?.Name ?? "Неизвестно"} | Дата: {presence.ClassDate.ToString("yyyy-MM-dd")} | Пара: {presence.LessonNumber} | Был/Не был: {(presence.WasPresent ? "Был" : "Не был")}");
|
||||
_excelExporter.ExportGroupInfoToExcel(groupForExport, usersForExport, presenceForExport, filePath);
|
||||
Console.WriteLine("Отчёт экспортирован в Excel.");
|
||||
}
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void Pause()
|
||||
else
|
||||
{
|
||||
Console.WriteLine("\nНажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
Console.WriteLine("Группа не найдена.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат id группы.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный ввод. Пожалуйста, введите число.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,221 +1,48 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Demo.Domain.UseCase;
|
||||
using Demo.Data.Repository;
|
||||
using Demo.Data.LocalData.Entity;
|
||||
using Demo.Data.Exceptions;
|
||||
using AttendanceApp.Domain.Models;
|
||||
using Demo.Domain.UseCase;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace AttendanceApp.UI
|
||||
namespace Demo.UI
|
||||
{
|
||||
public class PresenceConsole
|
||||
{
|
||||
private readonly UseCaseGeneratePresence _generatePresenceUseCase;
|
||||
private readonly IPresenceRepository _presenceRepository;
|
||||
private readonly IGroupRepository _groupRepository;
|
||||
private readonly UseCasePresence _presenceUseCase;
|
||||
private readonly UserUseCase _userUseCase;
|
||||
|
||||
public PresenceConsole(UseCaseGeneratePresence generatePresenceUseCase, IPresenceRepository presenceRepository, IGroupRepository groupRepository)
|
||||
public PresenceConsole(UseCasePresence presenceUseCase, UserUseCase userUseCase)
|
||||
{
|
||||
_generatePresenceUseCase = generatePresenceUseCase;
|
||||
_presenceRepository = presenceRepository;
|
||||
_groupRepository = groupRepository;
|
||||
_presenceUseCase = presenceUseCase;
|
||||
_userUseCase = userUseCase;
|
||||
}
|
||||
|
||||
public void GenerateDailyPresence()
|
||||
public void DisplayPresenceByGroup(int groupId)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Генерация посещаемости на текущий день ===");
|
||||
Console.Write("Введите номер первого занятия: ");
|
||||
var firstClassInput = Console.ReadLine();
|
||||
Console.Write("Введите номер последнего занятия: ");
|
||||
var lastClassInput = Console.ReadLine();
|
||||
Console.Write("Введите ID группы: ");
|
||||
var groupIdInput = Console.ReadLine();
|
||||
var currentDate = DateTime.Now.Date;
|
||||
var presence = _presenceUseCase.GetPresenceByGroup(groupId);
|
||||
var users = _userUseCase.GetAllUsers().ToDictionary(u => u.Id);
|
||||
|
||||
if (int.TryParse(firstClassInput, out int firstClassNum)
|
||||
&& int.TryParse(lastClassInput, out int lastClassNum)
|
||||
&& int.TryParse(groupIdInput, out int groupId))
|
||||
foreach (var p in presence)
|
||||
{
|
||||
try
|
||||
{
|
||||
_generatePresenceUseCase.GenerateDailyPresence(firstClassNum, lastClassNum, groupId, currentDate);
|
||||
Console.WriteLine("Посещаемость успешно сгенерирована на текущий день.");
|
||||
var user = users[p.UserId];
|
||||
Console.WriteLine($"Дата: {p.Date}, Занятие: {p.LessonNumber}, ФИО: {user.FIO}, Посещаемость: {(p.IsAttendance ? "Присутствовал" : "Отсутствовал")}");
|
||||
}
|
||||
catch (GroupNotFoundException ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ввода.");
|
||||
}
|
||||
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
public void DisplayPresenceByGroupAndDate(int groupId, DateTime date)
|
||||
{
|
||||
var presence = _presenceUseCase.GetPresenceByGroupAndDate(groupId, date);
|
||||
var users = _userUseCase.GetAllUsers().ToDictionary(u => u.Id);
|
||||
|
||||
foreach (var p in presence)
|
||||
{
|
||||
var user = users[p.UserId];
|
||||
Console.WriteLine($"Дата: {p.Date}, Занятие: {p.LessonNumber}, ФИО: {user.FIO}, Посещаемость: {(p.IsAttendance ? "Присутствовал" : "Отсутствовал")}");
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateWeeklyPresence()
|
||||
public void MarkUserAsAbsent(Guid userId, int lessonNumber, DateTime date)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Генерация посещаемости на неделю ===");
|
||||
Console.Write("Введите номер первого занятия: ");
|
||||
var firstClassInput = Console.ReadLine();
|
||||
Console.Write("Введите номер последнего занятия: ");
|
||||
var lastClassInput = Console.ReadLine();
|
||||
Console.Write("Введите ID группы: ");
|
||||
var groupIdInput = Console.ReadLine();
|
||||
Console.Write("Введите стартовую дату (yyyy-MM-dd): ");
|
||||
var startDateInput = Console.ReadLine();
|
||||
|
||||
if (int.TryParse(firstClassInput, out int firstClassNum)
|
||||
&& int.TryParse(lastClassInput, out int lastClassNum)
|
||||
&& int.TryParse(groupIdInput, out int groupId)
|
||||
&& DateTime.TryParseExact(startDateInput, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime startDate))
|
||||
{
|
||||
try
|
||||
{
|
||||
_generatePresenceUseCase.GenerateWeeklyPresence(firstClassNum, lastClassNum, groupId, startDate);
|
||||
Console.WriteLine("Посещаемость успешно сгенерирована на неделю.");
|
||||
}
|
||||
catch (GroupNotFoundException ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ввода.");
|
||||
}
|
||||
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
public void ShowPresenceByGroupAndDate()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Показать посещаемость по группе и дате ===");
|
||||
Console.Write("Введите ID группы: ");
|
||||
var groupIdInput = Console.ReadLine();
|
||||
Console.Write("Введите дату (yyyy-MM-dd): ");
|
||||
var dateInput = Console.ReadLine();
|
||||
|
||||
if (int.TryParse(groupIdInput, out int groupId) && DateTime.TryParse(dateInput, out DateTime date))
|
||||
{
|
||||
try
|
||||
{
|
||||
var group = _groupRepository.GetGroupById(groupId);
|
||||
// Добавляем проверку на null
|
||||
if (group == null)
|
||||
{
|
||||
Console.WriteLine($"Группа с ID {groupId} не найдена.");
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
return;
|
||||
}
|
||||
|
||||
var presences = _presenceRepository.GetPresencesByGroupAndDate(groupId, date);
|
||||
Console.WriteLine($"Посещаемость группы {group.Name} на {date.ToShortDateString()}:");
|
||||
foreach (var presence in presences)
|
||||
{
|
||||
Console.WriteLine($"Пользователь ID: {presence.UserId} | Занятие №: {presence.LessonNumber} | Присутствует: {presence.WasPresent}");
|
||||
}
|
||||
}
|
||||
catch (GroupNotFoundException ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ввода.");
|
||||
}
|
||||
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
public void MarkUserAbsent()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Отметить пользователя как отсутствующего ===");
|
||||
Console.Write("Введите ID пользователя (GUID): ");
|
||||
var userIdInput = Console.ReadLine();
|
||||
Console.Write("Введите диапазон занятий (через запятую, например: 1,3): ");
|
||||
var classRangeInput = Console.ReadLine();
|
||||
|
||||
if (Guid.TryParse(userIdInput, out Guid userId)
|
||||
&& classRangeInput.Contains(",")
|
||||
&& int.TryParse(classRangeInput.Split(',')[0], out int startClass)
|
||||
&& int.TryParse(classRangeInput.Split(',')[1], out int endClass))
|
||||
{
|
||||
try
|
||||
{
|
||||
var currentDate = DateTime.Now.Date;
|
||||
for (int classNum = startClass; classNum <= endClass; classNum++)
|
||||
{
|
||||
var presence = new Presence
|
||||
{
|
||||
ClassDate = currentDate,
|
||||
LessonNumber = classNum,
|
||||
WasPresent = false,
|
||||
UserId = userId
|
||||
};
|
||||
_presenceRepository.UpdatePresence(presence);
|
||||
}
|
||||
Console.WriteLine("Пользователь успешно отмечен как отсутствующий на указанных занятиях.");
|
||||
}
|
||||
catch (RepositoryException ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ввода.");
|
||||
}
|
||||
|
||||
Console.WriteLine("Нажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
public void ShowPresenceByGroup()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Показать посещаемость по группе ===");
|
||||
Console.Write("Введите ID группы: ");
|
||||
var groupIdInput = Console.ReadLine();
|
||||
|
||||
if (int.TryParse(groupIdInput, out int groupId))
|
||||
{
|
||||
try
|
||||
{
|
||||
var group = _groupRepository.GetGroupById(groupId);
|
||||
var presences = _presenceRepository.GetPresenceByGroup(groupId);
|
||||
|
||||
Console.WriteLine($"Посещаемость группы {group.Name}:");
|
||||
foreach (var presence in presences)
|
||||
{
|
||||
Console.WriteLine($"Дата: {presence.ClassDate.ToShortDateString()} | " +
|
||||
$"Занятие №{presence.LessonNumber} | " +
|
||||
$"Присутствует: {(presence.WasPresent ? "Да" : "Нет")} | " +
|
||||
$"Студент ID: {presence.UserId}");
|
||||
}
|
||||
}
|
||||
catch (GroupNotFoundException ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Неверный формат ID группы.");
|
||||
}
|
||||
|
||||
Console.WriteLine("\nНажмите любую клавишу для продолжения...");
|
||||
Console.ReadKey();
|
||||
_presenceUseCase.MarkUserAsAbsent(userId, lessonNumber, date);
|
||||
Console.WriteLine("Пользователь отмечен как отсутствующий.");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Demo.Data.RemoteData.RemoteDataBase.DAO; // Используйте правильное пространство имен
|
||||
using Demo.Domain.UseCase;
|
||||
using System;
|
||||
|
||||
namespace Demo1.UI
|
||||
namespace Demo.UI
|
||||
{
|
||||
internal class UserConsole
|
||||
public class UserConsole
|
||||
{
|
||||
private readonly UserUseCase _userUseCase;
|
||||
|
||||
public UserConsole(UserUseCase userUseCase)
|
||||
{
|
||||
_userUseCase = userUseCase;
|
||||
}
|
||||
|
||||
public void DisplayAllUsers()
|
||||
{
|
||||
var users = _userUseCase.GetAllUsers();
|
||||
foreach (var user in users)
|
||||
{
|
||||
Console.WriteLine($"ID: {user.Id}, FIO: {user.FIO}, GroupID: {user.GroupID}");
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteUser(Guid id)
|
||||
{
|
||||
_userUseCase.DeleteUser(id);
|
||||
Console.WriteLine("User deleted.");
|
||||
}
|
||||
|
||||
public void UpdateUser(User user)
|
||||
{
|
||||
_userUseCase.UpdateUser(user);
|
||||
Console.WriteLine("User updated.");
|
||||
}
|
||||
|
||||
public void FindUser(Guid id)
|
||||
{
|
||||
var user = _userUseCase.GetUserById(id);
|
||||
if (user != null)
|
||||
{
|
||||
Console.WriteLine($"ID: {user.Id}, FIO: {user.FIO}, GroupID: {user.GroupID}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("User not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,10 +1,16 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net8.0",
|
||||
"framework": {
|
||||
"frameworks": [
|
||||
{
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "8.0.0"
|
||||
},
|
||||
{
|
||||
"name": "Microsoft.AspNetCore.App",
|
||||
"version": "8.0.0"
|
||||
}
|
||||
],
|
||||
"configProperties": {
|
||||
"System.Reflection.NullabilityInfoContext.IsSupported": true,
|
||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Demo1")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+06b1f950636c0e6a821db89e32cb6df6c2d4fc5f")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9ba62b2fa20afffbdbc79b338375befcb707042e")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Demo1")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Demo1")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user