Added updating name with guid, finding name with guid, updating group name

This commit is contained in:
Dasha 2024-10-18 11:27:50 +03:00
parent 2adf9afa83
commit 1305f40f24
16 changed files with 48 additions and 18 deletions

View File

@ -13,13 +13,12 @@ namespace Posechaemost.Data.Repository
public class GroupRepositoryImpl
{
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
public GroupLocalEntity? UpdateGroup(GroupLocalEntity groupUpdateLocalEnity)
public GroupLocalEntity? UpdateGroup(String name)
{
GroupLocalEntity? groupLocal = GetAllGroups()
.Where(x => x.Id == groupUpdateLocalEnity.Id).FirstOrDefault();
.Where(x => x.Name == name).FirstOrDefault();
if (groupLocal == null) return null;
groupLocal.Id = groupUpdateLocalEnity.Id;
groupLocal.Name = groupUpdateLocalEnity.Name;
groupLocal.Name = name;
return groupLocal;
}

View File

@ -44,5 +44,12 @@ namespace Posechaemost.Data.Repository
return userLocal;
}
public UserLocalEntity? UpdateUserByGuid(Guid userGuid) {
UserLocalEntity? userLocal = GetAllUsers
.Where(x => x.Guid == userGuid).FirstOrDefault();
if (userLocal == null) return null;
return userLocal;
}
}
}

View File

@ -9,6 +9,6 @@ namespace Posechaemost.Domain.Models
public class User{
public required string FIO {get; set; }
public Guid Guid {get; set;}
public required Group Group {get; set;}
public required Group GroupId {get; set;}
}
}

View File

@ -21,13 +21,12 @@ namespace Posechaemost.Domain.UseCase
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
public Group UpdateGroupName(Group grou) {
GroupLocalEntity groupLocalEntity = new GroupLocalEntity {Id = grou.Id, Name = grou.Name};
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity);
public Group UpdateGroupName(String name, String name1) {
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(name);
if (result == null) throw new Exception("");
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.Id);
Group? group = GetAllGroups().FirstOrDefault(it => it.Name == result.Name);
if (group == null) throw new Exception("");
return new Group {Id = group.Id, Name = group.Name};
return new Group {Id = group.Id, Name = name1};
}
}
}

View File

@ -29,7 +29,7 @@ namespace Posechaemost.Domain.UseCase
(user, group) =>
new User { FIO = user.FIO,
Guid = user.Guid,
Group = new Group {Id = group.Id, Name = group.Name } }
GroupId = new Group {Id = group.Id, Name = group.Name } }
).ToList();
@ -37,16 +37,24 @@ namespace Posechaemost.Domain.UseCase
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
}
public User UpdateUser(User user) {
UserLocalEntity userLocalEnity = new UserLocalEntity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid };
UserLocalEntity userLocalEnity = new UserLocalEntity { FIO = user.FIO, GroupID = user.GroupId.Id, Guid = user.Guid };
UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEnity);
if (result == null) throw new Exception("");
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.GroupID);
if (group == null) throw new Exception("");
return new User { FIO = user.FIO, Guid = user.Guid, Group = group};
return new User { FIO = user.FIO, Guid = user.Guid, GroupId = group};
}
public UserLocalEntity GetUserByGuid(Guid userGuid) {
return _repositoryUserImpl.GetUserByGuid(userGuid);
}
public User UpdateUserByGuid(Guid userGuid, String fio, String groupId) {
UserLocalEntity? result = _repositoryUserImpl.UpdateUserByGuid(userGuid);
if (result == null) throw new Exception("");
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == int.Parse(groupId));
if (group == null) throw new Exception("");
return new User { FIO = fio, GroupId = group, Guid = userGuid };
}
}
}

View File

@ -1,3 +1,4 @@
using Posechaemost.Domain.Models;
using Posechaemost.Domain.UseCase;
using System;
using System.Collections.Generic;
@ -23,5 +24,12 @@ namespace Posechaemost.UI
}
Console.WriteLine(groupOutput);
}
public void UpdateGroupName(String name, String name1) {
StringBuilder userOutput = new StringBuilder();
var group = _groupUseCase.UpdateGroupName(name, name1);
userOutput.AppendLine($"{group.Id}\t{group.Name}");
Console.WriteLine(userOutput);
}
}
}

View File

@ -32,6 +32,8 @@ namespace Posechaemost.UI
case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
case "3": _groupConsoleUI.DisplayAllGroups(); break;
case "4": _userConsoleUI.GetUserByGuid(Guid.Parse(Console.ReadLine())); break;
case "5": _userConsoleUI.UpdateUserByGuid(Guid.Parse(Console.ReadLine()), Console.ReadLine(), Console.ReadLine()); break;
case "6": _groupConsoleUI.UpdateGroupName(Console.ReadLine(), Console.ReadLine()); break;
default: DisplayMenu();
break;

View File

@ -1,3 +1,4 @@
using Posechaemost.Data.LocalData.Entity;
using Posechaemost.Domain.UseCase;
using System;
using System.Collections.Generic;
@ -25,7 +26,7 @@ namespace Posechaemost.UI
StringBuilder userOutput = new StringBuilder();
foreach (var user in _userUseCase.GetAllUsers())
{
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.Group.Name}");
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupId.Name}");
}
Console.WriteLine(userOutput);
}
@ -36,8 +37,14 @@ namespace Posechaemost.UI
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupID}");
Console.WriteLine(userOutput);
}
}
public void UpdateUserByGuid(Guid userGuid, String name, String groupId) {
StringBuilder userOutput = new StringBuilder();
var user = _userUseCase.UpdateUserByGuid(userGuid, name, groupId);
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupId.Name}");
Console.WriteLine(userOutput);
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Posechaemost")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2043a0253af9ebde32c83e4366bb2ddff439b3bd")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2adf9afa836f2195e7d6875eb60914f8f6544ee9")]
[assembly: System.Reflection.AssemblyProductAttribute("Posechaemost")]
[assembly: System.Reflection.AssemblyTitleAttribute("Posechaemost")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
// Создано классом WriteCodeFragment MSBuild.

View File

@ -1 +1 @@
23fad0f77cb5c1fcd312e88f594bb29098487a4c55237df8836db88abd48689f
96bf08b88313635c8c7dfa5999c9c749997058383865f8a634f20c197c546273

Binary file not shown.

Binary file not shown.