This commit is contained in:
Userok 2024-11-07 14:31:00 +03:00
parent cefc9b3a85
commit 6cd68fd8f8
11 changed files with 133 additions and 13 deletions

Binary file not shown.

View File

@ -1,4 +1,5 @@
using Zurnal.RemaDateBase.DateDao;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
internal interface IGroupRepository
{
@ -8,7 +9,7 @@ internal interface IGroupRepository
{
return AllGroup.Select(g => new GroupDao { GroupName = g.GroupName, Id = g.Id });
}
List<GroupLocalEntity> GetAllGroup();
public bool RemoveGroupById(int groupId)
{
var group = AllGroup.FirstOrDefault(g => g.Id == groupId);

View File

@ -0,0 +1,52 @@
using Zurnal.Date.LocalDate;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Data.Repository
{
public class SQLGroupRepositoryImpl:IGroupRepository
{
private readonly RemoteDateBaseContext _remoteDataBaseContext;
public SQLGroupRepositoryImpl(RemoteDateBaseContext remoteDataBaseContext) {
_remoteDataBaseContext = remoteDataBaseContext;
}
public List<GroupDao> AllGroup => throw new NotImplementedException();
public bool AddGroup(GroupLocalEntity newGroup)
{
GroupDao groupDao = new GroupDao { GroupName = newGroup.Name };
var result = _remoteDataBaseContext.Group.Add(groupDao);
if (result != null) {
_remoteDataBaseContext.SaveChanges();
return true; }
return false;
}
public List<GroupLocalEntity> GetAllGroup()
{
return _remoteDataBaseContext.Group.Select(group => new GroupLocalEntity{
Id = group.Id,
Name = group.GroupName}
).ToList();
}
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public GroupLocalEntity GetGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool RemoveGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,7 @@
namespace domain.Models.RequestModels
{
public class GroupAddRequest
{
public string Name { get; set; }
}
}

View File

@ -0,0 +1,4 @@
public class GroupResponse{
public int Id {get; set;}
public string Name {get; set;}
}

View File

@ -1,9 +1,11 @@
using Zurnal.Data.Repository;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Domain.UseCase
{
public class GroupUseCase : IGroupRepository
{
private readonly IGroupRepository _repository;
private List<GroupDao> _groups = new List<GroupDao>();
public List<GroupDao> AllGroup => _groups;
private UserRepositoryImpl _repositoryUserImpl;
@ -59,5 +61,19 @@ namespace Zurnal.Domain.UseCase
{
return _groups.FirstOrDefault(g => g.Id == id);
}
public List<GroupResponse> getAllGroup(){
return _repository.GetAllGroup().Select(group =>
new GroupResponse {
Id = group.Id,
Name = group.Name
}
).ToList();
}
public List<GroupLocalEntity> GetAllGroup()
{
throw new NotImplementedException();
}
}
}

View File

@ -1,9 +1,18 @@
using Zurnal.UI;
using Zurnal.Data.Repository;
using Zurnal.Domain.UseCase;
using Zurnal.Domain.UseCase;
using Microsoft.Extensions.DependencyInjection;
using UI;
using Data.Repository;
GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl();
UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl();
UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl);
IServiceCollection services = new ServiceCollection();
MainMenuUI mainMenuUI = new MainMenuUI(userUseCase);
services
.AddDbContext<RemoteDateBaseContext>()
.AddSingleton<IGroupRepository,SQLGroupRepositoryImpl>()
.AddSingleton<GroupUseCase>()
.AddSingleton<GroupConsol>();
var serviceProvider = services.BuildServiceProvider();
GroupConsol groupUI = serviceProvider.GetService<GroupConsol>();
groupUI.AddGroup();

View File

@ -3,8 +3,6 @@ using Zurnal.RemaDateBase.DateDao;
public class RemoteDateBaseContext : DbContext
{
public RemoteDateBaseContext() { }
public DbSet<GroupDao> Group { get; set; }
public DbSet<UserDao> User { get; set; }
public DbSet<PresnceDao> Presence { get; set; }

33
Zurnal/UI/GroupConsol.cs Normal file
View File

@ -0,0 +1,33 @@
using domain;
using domain.Models.RequestModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zurnal.Domain.UseCase;
using Zurnal.RemaDateBase.DateDao;
namespace UI
{
public class GroupConsol
{
private readonly GroupUseCase _groupUseCase;
public GroupConsol(GroupUseCase groupUseCase) {
_groupUseCase = groupUseCase;
}
public void AddGroup() {
Console.WriteLine("Введите название группы: ");
string groupName = Console.ReadLine();
if (string.IsNullOrWhiteSpace(groupName)) {
Console.WriteLine("Название группы не может быть пустым. Пожалуйста, введите корректное название.");
return;
}
GroupDao groupDao = new GroupDao { GroupName = groupName };
_groupUseCase.AddGroup(groupDao);
}
}
}

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Zurnal")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+979f0a84e8934a72efb3311a281d819c04f351b5")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+cefc9b3a85c12cb82d7e543ab8d2eb025849b9ec")]
[assembly: System.Reflection.AssemblyProductAttribute("Zurnal")]
[assembly: System.Reflection.AssemblyTitleAttribute("Zurnal")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
81b7b72033be0fe61e2a2ba2abf77030b6175ed4211ce31436b98277e897b53f
e861d9be05b9445b3ebef44d26117a8c4b30fb141208d42302beba8abc1372c1