implemented everything in admin but clearPresence, not understanding how to do it
This commit is contained in:
parent
8ef372052b
commit
7d03600cac
78
data/Repository/AdminRepositoryImp.cs
Normal file
78
data/Repository/AdminRepositoryImp.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using presence.data.RemoteData;
|
||||
using presence.data.RemoteData.RemoteDataBase;
|
||||
using presence.data.RemoteData.RemoteDataBase.DAO;
|
||||
using presence.data.Repository;
|
||||
|
||||
namespace data.Repository
|
||||
{
|
||||
public class AdminRepositoryImp: IAdminRepository
|
||||
{
|
||||
private readonly RemoteDataBaseContext _remoteDataBaseContext;
|
||||
|
||||
public AdminRepositoryImp(RemoteDataBaseContext remoteDataBaseContext)
|
||||
{
|
||||
_remoteDataBaseContext = remoteDataBaseContext;
|
||||
}
|
||||
|
||||
public bool AddStudents(GroupDao group, List<string> students)
|
||||
{
|
||||
_remoteDataBaseContext.Groups.Add(group);
|
||||
foreach (string student in students)
|
||||
{
|
||||
var user = new UserDao
|
||||
{
|
||||
FIO = student,
|
||||
GroupId = group.Id,
|
||||
Group = _remoteDataBaseContext.Groups.Where(x => x.Id == group.Id).FirstOrDefault()
|
||||
};
|
||||
_remoteDataBaseContext.Users.Add(user);
|
||||
}
|
||||
_remoteDataBaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void DeleteUserFromGroup(int userId, int groupId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void DeleteGroup(int groupId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ClearPresence()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<GroupDao> GetAllGroupsWithStudents()
|
||||
{
|
||||
return _remoteDataBaseContext.Groups.Select(x => new GroupDao
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
User = _remoteDataBaseContext.Users.Where(it => it.GroupId == x.Id).ToList()}).ToList();
|
||||
}
|
||||
|
||||
public UserDao GetStudentInfo(int userId)
|
||||
{
|
||||
return _remoteDataBaseContext.Users.Where(x => x.UserId == userId).FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool RemoveUserById(int userId, int groupId)
|
||||
{
|
||||
var userLocal = _remoteDataBaseContext.Users
|
||||
.Where(x => x.UserId== userId && x.GroupId == groupId).FirstOrDefault();
|
||||
if (userLocal == null) return false;
|
||||
|
||||
_remoteDataBaseContext.Users.Remove(userLocal);
|
||||
_remoteDataBaseContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -54,7 +54,12 @@ namespace presence.data.Repository
|
||||
var groupLocal = _remoteDatabaseContext.Groups
|
||||
.Where(x => x.Id == groupID).FirstOrDefault();
|
||||
if (groupLocal == null) return false;
|
||||
|
||||
var userLocal = _remoteDatabaseContext.Users.Where(x => x.GroupId == groupID).ToList();
|
||||
if (userLocal == null) return false;
|
||||
foreach (var user in userLocal)
|
||||
{
|
||||
_remoteDatabaseContext.Users.Remove(user);
|
||||
}
|
||||
_remoteDatabaseContext.Groups.Remove(groupLocal);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
|
16
data/Repository/IAdminRepository.cs
Normal file
16
data/Repository/IAdminRepository.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using presence.data.RemoteData.RemoteDataBase.DAO;
|
||||
|
||||
namespace data.Repository
|
||||
{
|
||||
public interface IAdminRepository
|
||||
{
|
||||
bool AddStudents(GroupDao group, List<string> students);
|
||||
IEnumerable<GroupDao> GetAllGroupsWithStudents();
|
||||
UserDao GetStudentInfo(int userId);
|
||||
bool RemoveUserById(int userId, int groupId);
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
@ -13,10 +13,10 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("data")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5b98b0036758c0bfbfd050b258dbaf603f2669f2")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8ef372052b678424c7aa0641185bc80a86633fd3")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("data")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("data")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
// Создано классом WriteCodeFragment MSBuild.
|
||||
|
||||
|
@ -1 +1 @@
|
||||
6f386b203319659ed0626eb565d13c3eafd1b1ae62135254883fcc52ed19b403
|
||||
24a878335b95e62669ffd03f1fc8ae7961ca2aeb2b77b5a0cc8714c45febe0a6
|
||||
|
@ -1 +1 @@
|
||||
0e40f97203a35e4eec117837f8297d4b9791879cf576ef18934e5c69224e371b
|
||||
8eca5ecb6d779046df6e1bf2012302fb656c15233d139f1b56f144cbd823ea78
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -9,5 +9,6 @@ namespace domain.Models.ResponseModels
|
||||
{
|
||||
public int Id {get; set;}
|
||||
public string Name {get; set;}
|
||||
public IEnumerable<UserResponse> User {get; set;}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ namespace domain.Models.ResponseModels
|
||||
{
|
||||
public required string FIO {get; set; }
|
||||
public int Id {get; set;}
|
||||
public required GroupResponse Group {get; set;}
|
||||
public int GroupId {get; set;}
|
||||
public GroupResponse Group {get; set;}
|
||||
}
|
||||
}
|
59
domain/UseCase/AdminUseCase.cs
Normal file
59
domain/UseCase/AdminUseCase.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading.Tasks;
|
||||
using data.Repository;
|
||||
using domain.Models.ResponseModels;
|
||||
using presence.data.RemoteData.RemoteDataBase.DAO;
|
||||
using presence.data.Repository;
|
||||
|
||||
namespace domain.UseCase
|
||||
{
|
||||
public class AdminUseCase
|
||||
{
|
||||
private readonly IAdminRepository _adminRepository;
|
||||
private readonly IGroupRepository _groupRepository;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
|
||||
public AdminUseCase(IAdminRepository adminRepository, IGroupRepository groupRepository, IUserRepository userRepository)
|
||||
{
|
||||
_adminRepository = adminRepository;
|
||||
_groupRepository = groupRepository;
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
public IEnumerable<GroupResponse> GetAllGroupsWithStudents() =>
|
||||
_adminRepository.GetAllGroupsWithStudents().Select(it => new GroupResponse
|
||||
{
|
||||
Name = it.Name,
|
||||
Id = it.Id,
|
||||
User = it.User.Where(u => u.GroupId == it.Id)
|
||||
.Select(u => new UserResponse { Id = u.UserId, FIO = u.FIO })
|
||||
.ToList()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
public UserResponse GetStudentInfo(int userId)
|
||||
{
|
||||
UserResponse user= new UserResponse{
|
||||
Id = userId,
|
||||
FIO = _adminRepository.GetStudentInfo(userId).FIO,
|
||||
GroupId = _adminRepository.GetStudentInfo(userId).GroupId
|
||||
};
|
||||
return user;
|
||||
}
|
||||
|
||||
public bool AddStudents(string GroupName, List<string> Students)
|
||||
{
|
||||
GroupDao groupDao= new GroupDao{ Name = GroupName};
|
||||
return _adminRepository.AddStudents(groupDao, Students);
|
||||
}
|
||||
|
||||
public bool DeleteGroup(int groupId) => _groupRepository.RemoveGroupById(groupId);
|
||||
|
||||
public bool DeleteUserFromGroup(int userId, int groupId) => _adminRepository.RemoveUserById(userId, groupId);
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,10 +13,10 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("domain")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5b98b0036758c0bfbfd050b258dbaf603f2669f2")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8ef372052b678424c7aa0641185bc80a86633fd3")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("domain")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("domain")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
// Создано классом WriteCodeFragment MSBuild.
|
||||
|
||||
|
@ -1 +1 @@
|
||||
32c088b7c6199415eae14640ae08a92e330be47769adae5ea3e1bd938c16f111
|
||||
2be1454f305b332ed3dfd12d83b5bd32519cfeb34730e08d6bc1129099d63430
|
||||
|
Binary file not shown.
@ -1 +1 @@
|
||||
ae51241ac0f631c070df03008b50d177e40c007642b63ec680be1b4b5ad4221b
|
||||
39d5017ade2f977b488b3c519c01dabccf98b78aec07d7faf03198773ce4ae62
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using domain.Models.ResponseModels;
|
||||
using domain.UseCase;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using presence.domain.Models;
|
||||
using presence.domain.UseCase;
|
||||
@ -12,14 +14,46 @@ namespace presence_api.Controllers.UserController;
|
||||
[Route("api/[admin]")]
|
||||
public class AdminController: ControllerBase
|
||||
{
|
||||
private readonly UserUseCase _userUseCase;
|
||||
private readonly GroupUseCase _groupUseCase;
|
||||
private readonly PresenceUseCase _presenceUseCase;
|
||||
private readonly AdminUseCase _adminUseCase;
|
||||
|
||||
public AdminController(UserUseCase userUseCase, GroupUseCase groupUseCase, PresenceUseCase presenceUseCase)
|
||||
public AdminController(AdminUseCase adminUseCase)
|
||||
{
|
||||
_userUseCase = userUseCase;
|
||||
_groupUseCase = groupUseCase;
|
||||
_presenceUseCase = presenceUseCase;
|
||||
_adminUseCase = adminUseCase;
|
||||
}
|
||||
|
||||
[HttpPost("~/AddStudents")]
|
||||
public ActionResult<String> AddStudents([FromQuery] string GroupName, [FromQuery] List<string> students)
|
||||
{
|
||||
return _adminUseCase.AddStudents(GroupName, students) ? "Данные группы и студентов добавлены": "Данные не добавлены";
|
||||
}
|
||||
|
||||
[HttpDelete("~/DeleteUserFromGroup")]
|
||||
public ActionResult<string> DeleteUserFromGroup([FromQuery] int userId, [FromQuery] int groupId)
|
||||
{
|
||||
return _adminUseCase.DeleteUserFromGroup(userId, groupId) ? "Юзер удален": "Юзер не удален";
|
||||
}
|
||||
|
||||
[HttpDelete("~/DeleteGroup")]
|
||||
public ActionResult<String> DeleteGroup([FromQuery] int groupId)
|
||||
{
|
||||
return _adminUseCase.DeleteGroup(groupId) ? "Группа удалена" : "Группа не удалена";
|
||||
}
|
||||
|
||||
// [HttpDelete("~/ClearPresence")]
|
||||
// public ActionResult ClearPresence()
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
[HttpGet("~/GetAllGroupsWithStudents")]
|
||||
public ActionResult<IEnumerable<GroupResponse>> GetAllGroupsWithStudents()
|
||||
{
|
||||
return Ok(_adminUseCase.GetAllGroupsWithStudents());
|
||||
}
|
||||
|
||||
[HttpGet("~/GetStudentInfo")]
|
||||
public ActionResult<UserResponse> GetStudentInfo([FromQuery] int userId)
|
||||
{
|
||||
return _adminUseCase.GetStudentInfo(userId);
|
||||
}
|
||||
}
|
@ -40,26 +40,26 @@ public class PresenceController: ControllerBase
|
||||
return Ok(_presenceUseCase.GetPresence(GroupId, startData, endData, UserId));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[HttpPost("~/AddPresence")]
|
||||
public ActionResult<IEnumerable<Presence>> PostPresence([FromQuery] int GroupId,
|
||||
[FromQuery] string StartData, [FromQuery] string EndData, [FromQuery] int UserId)
|
||||
{
|
||||
return Ok(_presenceUseCase.AddPresenceByDate(StartData, EndData, GroupId));
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[HttpDelete("~/DeleteByGroup")]
|
||||
public ActionResult<IEnumerable<PresenceResponse>> DeletePresenceByGroup([FromQuery] int GroupId)
|
||||
{
|
||||
return Ok(_presenceUseCase.DeletePresenceByGroup(GroupId));
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[HttpDelete("~/DeleteByUser")]
|
||||
public ActionResult<IEnumerable<PresenceResponse>> DeletePresenceByUser([FromQuery] int UserId)
|
||||
{
|
||||
return Ok(_presenceUseCase.DeletePresenceByUser(UserId));
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[HttpDelete("~/DeleteByDate")]
|
||||
public ActionResult<IEnumerable<PresenceResponse>> DeletePresenceByDate([FromQuery] string StartData, [FromQuery] string EndData)
|
||||
{
|
||||
DateOnly startData;
|
||||
@ -77,7 +77,7 @@ public class PresenceController: ControllerBase
|
||||
return Ok(_presenceUseCase.DeletePresenceByDate(startData, endData));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[HttpPost("~/IsAttendence")]
|
||||
public ActionResult<PresenceResponse> UpdateAttendance([FromQuery] int FirstClass,
|
||||
[FromQuery] int LastClass, [FromQuery] string Data,
|
||||
[FromQuery] int UserId)
|
||||
|
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,10 +13,10 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("presence_api")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5b98b0036758c0bfbfd050b258dbaf603f2669f2")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8ef372052b678424c7aa0641185bc80a86633fd3")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("presence_api")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("presence_api")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
// Создано классом WriteCodeFragment MSBuild.
|
||||
|
||||
|
@ -1 +1 @@
|
||||
b64a32c4afcdd923cba00e274a519ae6a5efc835494f91bacc7cf08bf4992583
|
||||
d71e0c1c402bb5f7999f22a103739c4472d550306d274e226a12195f88ae957b
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user