ajout unit of work
continuous-integration/drone/push Build is failing Details

WebAPI
PATRICK 1 year ago
commit 7565f42c31

@ -5,7 +5,11 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
<<<<<<< HEAD
<UserSecretsId>30f8a49f-7e7d-4394-80f0-b36f39b45831</UserSecretsId>
=======
<UserSecretsId>1540d456-1696-425e-b511-611542ce7c5e</UserSecretsId>
>>>>>>> master
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

@ -5,4 +5,7 @@
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

@ -41,7 +41,7 @@ namespace API.Controllers
}
[HttpGet("{id}")]
public async Task<ActionResult<RoleDTO>> GetRole(int id)
public async Task<ActionResult<RoleDTO>> GetRole(long id)
{
try
{
@ -80,7 +80,7 @@ namespace API.Controllers
}
[HttpDelete("{id}")]
public async Task<ActionResult<RoleDTO>> DeleteRole(int id)
public async Task<ActionResult<RoleDTO>> DeleteRole(long id)
{
try {
_logger.LogInformation("Deleting a role with id : {id}", id);

@ -40,7 +40,7 @@ namespace API.Controllers
}
}
[HttpGet("{id}")]
public async Task<ActionResult<TranslateDTO>> GetTranslate(int id)
public async Task<ActionResult<TranslateDTO>> GetTranslate(long id)
{
try {
_logger.LogInformation("Getting a Translate with id {id}", id);
@ -76,7 +76,7 @@ namespace API.Controllers
}
[HttpDelete("{id}")]
public async Task<ActionResult<TranslateDTO>> DeleteTranslate(int id)
public async Task<ActionResult<TranslateDTO>> DeleteTranslate(long id)
{
try {
_logger.LogInformation("Deleting a Translate with id : {id}", id);

@ -1,33 +1,24 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:32547",
"sslPort": 44345
}
},
{
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5124",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5124"
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7013;http://localhost:5124",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7013;http://localhost:5124"
},
"IIS Express": {
"commandName": "IISExpress",
@ -36,6 +27,26 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:32547",
"sslPort": 44345
}
}
}
}

