Added updating name with guid, finding name with guid, updating group name
This commit is contained in:
parent
2adf9afa83
commit
1305f40f24
@ -13,13 +13,12 @@ namespace Posechaemost.Data.Repository
|
|||||||
public class GroupRepositoryImpl
|
public class GroupRepositoryImpl
|
||||||
{
|
{
|
||||||
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
|
public List<GroupLocalEntity> GetAllGroups() => LocalStaticData.groups;
|
||||||
public GroupLocalEntity? UpdateGroup(GroupLocalEntity groupUpdateLocalEnity)
|
public GroupLocalEntity? UpdateGroup(String name)
|
||||||
{
|
{
|
||||||
GroupLocalEntity? groupLocal = GetAllGroups()
|
GroupLocalEntity? groupLocal = GetAllGroups()
|
||||||
.Where(x => x.Id == groupUpdateLocalEnity.Id).FirstOrDefault();
|
.Where(x => x.Name == name).FirstOrDefault();
|
||||||
if (groupLocal == null) return null;
|
if (groupLocal == null) return null;
|
||||||
groupLocal.Id = groupUpdateLocalEnity.Id;
|
groupLocal.Name = name;
|
||||||
groupLocal.Name = groupUpdateLocalEnity.Name;
|
|
||||||
return groupLocal;
|
return groupLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,5 +44,12 @@ namespace Posechaemost.Data.Repository
|
|||||||
return userLocal;
|
return userLocal;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserLocalEntity? UpdateUserByGuid(Guid userGuid) {
|
||||||
|
UserLocalEntity? userLocal = GetAllUsers
|
||||||
|
.Where(x => x.Guid == userGuid).FirstOrDefault();
|
||||||
|
if (userLocal == null) return null;
|
||||||
|
return userLocal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,6 +9,6 @@ namespace Posechaemost.Domain.Models
|
|||||||
public class User{
|
public class User{
|
||||||
public required string FIO {get; set; }
|
public required string FIO {get; set; }
|
||||||
public Guid Guid {get; set;}
|
public Guid Guid {get; set;}
|
||||||
public required Group Group {get; set;}
|
public required Group GroupId {get; set;}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,13 +21,12 @@ namespace Posechaemost.Domain.UseCase
|
|||||||
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
|
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
|
||||||
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
|
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
|
||||||
|
|
||||||
public Group UpdateGroupName(Group grou) {
|
public Group UpdateGroupName(String name, String name1) {
|
||||||
GroupLocalEntity groupLocalEntity = new GroupLocalEntity {Id = grou.Id, Name = grou.Name};
|
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(name);
|
||||||
GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(groupLocalEntity);
|
|
||||||
if (result == null) throw new Exception("");
|
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("");
|
if (group == null) throw new Exception("");
|
||||||
return new Group {Id = group.Id, Name = group.Name};
|
return new Group {Id = group.Id, Name = name1};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,7 +29,7 @@ namespace Posechaemost.Domain.UseCase
|
|||||||
(user, group) =>
|
(user, group) =>
|
||||||
new User { FIO = user.FIO,
|
new User { FIO = user.FIO,
|
||||||
Guid = user.Guid,
|
Guid = user.Guid,
|
||||||
Group = new Group {Id = group.Id, Name = group.Name } }
|
GroupId = new Group {Id = group.Id, Name = group.Name } }
|
||||||
).ToList();
|
).ToList();
|
||||||
|
|
||||||
|
|
||||||
@ -37,16 +37,24 @@ namespace Posechaemost.Domain.UseCase
|
|||||||
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
|
||||||
}
|
}
|
||||||
public User UpdateUser(User user) {
|
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);
|
UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEnity);
|
||||||
if (result == null) throw new Exception("");
|
if (result == null) throw new Exception("");
|
||||||
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.GroupID);
|
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.GroupID);
|
||||||
if (group == null) throw new Exception("");
|
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) {
|
public UserLocalEntity GetUserByGuid(Guid userGuid) {
|
||||||
return _repositoryUserImpl.GetUserByGuid(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 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
using Posechaemost.Domain.Models;
|
||||||
using Posechaemost.Domain.UseCase;
|
using Posechaemost.Domain.UseCase;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -23,5 +24,12 @@ namespace Posechaemost.UI
|
|||||||
}
|
}
|
||||||
Console.WriteLine(groupOutput);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@ namespace Posechaemost.UI
|
|||||||
case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
|
case "2": _userConsoleUI.RemoveUserByGuid(Guid.Parse(Console.ReadLine())); break;
|
||||||
case "3": _groupConsoleUI.DisplayAllGroups(); break;
|
case "3": _groupConsoleUI.DisplayAllGroups(); break;
|
||||||
case "4": _userConsoleUI.GetUserByGuid(Guid.Parse(Console.ReadLine())); 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();
|
default: DisplayMenu();
|
||||||
break;
|
break;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using Posechaemost.Data.LocalData.Entity;
|
||||||
using Posechaemost.Domain.UseCase;
|
using Posechaemost.Domain.UseCase;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -25,7 +26,7 @@ namespace Posechaemost.UI
|
|||||||
StringBuilder userOutput = new StringBuilder();
|
StringBuilder userOutput = new StringBuilder();
|
||||||
foreach (var user in _userUseCase.GetAllUsers())
|
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);
|
Console.WriteLine(userOutput);
|
||||||
}
|
}
|
||||||
@ -36,8 +37,14 @@ namespace Posechaemost.UI
|
|||||||
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupID}");
|
userOutput.AppendLine($"{user.Guid}\t{user.FIO}\t{user.GroupID}");
|
||||||
Console.WriteLine(userOutput);
|
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.
@ -13,10 +13,10 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Posechaemost")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("Posechaemost")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[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.AssemblyProductAttribute("Posechaemost")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("Posechaemost")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("Posechaemost")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|
||||||
// Generated by the MSBuild WriteCodeFragment class.
|
// Создано классом WriteCodeFragment MSBuild.
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
23fad0f77cb5c1fcd312e88f594bb29098487a4c55237df8836db88abd48689f
|
96bf08b88313635c8c7dfa5999c9c749997058383865f8a634f20c197c546273
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user