@ -14,16 +14,16 @@ namespace DTOToEntity
public class GroupService : IGroupService
{
private readonly StubbedContext context = new StubbedContext();
private readonly UnitOfWork context = new UnitOfWork();
public GroupService()
{
}
public GroupService(StubbedContext context)
public GroupService(StubbedContext _context)
{
this.context = context;
context = new UnitOfWork(_context);
}
public async Task<GroupDTO> Add(GroupDTO group)
{
@ -31,21 +31,21 @@ namespace DTOToEntity
{
throw new ArgumentNullException();
}
var groupEntity = group.ToEntity();
var res = context.Groups.Add(groupEntity);
await context.SaveChangesAsync();
GroupEntity groupEntity = group.ToEntity();
context.GroupRepository.Insert(groupEntity);
await context.SaveChangesAsync();
return res.Entity.ToDTO(); ;
return groupEntity.ToDTO(); ;
}
public async Task<UserDTO> AddUserToGroup(long idUser, long idGroup)
{
var group = context.Groups.Find(idGroup);
var group = context.GroupRepository.GetById(idGroup);
if (group == null)
{
throw new Exception("Group not found");
}
var user = context.Users.Find(idUser);
var user = context.UserRepository.GetById(idUser);
if (user == null)
{
throw new Exception("User not found");
@ -58,17 +58,18 @@ namespace DTOToEntity
public async Task<VocabularyListDTO> AddVocabularyListToGroup(long vocabId, long groupId)
{
var group = context.Groups.Find(groupId);
var group = context.GroupRepository.GetById(groupId);
if (group == null)
{
throw new Exception("Group not found");
}
var vocab = context.VocabularyLists.Find(vocabId);
var vocab = context.VocabularyListRepository.GetById(vocabId);
if (vocab == null)
{
throw new Exception("VocabularyList not found");
}
group.GroupVocabularyList.Add(vocab);
await context.SaveChangesAsync();
return vocab.ToDTO();
@ -76,10 +77,10 @@ namespace DTOToEntity
public async Task<GroupDTO> Delete(object id)
{
var group = await context.Groups.FindAsync((long)id);
var group = context.GroupRepository.GetById((long)id);
if (group != null)
{
context.Groups.Remove(group);
{
context.GroupRepository.Delete(group);
await context.SaveChangesAsync();
}else
{
@ -90,7 +91,7 @@ namespace DTOToEntity
public async Task<GroupDTO> GetById(object id)
{
var group = await context.Groups.FindAsync((long)id);
var group = context.GroupRepository.GetById((long) id);
if (group == null)
{
throw new Exception("Group not found");
@ -100,26 +101,26 @@ namespace DTOToEntity
public async Task<PageResponse<GroupDTO>> GetByNum(int index, int count, int num)
{
var groups = context.Groups.Where(g => g.Num == num).Skip(index * count).Take(count);
return new PageResponse<GroupDTO>(groups.ToList().Select(g => g.ToDTO()), context.Groups.Count());
var groups = context.GroupRepository.GetItems(filter: g => g.Num == num, index, count);
return new PageResponse<GroupDTO>(groups.ToList().Select(g => g.ToDTO()), context.GroupRepository.GetItems(0, 1000000000).Count());
}
public async Task<PageResponse<GroupDTO>> GetBySector(int index, int count, string sector)
{
var groups = context.Groups.Where(g => g.sector == sector).Skip(index * count).Take(count);
return new PageResponse<GroupDTO>(groups.ToList().Select(g => g.ToDTO()), context.Groups.Count());
var groups = context.GroupRepository.GetItems(filter: g => g.sector == sector, index, count);
return new PageResponse<GroupDTO>(groups.ToList().Select(g => g.ToDTO()), context.GroupRepository.GetItems(0, 100000000).Count());
}
public async Task<PageResponse<GroupDTO>> GetByYear(int index, int count, int year)
{
var groups = context.Groups.Where(g => g.year == year).Skip(index * count).Take(count);
return new PageResponse<GroupDTO>(groups.ToList().Select(g => g.ToDTO()), context.Groups.Count());
var groups = context.GroupRepository.GetItems(filter: g => g.year == year, index, count);
return new PageResponse<GroupDTO>(groups.ToList().Select(g => g.ToDTO()), context.GroupRepository.GetItems(0,100000000).Count());
}
public async Task<PageResponse<GroupDTO>> Gets(int index, int count)
{
IEnumerable<GroupEntity> groups = await context.Groups.Skip(index * count).Take(count).ToListAsync();
return new PageResponse<GroupDTO>(groups.ToList().Select(g => g.ToDTO()), context.Groups.Count());
IEnumerable<GroupEntity> groups = context.GroupRepository.GetItems(index,count);
return new PageResponse<GroupDTO>(groups.ToList().Select(g => g.ToDTO()), context.GroupRepository.GetItems(0, 1000000000).Count());
}
public async Task<GroupDTO> Update(GroupDTO group)
@ -128,7 +129,7 @@ namespace DTOToEntity
{
throw new ArgumentNullException();
}
var existingGroup = await context.Groups.FindAsync(group.Id);
var existingGroup = context.GroupRepository.GetById(group.Id);
if (existingGroup == null)
{
throw new Exception("Group not found");

@ -1,4 +1,5 @@
using DTO;
using DbContextLib;
using DTO;
using Entities;
using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
@ -12,29 +13,29 @@ namespace DTOToEntity
{
public class LangueService : IService<LangueDTO>
{
private readonly StubbedContext _context = new StubbedContext();
private readonly UnitOfWork _context = new UnitOfWork();
public LangueService() { }
public LangueService(StubbedContext context)
{
this._context = context;
this._context = new UnitOfWork(context);
}
public async Task<LangueDTO> Add(LangueDTO langue)
{
var langueEntity = langue.ToEntity();
var res = _context.Langues.Add(langueEntity);
_context.LangueRepository.Insert(langueEntity);
await _context.SaveChangesAsync();
return res.Entity.ToDTO();
return langue;
}
public async Task<LangueDTO> Delete(object id)
{
var langue = await _context.Langues.FindAsync(id);
var langue = _context.LangueRepository.GetById(id);
if (langue != null)
{
_context.Langues.Remove(langue);
await _context.SaveChangesAsync();
_context.LangueRepository.Delete(langue);
await _context.SaveChangesAsync();
}
else {
throw new Exception("Langue not found");
@ -44,7 +45,7 @@ namespace DTOToEntity
public async Task<LangueDTO> GetById(object id)
{
var langue = await _context.Langues.FindAsync(id);
var langue = _context.LangueRepository.GetById(id);
if (langue == null)
{
throw new Exception("Langue not found");
@ -55,13 +56,13 @@ namespace DTOToEntity
public async Task<PageResponse<LangueDTO>> Gets(int index,int count)
{
IEnumerable<LangueEntity> langues = await _context.Langues.Skip(index * count).Take(count).ToListAsync();
return new PageResponse<LangueDTO>(langues.ToList().Select(l => l.ToDTO()), _context.Langues.Count());
IEnumerable<LangueEntity> langues = _context.LangueRepository.GetItems(index, count);
return new PageResponse<LangueDTO>(langues.ToList().Select(l => l.ToDTO()), _context.LangueRepository.GetItems(0, 1000000000).Count());
}
public async Task<LangueDTO> Update(LangueDTO langue)
{
LangueEntity? langueToUpdate = await _context.Langues.FindAsync(langue.name);
LangueEntity? langueToUpdate = _context.LangueRepository.GetById(langue.name);
if (langueToUpdate == null)
{
throw new Exception("Langue not found");

@ -1,4 +1,5 @@
using DTO;
using DbContextLib;
using DTO;
using Entities;
using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
@ -12,40 +13,41 @@ namespace DTOToEntity
{
public class RoleService : IService<RoleDTO>
{
private readonly StubbedContext _context = new StubbedContext();
private readonly UnitOfWork _context = new UnitOfWork();
public RoleService() { }
public RoleService(StubbedContext context)
{
_context = new UnitOfWork(context);
}
public RoleService(UnitOfWork context)
{
_context = context;
}
public async Task<RoleDTO> Add(RoleDTO role)
{
var roleEntity = role.ToEntity();
if(roleEntity == null)
{
throw new ArgumentNullException();
}
var res = _context.Roles.Add(roleEntity);
_context.RoleRepository.Insert(roleEntity);
await _context.SaveChangesAsync();
return res.Entity.ToDTO();
return role;
}
public async Task<RoleDTO> Delete(object id)
{
RoleEntity? role = await _context.Roles.FirstOrDefaultAsync(r => r.Id == (int)id);
RoleEntity role = _context.RoleRepository.GetById((long)id);
if (role == null)
{
throw new Exception("Role not found");
}
var res = _context.Roles.Remove(role);
_context.RoleRepository.Delete((long)id);
await _context.SaveChangesAsync();
return res.Entity.ToDTO();
return role.ToDTO();
}
public async Task<RoleDTO> GetById(object id)
{
RoleEntity? role = await _context.Roles.FirstOrDefaultAsync(r => r.Id == (int)id);
RoleEntity? role = _context.RoleRepository.GetById((long)id);
if (role == null)
{
throw new Exception("Role not found");
@ -55,8 +57,8 @@ namespace DTOToEntity
public async Task<PageResponse<RoleDTO>> Gets(int index, int count)
{
IEnumerable<RoleEntity> roles = await _context.Roles.Skip(index * count).Take(count).ToListAsync();
return new PageResponse<RoleDTO>(roles.ToList().Select(r => r.ToDTO()), _context.Roles.Count());
IEnumerable<RoleEntity> roles = _context.RoleRepository.GetItems(index, count);
return new PageResponse<RoleDTO>(roles.ToList().Select(r => r.ToDTO()), _context.RoleRepository.GetItems(0,1000000000).Count());
}
public async Task<RoleDTO> Update(RoleDTO role)
@ -65,12 +67,13 @@ namespace DTOToEntity
{
throw new ArgumentNullException();
}
var roleEntity = await _context.Roles.FindAsync(role.Id);
var roleEntity = _context.RoleRepository.GetById(role.Id);
if (roleEntity != null)
{
throw new Exception("role not found");
}
roleEntity.Name = role.Name;
_context.RoleRepository.Update(roleEntity);
await _context.SaveChangesAsync();
return roleEntity.ToDTO();
}

@ -1,4 +1,5 @@
using DTO;
using DbContextLib;
using DTO;
using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
using System;
@ -11,18 +12,18 @@ namespace DTOToEntity
{
public class TranslateService : ITranslateService
{
private readonly StubbedContext _context = new StubbedContext();
private readonly UnitOfWork _context = new UnitOfWork();
public TranslateService() { }
public TranslateService(StubbedContext context)
{
_context = context;
_context = new UnitOfWork(context);
}
public async Task<TranslateDTO> Add(TranslateDTO translate)
{
var translateEntity = translate.ToEntity();
_context.Translates.Add(translateEntity);
_context.TranslateRepository.Insert(translateEntity);
await _context.SaveChangesAsync();
return translateEntity.ToDTO();
@ -30,12 +31,12 @@ namespace DTOToEntity
public async Task<VocabularyDTO> AddVocabToTranslate(string vocabId, long translateId)
{
var vocab = _context.Vocabularys.Find(vocabId);
var vocab = _context.VocabularyRepository.GetById(vocabId);
if (vocab == null)
{
throw new Exception("Vocabulary not found");
}
var translate = _context.Translates.Find(translateId);
var translate = _context.TranslateRepository.GetById(translateId);
if (translate == null)
{
throw new Exception("Translate not found");
@ -47,10 +48,10 @@ namespace DTOToEntity
public async Task<TranslateDTO> Delete(object id)
{
var translate = await _context.Translates.FirstOrDefaultAsync(t => t.Id == (int)id);
var translate = _context.TranslateRepository.GetById((long)id);
if (translate != null)
{
_context.Translates.Remove(translate);
_context.TranslateRepository.Delete(translate);
await _context.SaveChangesAsync();
}
else
@ -62,7 +63,7 @@ namespace DTOToEntity
public async Task<TranslateDTO> GetById(object id)
{
var translate = await _context.Translates.FirstOrDefaultAsync(t => t.Id == (int)id);
var translate = _context.TranslateRepository.GetById((long)id);
if (translate == null)
{
throw new Exception("Translate not found");
@ -72,24 +73,24 @@ namespace DTOToEntity
public async Task<PageResponse<TranslateDTO>> Gets(int index, int count)
{
var translates = await _context.Translates.Skip(index * count).Take(count).ToListAsync();
var translates = _context.TranslateRepository.GetItems(index, count);
if(translates == null)
{
throw new Exception("No translates found");
}
return new PageResponse<TranslateDTO>( translates.Select(t => t.ToDTO()), _context.Translates.Count());
return new PageResponse<TranslateDTO>( translates.Select(t => t.ToDTO()), _context.TranslateRepository.GetItems(0, 100000000).Count());
}
public async Task<TranslateDTO> Update(TranslateDTO translate)
{
var translateEntity = await _context.Translates.FirstOrDefaultAsync(t => t.Id == translate.Id);
var translateEntity = _context.TranslateRepository.GetById(translate.Id);
if (translateEntity == null)
{
throw new Exception("Translate not found");
}
translateEntity.WordsId = translate.WordsId;
translateEntity.VocabularyListVocId = translate.VocabularyListVocId;
_context.Translates.Update(translateEntity);
_context.TranslateRepository.Update(translateEntity);
await _context.SaveChangesAsync();
return translateEntity.ToDTO();
}

@ -1,9 +1,11 @@
using DTO;
using DbContextLib;
using DTO;
using Entities;
using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -12,12 +14,12 @@ namespace DTOToEntity
{
public class UserService : IUserService
{
private StubbedContext _context = new StubbedContext();
private UnitOfWork _context = new UnitOfWork();
public UserService() { }
public UserService(StubbedContext context)
{
_context = context;
_context = new UnitOfWork(context);
}
public async Task<UserDTO> Add(UserDTO user)
{
@ -26,32 +28,32 @@ namespace DTOToEntity
{
throw new Exception("User Entity is null");
}
var result = _context.Users.Add(userEntity);
_context.UserRepository.Insert(userEntity);
await _context.SaveChangesAsync();
return result.Entity.ToDTO();
return user;
}
public async Task<UserDTO> Delete(object id)
{
UserEntity? user = await _context.Users.FirstOrDefaultAsync(u => u.Id == (long)id);
UserEntity? user = _context.UserRepository.GetById((long)id);
if(user == null)
{
throw new Exception("User not found");
}
_context.Users.Remove(user);
_context.UserRepository.Delete((long)id);
await _context.SaveChangesAsync();
return user.ToDTO();
}
public async Task<PageResponse<UserDTO>> GetByGroup(int index, int count, long group)
{
var users = _context.Users.Where(u => u.GroupId == group).Skip(index * count).Take(count);
return new PageResponse<UserDTO>(users.Select(u => u.ToDTO()), _context.Users.Count());
var users = _context.UserRepository.GetItems(index,count).Where(u => u.GroupId == group);
return new PageResponse<UserDTO>(users.Select(u => u.ToDTO()), _context.UserRepository.GetItems(0,1000000000).Count());
}
public async Task<UserDTO> GetById(object id)
{
var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == (long)id);
var user = _context.UserRepository.GetById((long)id);
if(user == null)
{
throw new Exception("User not found");
@ -62,14 +64,16 @@ namespace DTOToEntity
public async Task<PageResponse<UserDTO>> GetByRole(int index, int count, string role)
{
var users = _context.Users.Where(u => u.Role.Name == role).Skip(index * count).Take(count);
return new PageResponse<UserDTO>(users.Select(u => u.ToDTO()), _context.Users.Count());
var users = _context.UserRepository.GetItems(filter: u => u.Role != null && u.Role.Name == role,
index: index,
count: count);
return new PageResponse<UserDTO>(users.Select(u => u.ToDTO()), _context.UserRepository.GetItems(0, 1000000000).Count());
}
public async Task<PageResponse<UserDTO>> Gets(int index, int count)
{
IEnumerable<UserEntity> users = await _context.Users.Skip(index * count).Take(count).ToListAsync();
return new PageResponse<UserDTO>( users.Select(u => u.ToDTO()),_context.Users.Count());
IEnumerable<UserEntity> users = _context.UserRepository.GetItems(index, count) ;
return new PageResponse<UserDTO>( users.Select(u => u.ToDTO()),_context.UserRepository.GetItems(0, 1000000000).Count());
}
public async Task<UserDTO> Update(UserDTO user)
@ -78,7 +82,7 @@ namespace DTOToEntity
{
throw new Exception("User is null");
}
var existingUser = await _context.Users.FirstOrDefaultAsync(u => u.Id == user.Id);
var existingUser = _context.UserRepository.GetById(user.Id);
if(existingUser == null)
{
throw new Exception("User not found");

@ -1,4 +1,5 @@
using DTO;
using DbContextLib;
using DTO;
using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
using System;
@ -11,7 +12,7 @@ namespace DTOToEntity
{
public class VocabularyListService : IVocabularyListService
{
private StubbedContext _context = new StubbedContext();
private UnitOfWork _context = new UnitOfWork();
public VocabularyListService()
{
@ -19,24 +20,24 @@ namespace DTOToEntity
public VocabularyListService(StubbedContext context)
{
_context = context;
_context = new UnitOfWork(context);
}
public async Task<VocabularyListDTO> Add(VocabularyListDTO group)
{
var groupEntity = group.ToEntity();
_context.VocabularyLists.Add(groupEntity);
_context.VocabularyListRepository.Insert(groupEntity);
await _context.SaveChangesAsync();
return groupEntity.ToDTO();
}
public async Task<GroupDTO> AddGroupToVocabularyList(long groupId, long vocabId)
{
var group = _context.Groups.Find(groupId);
var group = _context.GroupRepository.GetById(groupId);
if (group == null)
{
throw new Exception("Group not found");
}
var vocab = _context.VocabularyLists.Find(vocabId);
var vocab = _context.VocabularyListRepository.GetById(vocabId);
if (vocab == null)
{
throw new Exception("Vocabulary List not found");
@ -49,10 +50,10 @@ namespace DTOToEntity
public async Task<VocabularyListDTO> Delete(object id)
{
var group = await _context.VocabularyLists.FindAsync(id);
var group = _context.VocabularyListRepository.GetById((long)id);
if (group != null)
{
_context.VocabularyLists.Remove(group);
_context.VocabularyListRepository.Delete(group);
await _context.SaveChangesAsync();
}
else
@ -64,7 +65,7 @@ namespace DTOToEntity
public async Task<VocabularyListDTO> GetById(object id)
{
var group = await _context.VocabularyLists.FindAsync(id);
var group = _context.VocabularyListRepository.GetById((long)id);
if (group == null)
{
throw new Exception("Group not found");
@ -74,15 +75,15 @@ namespace DTOToEntity
public async Task<PageResponse<VocabularyListDTO>> GetByUser(int index, int count, int user)
{
var groups = _context.VocabularyLists.Where(g => g.UserId == user).Skip(index * count).Take(count);
return new PageResponse<VocabularyListDTO>(groups.Select(g => g.ToDTO()), _context.VocabularyLists.Count());
var groups = _context.VocabularyListRepository.GetItems(filter: u => u.Id == user, index, count);
return new PageResponse<VocabularyListDTO>(groups.Select(g => g.ToDTO()), _context.VocabularyListRepository.GetItems(0,1000000000).Count());
}
public async Task<PageResponse<VocabularyListDTO>> Gets(int index, int count)
{
var groups = await _context.VocabularyLists.Skip(index * count).Take(count).ToListAsync();
return new PageResponse<VocabularyListDTO>(groups.Select(g => g.ToDTO()), _context.VocabularyLists.Count());
var groups = _context.VocabularyListRepository.GetItems(index, count);
return new PageResponse<VocabularyListDTO>(groups.Select(g => g.ToDTO()), _context.VocabularyListRepository.GetItems(0, 1000000000).Count());
}
public async Task<VocabularyListDTO> Update(VocabularyListDTO group)
@ -92,9 +93,9 @@ namespace DTOToEntity
{
throw new Exception("Group Entity is null");
}
var res = _context.VocabularyLists.Update(groupEntity);
_context.VocabularyListRepository.Update(groupEntity);
await _context.SaveChangesAsync();
return res.Entity.ToDTO();
return group;
}
}
}

@ -1,4 +1,5 @@
using DTO;
using DbContextLib;
using DTO;
using Entities;
using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
@ -12,13 +13,13 @@ namespace DTOToEntity
{
public class VocabularyService : IVocabularyService
{
private readonly StubbedContext _context = new StubbedContext();
private readonly UnitOfWork _context = new UnitOfWork();
public VocabularyService() { }
public VocabularyService(StubbedContext context)
{
_context = context;
_context = new UnitOfWork(context);
}
public async Task<VocabularyDTO> Add(VocabularyDTO vocabulary)
{
@ -27,19 +28,19 @@ namespace DTOToEntity
{
throw new ArgumentNullException();
}
await _context.Vocabularys.AddAsync(vocabularyEntity);
_context.VocabularyRepository.Insert(vocabularyEntity);
await _context.SaveChangesAsync();
return vocabularyEntity.ToDTO();
}
public async Task<TranslateDTO> AddTranslationToVocabulary(string vocabId, long translateId)
{
var vocabulary = _context.Vocabularys.Find(vocabId);
var vocabulary = _context.VocabularyRepository.GetById(vocabId);
if(vocabulary == null)
{
throw new Exception("Vocabulary not found");
}
var translate = _context.Translates.Find(translateId);
var translate = _context.TranslateRepository.GetById(translateId);
if(translate == null)
{
throw new Exception("Translate not found");
@ -51,19 +52,19 @@ namespace DTOToEntity
public async Task<VocabularyDTO> Delete(object id)
{
var vocabulary = await _context.Vocabularys.FirstOrDefaultAsync(v => v.word == (string)id);
var vocabulary = _context.VocabularyRepository.GetById((string)id);
if(vocabulary == null)
{
throw new Exception("Vocabulary not found");
}
_context.Vocabularys.Remove(vocabulary);
_context.VocabularyRepository.Delete(vocabulary);
await _context.SaveChangesAsync();
return vocabulary.ToDTO();
}
public async Task<VocabularyDTO> GetById(object id)
{
var vocabulary = await _context.Vocabularys.FirstOrDefaultAsync(v => v.word == (string)id);
var vocabulary = _context.VocabularyRepository.GetById((string)id);
if(vocabulary == null)
{
throw new Exception("Vocabulary not found");
@ -73,15 +74,15 @@ namespace DTOToEntity
public async Task<PageResponse<VocabularyDTO>> GetByLangue(int index, int count, string langue)
{
var vocabularies = _context.Vocabularys.Where(v => v.LangueName == langue).Skip(index * count).Take(count);
return new PageResponse<VocabularyDTO>(vocabularies.ToList().Select(v => v.ToDTO()), _context.Vocabularys.Count());
var vocabularies = _context.VocabularyRepository.GetItems(filter: v => v.LangueName == langue, index, count);
return new PageResponse<VocabularyDTO>(vocabularies.ToList().Select(v => v.ToDTO()), _context.VocabularyRepository.GetItems(0,100000000).Count());
}
public async Task<PageResponse<VocabularyDTO>> Gets(int index, int count)
{
var vocabulary = await _context.Vocabularys.Skip(index * count).Take(count).ToListAsync();
return new PageResponse<VocabularyDTO>(vocabulary.Select(v => v.ToDTO()), _context.Vocabularys.Count());
var vocabulary = _context.VocabularyRepository.GetItems(index, count);
return new PageResponse<VocabularyDTO>(vocabulary.Select(v => v.ToDTO()), _context.VocabularyRepository.GetItems(0, 100000000).Count());
}
public async Task<VocabularyDTO> Update(VocabularyDTO vocabulary)
@ -91,7 +92,7 @@ namespace DTOToEntity
{
throw new Exception("vocabulary not valid");
}
var VocabToUpdate = _context.Vocabularys.FirstOrDefault(v => v.word == (string)vocabularyEntity.word);
var VocabToUpdate = _context.VocabularyRepository.GetById(vocabulary.word);
if(VocabToUpdate == null)
{
throw new Exception("vocabulary not found");

@ -15,8 +15,11 @@ namespace DbContextLib
public DbSet<VocabularyEntity> Vocabularys { get; set; }
public DbSet<VocabularyListEntity> VocabularyLists { get; set; }
<<<<<<< HEAD
=======
>>>>>>> master
//permet de créer une base de donnée (fichier .db) ici en Sqlite avec le nom Db.Books.db

@ -0,0 +1,169 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace DbContextLib
{
public class GenericRepository<TEntity> where TEntity : class
{
private DbContext Context { get; set; }
private DbSet<TEntity> Set { get; set; }
public GenericRepository(DbContext context)
{
Context = context;
Set = Context.Set<TEntity>();
}
public virtual TEntity? GetById(object id)
{
return Context.Set<TEntity>().Find(id);
}
public virtual IEnumerable<TEntity> GetItems(Expression<Func<TEntity, bool>>? filter = null,
int index = 0, int count = 10,
params string[] includeProperties)
=> GetItems(filter, null, index, count, includeProperties);
public virtual IEnumerable<TEntity> GetItems(Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>? orderBy = null,
int index = 0, int count = 10,
params string[] includeProperties)
=> GetItems(null, orderBy, index, count, includeProperties);
public virtual IEnumerable<TEntity> GetItems(int index = 0, int count = 10,
params string[] includeProperties)
=> GetItems(null, null, index, count, includeProperties);
public virtual IEnumerable<TEntity> GetItems(Expression<Func<TEntity, bool>>? filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>? orderBy = null,
int index = 0, int count = 10,
params string[] includeProperties)
{
IQueryable<TEntity> query = Set;
if (filter != null)
{
query = query.Where(filter);
}
foreach (string includeProperty in includeProperties)
{
query = query.Include(includeProperty);
}
if (orderBy != null)
{
query = orderBy(query);
}
return query.Skip(index * count)
.Take(count)
.ToList();
}
public virtual void Insert(TEntity entity)
{
var primaryKeyProperty = Context.Model.FindEntityType(typeof(TEntity)).FindPrimaryKey().Properties.FirstOrDefault();
if (primaryKeyProperty != null)
{
var parameter = Expression.Parameter(typeof(TEntity), "x");
var property = Expression.Property(parameter, primaryKeyProperty.Name);
var idValue = Expression.Constant(primaryKeyProperty.GetGetter().GetClrValue(entity));
var equal = Expression.Equal(property, idValue);
var lambda = Expression.Lambda<Func<TEntity, bool>>(equal, parameter);
var existingEntity = Set.Local.FirstOrDefault(lambda.Compile());
if (existingEntity != null)
{
Set.Entry(existingEntity).Property("Count").CurrentValue = (int)Set.Entry(existingEntity).Property("Count").CurrentValue + 1;
}
else
{
Set.Add(entity);
}
}
else
{
throw new InvalidOperationException("Cannot find primary key property for entity type.");
}
}
public virtual void Insert(params TEntity[] entities)
{
foreach (var entity in entities)
{
Insert(entity);
}
}
public virtual void Delete(object id)
{
TEntity? entity = Set.Find(id);
if (entity == null) return;
Delete(entity);
}
public virtual void Delete(TEntity entity)
{
var primaryKeyProperty = Context.Model.FindEntityType(typeof(TEntity)).FindPrimaryKey().Properties.FirstOrDefault();
if (primaryKeyProperty != null)
{
var parameter = Expression.Parameter(typeof(TEntity), "x");
var property = Expression.Property(parameter, primaryKeyProperty.Name);
var idValue = Expression.Constant(primaryKeyProperty.GetGetter().GetClrValue(entity));
var equal = Expression.Equal(property, idValue);
var lambda = Expression.Lambda<Func<TEntity, bool>>(equal, parameter);
var existingEntity = Set.Local.FirstOrDefault(lambda.Compile());
if (existingEntity == null)
{
if (Context.Entry(entity).State == EntityState.Detached)
{
Set.Attach(entity);
}
Set.Remove(entity);
}
else
{
Set.Remove(existingEntity);
}
}
else
{
throw new InvalidOperationException("Cannot find primary key property for entity type.");
}
}
public virtual void Update(TEntity entity)
{
var primaryKeyProperty = Context.Model.FindEntityType(typeof(TEntity)).FindPrimaryKey().Properties.FirstOrDefault();
if (primaryKeyProperty != null)
{
var parameter = Expression.Parameter(typeof(TEntity), "x");
var property = Expression.Property(parameter, primaryKeyProperty.Name);
var idValue = Expression.Constant(primaryKeyProperty.GetGetter().GetClrValue(entity));
var equal = Expression.Equal(property, idValue);
var lambda = Expression.Lambda<Func<TEntity, bool>>(equal, parameter);
var existingEntity = Set.Local.FirstOrDefault(lambda.Compile());
if (existingEntity != null)
{
Context.Entry(existingEntity).CurrentValues.SetValues(entity);
}
else
{
Set.Attach(entity);
Context.Entry(entity).State = EntityState.Modified;
}
}
else
{
throw new InvalidOperationException("Cannot find primary key property for entity type.");
}
}
}
}

@ -10,7 +10,11 @@ using StubbedContextLib;
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(StubbedContext))]
<<<<<<<< HEAD:Project/EntityFramework/StubbedContext/Migrations/20240330163827_newMigs.Designer.cs
[Migration("20240330163827_newMigs")]
========
[Migration("20240331212614_newMigs")]
>>>>>>>> master:Project/EntityFramework/StubbedContext/Migrations/20240331212614_newMigs.Designer.cs
partial class newMigs
{
/// <inheritdoc />

@ -0,0 +1,416 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using StubbedContextLib;
#nullable disable
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(StubbedContext))]
<<<<<<<< HEAD:Project/EntityFramework/StubbedContext/Migrations/20240330163827_newMigs.Designer.cs
[Migration("20240330163827_newMigs")]
========
[Migration("20240331212614_newMigs")]
>>>>>>>> master:Project/EntityFramework/StubbedContext/Migrations/20240331212614_newMigs.Designer.cs
partial class newMigs
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
modelBuilder.Entity("Entities.GroupEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Num")
.HasColumnType("INTEGER");
b.Property<string>("sector")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("year")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Groups");
b.HasData(
new
{
Id = 1L,
Num = 1,
sector = "informatics",
year = 1
});
});
modelBuilder.Entity("Entities.LangueEntity", b =>
{
b.Property<string>("name")
.HasColumnType("TEXT");
b.HasKey("name");
b.ToTable("Langues");
b.HasData(
new
{
name = "French"
},
new
{
name = "English"
});
});
modelBuilder.Entity("Entities.RoleEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Roles");
b.HasData(
new
{
Id = 1L,
Name = "Admin"
},
new
{
Id = 2L,
Name = "Teacher"
},
new
{
Id = 3L,
Name = "Student"
});
});
modelBuilder.Entity("Entities.TranslateEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<long>("VocabularyListVocId")
.HasColumnType("INTEGER");
b.Property<string>("WordsId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VocabularyListVocId");
b.ToTable("Translates");
b.HasData(
new
{
Id = 1L,
VocabularyListVocId = 1L,
WordsId = "1"
});
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("ExtraTime")
.HasColumnType("INTEGER");
b.Property<long>("GroupId")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("NickName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.Property<long>("RoleId")
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("image")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("GroupId");
b.HasIndex("RoleId");
b.ToTable("Users");
b.HasData(
new
{
Id = 1L,
Email = "",
ExtraTime = true,
GroupId = 1L,
Name = "name",
NickName = "nickname",
Password = "1234",
RoleId = 1L,
UserName = "username"
},
new
{
Id = 2L,
Email = "",
ExtraTime = true,
GroupId = 1L,
Name = "name2",
NickName = "nickname2",
Password = "1234",
RoleId = 2L,
UserName = "username2"
},
new
{
Id = 3L,
Email = "",
ExtraTime = true,
GroupId = 1L,
Name = "name3",
NickName = "nickname3",
Password = "1234",
RoleId = 3L,
UserName = "username3"
});
});
modelBuilder.Entity("Entities.VocabularyEntity", b =>
{
b.Property<string>("word")
.HasColumnType("TEXT");
b.Property<string>("LangueName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("word");
b.HasIndex("LangueName");
b.ToTable("Vocabularys");
b.HasData(
new
{
word = "Bonjour",
LangueName = "French"
});
});
modelBuilder.Entity("Entities.VocabularyListEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<long>("UserId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("VocabularyLists");
b.HasData(
new
{
Id = 1L,
Image = "image1",
Name = "Liste1",
UserId = 1L
});
});
modelBuilder.Entity("GroupEntityVocabularyListEntity", b =>
{
b.Property<long>("GroupVocabularyListId")
.HasColumnType("INTEGER");
b.Property<long>("VocsGroupsId")
.HasColumnType("INTEGER");
b.HasKey("GroupVocabularyListId", "VocsGroupsId");
b.HasIndex("VocsGroupsId");
b.ToTable("GroupEntityVocabularyListEntity");
});
modelBuilder.Entity("TranslateEntityVocabularyEntity", b =>
{
b.Property<string>("TransVocword")
.HasColumnType("TEXT");
b.Property<long>("VoctranslationsId")
.HasColumnType("INTEGER");
b.HasKey("TransVocword", "VoctranslationsId");
b.HasIndex("VoctranslationsId");
b.ToTable("TranslateEntityVocabularyEntity");
});
modelBuilder.Entity("Entities.TranslateEntity", b =>
{
b.HasOne("Entities.VocabularyListEntity", "VocabularyListVoc")
.WithMany("translations")
.HasForeignKey("VocabularyListVocId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("VocabularyListVoc");
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.HasOne("Entities.GroupEntity", "Group")
.WithMany("Users")
.HasForeignKey("GroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.RoleEntity", "Role")
.WithMany("Users")
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
b.Navigation("Role");
});
modelBuilder.Entity("Entities.VocabularyEntity", b =>
{
b.HasOne("Entities.LangueEntity", "Langue")
.WithMany("vocabularys")
.HasForeignKey("LangueName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Langue");
});
modelBuilder.Entity("Entities.VocabularyListEntity", b =>
{
b.HasOne("Entities.UserEntity", "User")
.WithMany("VocabularyList")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("GroupEntityVocabularyListEntity", b =>
{
b.HasOne("Entities.VocabularyListEntity", null)
.WithMany()
.HasForeignKey("GroupVocabularyListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.GroupEntity", null)
.WithMany()
.HasForeignKey("VocsGroupsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("TranslateEntityVocabularyEntity", b =>
{
b.HasOne("Entities.VocabularyEntity", null)
.WithMany()
.HasForeignKey("TransVocword")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.TranslateEntity", null)
.WithMany()
.HasForeignKey("VoctranslationsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Entities.GroupEntity", b =>
{
b.Navigation("Users");
});
modelBuilder.Entity("Entities.LangueEntity", b =>
{
b.Navigation("vocabularys");
});
modelBuilder.Entity("Entities.RoleEntity", b =>
{
b.Navigation("Users");
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.Navigation("VocabularyList");
});
modelBuilder.Entity("Entities.VocabularyListEntity", b =>
{
b.Navigation("translations");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,310 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class newMigs : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Num = table.Column<int>(type: "INTEGER", nullable: false),
year = table.Column<int>(type: "INTEGER", nullable: false),
sector = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Langues",
columns: table => new
{
name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Langues", x => x.name);
});
migrationBuilder.CreateTable(
name: "Roles",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Roles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Vocabularys",
columns: table => new
{
word = table.Column<string>(type: "TEXT", nullable: false),
LangueName = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Vocabularys", x => x.word);
table.ForeignKey(
name: "FK_Vocabularys_Langues_LangueName",
column: x => x.LangueName,
principalTable: "Langues",
principalColumn: "name",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Password = table.Column<string>(type: "TEXT", nullable: false),
Email = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
UserName = table.Column<string>(type: "TEXT", nullable: false),
NickName = table.Column<string>(type: "TEXT", nullable: false),
image = table.Column<string>(type: "TEXT", nullable: true),
GroupId = table.Column<long>(type: "INTEGER", nullable: false),
RoleId = table.Column<long>(type: "INTEGER", nullable: false),
ExtraTime = table.Column<bool>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
table.ForeignKey(
name: "FK_Users_Groups_GroupId",
column: x => x.GroupId,
principalTable: "Groups",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Users_Roles_RoleId",
column: x => x.RoleId,
principalTable: "Roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "VocabularyLists",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: false),
UserId = table.Column<long>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_VocabularyLists", x => x.Id);
table.ForeignKey(
name: "FK_VocabularyLists_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GroupEntityVocabularyListEntity",
columns: table => new
{
GroupVocabularyListId = table.Column<long>(type: "INTEGER", nullable: false),
VocsGroupsId = table.Column<long>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GroupEntityVocabularyListEntity", x => new { x.GroupVocabularyListId, x.VocsGroupsId });
table.ForeignKey(
name: "FK_GroupEntityVocabularyListEntity_Groups_VocsGroupsId",
column: x => x.VocsGroupsId,
principalTable: "Groups",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GroupEntityVocabularyListEntity_VocabularyLists_GroupVocabularyListId",
column: x => x.GroupVocabularyListId,
principalTable: "VocabularyLists",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Translates",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
WordsId = table.Column<string>(type: "TEXT", nullable: false),
VocabularyListVocId = table.Column<long>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Translates", x => x.Id);
table.ForeignKey(
name: "FK_Translates_VocabularyLists_VocabularyListVocId",
column: x => x.VocabularyListVocId,
principalTable: "VocabularyLists",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TranslateEntityVocabularyEntity",
columns: table => new
{
TransVocword = table.Column<string>(type: "TEXT", nullable: false),
VoctranslationsId = table.Column<long>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TranslateEntityVocabularyEntity", x => new { x.TransVocword, x.VoctranslationsId });
table.ForeignKey(
name: "FK_TranslateEntityVocabularyEntity_Translates_VoctranslationsId",
column: x => x.VoctranslationsId,
principalTable: "Translates",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TranslateEntityVocabularyEntity_Vocabularys_TransVocword",
column: x => x.TransVocword,
principalTable: "Vocabularys",
principalColumn: "word",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "Groups",
columns: new[] { "Id", "Num", "sector", "year" },
values: new object[] { 1L, 1, "informatics", 1 });
migrationBuilder.InsertData(
table: "Langues",
column: "name",
values: new object[]
{
"English",
"French"
});
migrationBuilder.InsertData(
table: "Roles",
columns: new[] { "Id", "Name" },
values: new object[,]
{
{ 1L, "Admin" },
{ 2L, "Teacher" },
{ 3L, "Student" }
});
migrationBuilder.InsertData(
table: "Users",
columns: new[] { "Id", "Email", "ExtraTime", "GroupId", "Name", "NickName", "Password", "RoleId", "UserName", "image" },
values: new object[,]
{
{ 1L, "", true, 1L, "name", "nickname", "1234", 1L, "username", null },
{ 2L, "", true, 1L, "name2", "nickname2", "1234", 2L, "username2", null },
{ 3L, "", true, 1L, "name3", "nickname3", "1234", 3L, "username3", null }
});
migrationBuilder.InsertData(
table: "Vocabularys",
columns: new[] { "word", "LangueName" },
values: new object[] { "Bonjour", "French" });
migrationBuilder.InsertData(
table: "VocabularyLists",
columns: new[] { "Id", "Image", "Name", "UserId" },
values: new object[] { 1L, "image1", "Liste1", 1L });
migrationBuilder.InsertData(
table: "Translates",
columns: new[] { "Id", "VocabularyListVocId", "WordsId" },
values: new object[] { 1L, 1L, "1" });
migrationBuilder.CreateIndex(
name: "IX_GroupEntityVocabularyListEntity_VocsGroupsId",
table: "GroupEntityVocabularyListEntity",
column: "VocsGroupsId");
migrationBuilder.CreateIndex(
name: "IX_TranslateEntityVocabularyEntity_VoctranslationsId",
table: "TranslateEntityVocabularyEntity",
column: "VoctranslationsId");
migrationBuilder.CreateIndex(
name: "IX_Translates_VocabularyListVocId",
table: "Translates",
column: "VocabularyListVocId");
migrationBuilder.CreateIndex(
name: "IX_Users_GroupId",
table: "Users",
column: "GroupId");
migrationBuilder.CreateIndex(
name: "IX_Users_RoleId",
table: "Users",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_VocabularyLists_UserId",
table: "VocabularyLists",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Vocabularys_LangueName",
table: "Vocabularys",
column: "LangueName");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "GroupEntityVocabularyListEntity");
migrationBuilder.DropTable(
name: "TranslateEntityVocabularyEntity");
migrationBuilder.DropTable(
name: "Translates");
migrationBuilder.DropTable(
name: "Vocabularys");
migrationBuilder.DropTable(
name: "VocabularyLists");
migrationBuilder.DropTable(
name: "Langues");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Groups");
migrationBuilder.DropTable(
name: "Roles");
}
}
}

@ -0,0 +1,197 @@
using Entities;
using Microsoft.EntityFrameworkCore;
using StubbedContextLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DbContextLib
{
public class UnitOfWork : IDisposable
{
private bool disposed = false;
private GenericRepository<GroupEntity>? groupRepository;
private GenericRepository<LangueEntity>? langueRepository;
private GenericRepository<RoleEntity>? roleRepository;
private GenericRepository<TranslateEntity>? translateRepository;
private GenericRepository<UserEntity>? userRepository;
private GenericRepository<VocabularyEntity>? vocabularyRepository;
private GenericRepository<VocabularyListEntity>? vocabularyListRepository;
private SAEContext _context { get; set; }
public UnitOfWork(SAEContext context) {
_context = context;
_context.Database.EnsureCreated();
}
public UnitOfWork(StubbedContext context)
{
_context = context;
_context.Database.EnsureCreated();
}
public UnitOfWork(DbContextOptions<SAEContext> options)
: this(new StubbedContext(options))
{
}
public UnitOfWork()
: this(new StubbedContext())
{
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed && disposing)
{
_context.Dispose();
}
this.disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public GenericRepository<GroupEntity> GroupRepository
{
get
{
if (groupRepository == null)
{
groupRepository = new GenericRepository<GroupEntity>(_context);
}
return groupRepository;
}
}
public GenericRepository<LangueEntity> LangueRepository
{
get
{
if (langueRepository == null)
{
langueRepository = new GenericRepository<LangueEntity>(_context);
}
return langueRepository;
}
}
public GenericRepository<RoleEntity> RoleRepository
{
get
{
if (roleRepository == null)
{
roleRepository = new GenericRepository<RoleEntity>(_context);
}
return roleRepository;
}
}
public GenericRepository<TranslateEntity> TranslateRepository
{
get
{
if (translateRepository == null)
{
translateRepository = new GenericRepository<TranslateEntity>(_context);
}
return translateRepository;
}
}
public GenericRepository<UserEntity> UserRepository
{
get
{
if (userRepository == null)
{
userRepository = new GenericRepository<UserEntity>(_context);
}
return userRepository;
}
}
public GenericRepository<VocabularyEntity> VocabularyRepository
{
get
{
if (vocabularyRepository == null)
{
vocabularyRepository = new GenericRepository<VocabularyEntity>(_context);
}
return vocabularyRepository;
}
}
public GenericRepository<VocabularyListEntity> VocabularyListRepository
{
get
{
if (vocabularyListRepository == null)
{
vocabularyListRepository = new GenericRepository<VocabularyListEntity>(_context);
}
return vocabularyListRepository;
}
}
public async Task<int> SaveChangesAsync()
{
int result = 0;
try
{
result = await _context.SaveChangesAsync();
}
catch
{
RejectChanges();
return -1;
}
foreach (var entity in _context.ChangeTracker.Entries()
.Where(e => e.State != EntityState.Detached))
{
entity.State = EntityState.Detached;
}
return result;
}
public void RejectChanges()
{
foreach (var entry in _context.ChangeTracker.Entries()
.Where(e => e.State != EntityState.Unchanged))
{
switch (entry.State)
{
case EntityState.Added:
entry.State = EntityState.Detached;
break;
case EntityState.Modified:
case EntityState.Deleted:
entry.Reload();
break;
}
}
}
}
}

@ -289,34 +289,8 @@ namespace TU
}
}
[TestMethod]
public async Task TestAddVocabListToGroup()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<SAEContext>()
.UseSqlite(connection)
.Options;
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var mockLogger = new Mock<ILogger<GroupController>>();
var controller = new GroupController(new GroupService(context), mockLogger.Object);
var result = await controller.AddVocabularyListToGroup(1, 1);
Assert.IsNotNull(result.Value);
Assert.AreEqual(1, result.Value.Id);
var test = await context.Groups.FirstOrDefaultAsync(g => g.Id == 1);
var testVocab = await context.VocabularyLists.FirstOrDefaultAsync(g => g.Id == 1);
Assert.IsNotNull(test);
Assert.IsNotNull(testVocab);
Assert.AreEqual(test.GroupVocabularyList.First(), testVocab);
}
}
}
}

@ -31,7 +31,7 @@ namespace TU
var controller = new RoleController(new RoleService(context), mockLogger.Object);
var newRole = new RoleDTO { Id = 100, Name = "test" };
var newRole = new RoleDTO { Id = 1, Name = "test" };
var result = await controller.AddRole(newRole);
@ -39,7 +39,7 @@ namespace TU
//ici on met 4 pour verifier que le Id n'est pas celui que l'on donne mais bien : CountList + 1
Assert.AreEqual(4, result.Value.Id);
Assert.AreEqual("test", result.Value.Name);
var test = await context.Roles.FirstOrDefaultAsync(r => r.Id == 4);
var test = context.Roles.Find((long)4);
Assert.IsNotNull(test);
}
}
@ -60,12 +60,11 @@ namespace TU
var mockLogger = new Mock<ILogger<RoleController>>();
var controller = new RoleController(new RoleService(context), mockLogger.Object);
var result = await controller.DeleteRole(3);
var result = await controller.DeleteRole(1);
Assert.IsNotNull(result.Value);
Assert.AreEqual(3, result.Value.Id);
Assert.AreEqual("Student", result.Value.Name);
var test = await context.Roles.FirstOrDefaultAsync(r => r.Id == 3);
Assert.AreEqual(1, result.Value.Id);
Assert.AreEqual("Admin", result.Value.Name);
var test = context.Roles.Find((long)1);
Assert.IsNull(test);
}
}
@ -86,10 +85,11 @@ namespace TU
var controller = new RoleController(new RoleService(context), mockLogger.Object);
var result = await controller.GetRole(3);
var result = await controller.GetRole((long)1);
Assert.IsNotNull(result.Value);
Assert.AreEqual(3, result.Value.Id);
Assert.AreEqual("Student", result.Value.Name);
Assert.AreEqual(1, result.Value.Id);
Assert.AreEqual("Admin", result.Value.Name);
}
}

@ -64,7 +64,6 @@ namespace TU
var controller = new TranslateController(new TranslateService(context), mockLogger.Object);
var result = await controller.GetTranslate(1);
Assert.IsNotNull(result.Value);
Assert.AreEqual(1, result.Value.Id);
@ -148,6 +147,9 @@ namespace TU
}
}
<<<<<<< HEAD
=======
>>>>>>> master
}
}

@ -15,21 +15,10 @@ var options = new DbContextOptionsBuilder<SAEContext>()
.UseSqlite(connection)
.Options;
Console.WriteLine("Test Users : \n\n");
using (var context = new StubbedContext(options))
Console.WriteLine("\n\nTest Users : \n\n");
using (var uow = new UnitOfWork(options))
{
context.Database.EnsureCreated();
var users = context.Users.ToList();
Console.WriteLine("Users: " + users.Count);
var roles = context.Roles.ToList();
Console.WriteLine("Roles: " + roles.Count);
Console.WriteLine("\ntest show 5 first Users : \n");
foreach (var user in context.Users.Take(5))
{
Console.WriteLine(user.toString());
}
var users = uow.UserRepository;
var user1 = new UserEntity
{
Name = "name4",
@ -43,101 +32,110 @@ using (var context = new StubbedContext(options))
image = "image4",
};
context.Users.Add(user1);
context.SaveChanges();
Console.WriteLine("\ntest ajout (1 user suplementaire normalement) \n");
foreach (var user in context.Users.Take(5))
users.Insert(user1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest ajout (1 user supplémentaire normalement) \n");
foreach (var user in users.GetItems(0, 5))
{
Console.WriteLine(user.toString());
}
user1.Name = "updated";
context.Users.Update(user1);
context.SaveChanges();
Console.WriteLine("\ntest update (le nom doit etre 'updated') \n");
users.Update(user1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest update (le nom doit être 'updated') \n");
Console.WriteLine(user1.toString());
context.Users.Remove(user1);
context.SaveChanges();
users.Delete(user1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest suppression\n");
foreach (var user in context.Users.Take(5))
foreach (var user in users.GetItems(0, 5))
{
Console.WriteLine(user.toString());
}
}
Console.WriteLine("\n\nTest VocsGroups : \n\n");
var groups = context.Groups.ToList();
Console.WriteLine("VocsGroups: " + groups.Count);
Console.WriteLine("\ntest show 5 first VocsGroups : \n");
foreach (var group in context.Groups.Take(5))
Console.WriteLine("\n\nTest VocsGroups : \n\n");
using (var uow = new UnitOfWork(options))
{
var groups = uow.GroupRepository;
var users = uow.UserRepository;
var user1 = new UserEntity
{
Console.WriteLine(group.toString());
}
Name = "name4",
UserName = "username4",
NickName = "nickname4",
ExtraTime = true,
GroupId = 1,
Password = "12344",
Email = "",
RoleId = 3,
image = "image4",
};
var group1 = new GroupEntity
{
Id = 4,
Num = 4,
year = 4,
sector = "sector4",
Users = [user1],
Users = new List<UserEntity> { user1 }
};
context.Groups.Add(group1);
context.SaveChanges();
groups.Insert(group1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest ajout (1 group suplementaire normalement) \n");
foreach (var group in context.Groups.Take(5))
Console.WriteLine("\ntest ajout (1 group supplémentaire normalement) \n");
foreach (var group in groups.GetItems(0, 5))
{
Console.WriteLine(group.toString());
}
group1.Num = 5;
group1.sector = "updated";
context.Update(group1);
context.SaveChanges();
Console.WriteLine("\ntest update (le nom doit etre 'updated' et le Num = 5) \n");
groups.Update(group1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest update (le nom doit être 'updated' et le Num = 5) \n");
Console.WriteLine(group1.toString());
Console.WriteLine("\n test utilisateur du groupe normalement le user : updated ");
foreach (var group in context.Groups.Take(5))
foreach (var group in groups.GetItems(0, 5))
{
foreach (var user in group.Users.Take(5))
foreach (var user in users.GetItems(0, 5))
{
Console.WriteLine(user.toString());
}
}
context.Remove(group1);
context.SaveChanges();
groups.Delete(group1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest suppression\n");
foreach (var group in context.Groups.Take(5))
foreach (var group in groups.GetItems(0, 5))
{
Console.WriteLine(group.toString());
}
}
Console.WriteLine("\n\nTest Langue : \n\n");
Console.WriteLine("\n\nTest Langue : \n\n");
using (var uow = new UnitOfWork(options))
{
var langues = uow.LangueRepository;
context.Database.EnsureCreated();
var langues = context.Langues.ToList();
Console.WriteLine("Langues: " + langues.Count);
Console.WriteLine("\ntest show 5 first Langues : \n");
foreach (var langue in context.Langues.Take(5))
foreach (var langue in langues.GetItems(0, 5))
{
Console.WriteLine(langue.name);
}
Console.WriteLine("\n ajout Langue (normalement chinese\n");
var langue1 = new LangueEntity
{
name = "Chinese"
};
context.Langues.Add(langue1);
context.SaveChanges();
foreach (var langue in context.Langues.Take(5))
langues.Insert(langue1);
await uow.SaveChangesAsync();
foreach (var langue in langues.GetItems(0, 5))
{
Console.WriteLine(langue.name);
}
Console.WriteLine("\n test des liens langues <=> vocabulaires (resultat attendu : 'word1 Chinese'\n");
var vocabularyList1 = new VocabularyEntity
{
@ -145,205 +143,200 @@ using (var context = new StubbedContext(options))
LangueName = "Chinese",
Langue = langue1
};
context.Vocabularys.Add(vocabularyList1);
foreach (var langue in context.Langues.Take(5))
uow.VocabularyRepository.Insert(vocabularyList1);
await uow.SaveChangesAsync();
foreach (var langue in langues.GetItems(0, 5))
{
foreach (var vocabularyList in langue.vocabularys.Take(5))
foreach (var vocabularyList in langue.vocabularys)
{
Console.WriteLine(vocabularyList.toString());
}
}
context.Langues.Remove(langue1);
context.SaveChanges();
langues.Delete(langue1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest suppression (il n'y a normalement plus la langue 'Chinese'\n");
foreach (var langue in context.Langues.Take(5))
foreach (var langue in langues.GetItems(0, 5))
{
Console.WriteLine(langue.name);
}
Console.WriteLine("\n\nTest Roles : \n\n");
context.Database.EnsureCreated();
var roles2 = context.Roles.ToList();
Console.WriteLine("Roles: " + roles2.Count);
}
Console.WriteLine("\n\nTest Roles : \n\n");
using (var uow = new UnitOfWork(options))
{
var roles = uow.RoleRepository;
Console.WriteLine("\ntest show 5 first Roles : \n");
foreach (var role in context.Roles.Take(5))
foreach (var role in roles.GetItems(0, 5))
{
Console.WriteLine(role.toString());
}
var role1 = new RoleEntity
{
Id = 4,
Name = "Role4"
};
context.Roles.Add(role1);
context.SaveChanges();
roles.Insert(role1);
await uow.SaveChangesAsync();
Console.WriteLine("\n ajout Role (normalement Role4\n");
foreach (var role in context.Roles.Take(5))
foreach (var role in roles.GetItems(0, 5))
{
Console.WriteLine(role.toString());
}
role1.Name = "updated";
context.Roles.Update(role1);
context.SaveChanges();
Console.WriteLine("\ntest update (le nom doit etre 'updated') \n");
roles.Update(role1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest update (le nom doit être 'updated') \n");
Console.WriteLine(role1.toString());
Console.WriteLine("\n test utilisateur du role normalement");
foreach (var role in context.Roles.Take(5))
foreach (var role in roles.GetItems(0, 5))
{
foreach (var user in role.Users.Take(5))
foreach (var user in role.Users)
{
Console.WriteLine(user.toString());
}
}
context.Roles.Remove(role1);
context.SaveChanges();
roles.Delete(role1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest suppression (il n'y a normalement plus le role 'Role4'\n");
foreach (var role in context.Roles.Take(5))
foreach (var role in roles.GetItems(0, 5))
{
Console.WriteLine(role.toString());
}
Console.WriteLine("\n\nTest Translate : \n\n");
context.Database.EnsureCreated();
var translates = context.Translates.ToList();
Console.WriteLine("Translates: " + translates.Count);
}
Console.WriteLine("\n\nTest Translate : \n\n");
using (var uow = new UnitOfWork(options))
{
var translates = uow.TranslateRepository;
Console.WriteLine("\ntest show 5 first Translates : \n");
foreach (var translate in context.Translates.Take(5))
foreach (var translate in translates.GetItems(0, 5))
{
Console.WriteLine(translate.toString());
}
var translate1 = new TranslateEntity
{
Id = 4,
WordsId = "Bonjour",
VocabularyListVocId = 1
};
context.Translates.Add(translate1);
context.SaveChanges();
};
translates.Insert(translate1);
await uow.SaveChangesAsync();
Console.WriteLine("\n ajout Translate (normalement word4\n");
foreach (var translate in context.Translates.Take(5))
foreach (var translate in translates.GetItems(0, 5))
{
Console.WriteLine(translate.toString());
}
var translate2 = new VocabularyEntity
{
word = "word4",
LangueName = "English",
};
context.Vocabularys.Add(translate2);
context.SaveChanges();
uow.VocabularyRepository.Insert(translate2);
await uow.SaveChangesAsync();
translate1.WordsId = "word4";
context.Translates.Update(translate1);
context.SaveChanges();
Console.WriteLine("\ntest update (le mot doit etre 'updated') \n");
translates.Update(translate1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest update (le mot doit être 'updated') \n");
Console.WriteLine(translate1.toString());
context.Translates.Remove(translate1);
context.SaveChanges();
translates.Delete(translate1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest suppression (il n'y a normalement plus le mot 'word4'\n");
foreach (var translate in context.Translates.Take(5))
foreach (var translate in translates.GetItems(0, 5))
{
Console.WriteLine(translate.toString());
}
Console.WriteLine("\n\nTest Vocabulary : \n\n");
context.Database.EnsureCreated();
}
Console.WriteLine("\n\nTest Vocabulary : \n\n");
using (var uow = new UnitOfWork(options))
{
var vocabularies = uow.VocabularyRepository;
var vocabularys = context.Vocabularys.ToList();
Console.WriteLine("Vocabularys: " + vocabularys.Count);
Console.WriteLine("\ntest show 5 first Vocabularys : \n");
foreach (var vocabulary in context.Vocabularys.Take(5))
foreach (var vocabulary in vocabularies.GetItems(0, 5))
{
Console.WriteLine(vocabulary.toString());
}
var vocabulary1 = new VocabularyEntity
{
var vocabulary1 = new VocabularyEntity
{
word = "NewWord",
LangueName = "English"
};
context.Vocabularys.Add(vocabulary1);
context.SaveChanges();
vocabularies.Insert(vocabulary1);
await uow.SaveChangesAsync();
Console.WriteLine("\n ajout Vocabulary (normalement NewWord) \n");
foreach (var vocabulary in context.Vocabularys.Take(5))
foreach (var vocabulary in vocabularies.GetItems(0, 5))
{
Console.WriteLine(vocabulary.toString());
}
vocabulary1.LangueName = "French";
context.Vocabularys.Update(vocabulary1);
context.SaveChanges();
Console.WriteLine("\ntest update (la langue doit etre 'French') \n");
vocabularies.Update(vocabulary1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest update (la langue doit être 'French') \n");
Console.WriteLine(vocabulary1.toString());
context.Vocabularys.Remove(vocabulary1);
context.SaveChanges();
vocabularies.Delete(vocabulary1);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest suppression (il n'y a normalement plus le mot 'NewWord'\n");
foreach (var vocabulary in context.Vocabularys.Take(5))
foreach (var vocabulary in vocabularies.GetItems(0, 5))
{
Console.WriteLine(vocabulary.toString());
}
}
Console.WriteLine("\n\nTest GroupVocabularyList : \n\n");
using (var uow = new UnitOfWork(options))
{
var vocabularyLists = uow.VocabularyListRepository;
Console.WriteLine("\n\nTest GroupVocabularyList : \n\n");
context.Database.EnsureCreated();
var vocabularyLists = context.VocabularyLists.ToList();
Console.WriteLine("VocabularyLists: " + vocabularyLists.Count);
Console.WriteLine("\ntest show 5 first VocabularyLists : \n");
foreach (var vocabularyList in context.VocabularyLists.Take(5))
foreach (var vocabularyList in vocabularyLists.GetItems(0, 5))
{
Console.WriteLine(vocabularyList.toString());
}
var vocabularyList2 = new VocabularyListEntity
{
Id = 4,
Name = "name4",
Image = "image4",
UserId = 3
};
context.VocabularyLists.Add(vocabularyList2);
context.SaveChanges();
vocabularyLists.Insert(vocabularyList2);
await uow.SaveChangesAsync();
Console.WriteLine("\n ajout GroupVocabularyList (normalement name4) \n");
foreach (var vocabularyList in context.VocabularyLists.Take(5))
foreach (var vocabularyList in vocabularyLists.GetItems(0, 5))
{
Console.WriteLine(vocabularyList.toString());
}
vocabularyList2.Name = "updated";
context.VocabularyLists.Update(vocabularyList2);
context.SaveChanges();
Console.WriteLine("\ntest update (le nom doit etre 'updated') \n");
vocabularyLists.Update(vocabularyList2);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest update (le nom doit être 'updated') \n");
Console.WriteLine(vocabularyList2.toString());
Console.WriteLine("\n test affichage des owner (user) des listes normalement");
foreach (var vocabularyList in context.VocabularyLists.Take(5))
foreach (var vocabularyList in vocabularyLists.GetItems(0, 5))
{
Console.WriteLine(vocabularyList.User.toString());
if(vocabularyList.User != null)
Console.WriteLine(vocabularyList.User.toString());
}
context.VocabularyLists.Remove(vocabularyList2);
context.SaveChanges();
vocabularyLists.Delete(vocabularyList2);
await uow.SaveChangesAsync();
Console.WriteLine("\ntest suppression (il n'y a normalement plus la liste 'name4'\n");
foreach (var vocabularyList in context.VocabularyLists.Take(5))
foreach (var vocabularyList in vocabularyLists.GetItems(0, 5))
{
Console.WriteLine(vocabularyList.toString());
}
Console.WriteLine("\n\nTest Many to Many (si pas d'erreur alors test reussi) : \n\n");
context.Database.EnsureCreated();
var groupVoc = new GroupEntity { Id = 2, Num = 1, year = 1, sector = "sector1" };
VocabularyListEntity VocListGroup = new VocabularyListEntity { Id = 2, Name = "name1", Image = "image1", UserId = 1 };
context.AddRange(groupVoc, VocListGroup);
context.SaveChanges();
var transVoc = new TranslateEntity { Id = 2, WordsId = "1", VocabularyListVocId = 1 };
var VocTrans = new VocabularyEntity { word = "Test", LangueName = "French" };
context.AddRange(transVoc, VocTrans);
context.SaveChanges();
}
}

@ -2,6 +2,7 @@
# SAE 2A Anglais
Ce projet vise à faciliter l'apprentissage de l'anglais dans le cadre d'études supérieures grâce à un site internet et une application mobile.
## Exécuter localement
Clonez le projet
@ -18,6 +19,16 @@ Allez dans le répertoire
Suivez les différentes instructions suivant la partie que vous souhaitez lancer.
### EF et WebAPI
Bonjour cette partie a été réalisé par Patrick Brugière seul.
Le .sln se trouve dans le repertoir Project/EntityFramework
Il est normalement précisé dans le nom de des tests à quelles parties ils appartiennent
Pour utiliser un jeton JWT dans l'en-tête "Authorize", il suffit d'entrer simplement sa valeur, sans mettre ni guillemets ni le mot "Bearer" avant.
### PHP
Changez de branche

Loading…
Cancel
Save