|
|
@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
using Entities.SQLudeoDB;
|
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
using Model.DTO;
|
|
|
|
|
|
|
|
using Services;
|
|
|
|
|
|
|
|
using DbContextLib;
|
|
|
|
|
|
|
|
using Model.Business;
|
|
|
|
|
|
|
|
using Model;
|
|
|
|
|
|
|
|
using Model.Mappers;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ModelToEntity
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public class DbDataManager : IDataServiceEF
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public async Task<User> GetUserById(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using(var context = new UserDbContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var userEntity = context.Users.FirstOrDefault(u => u.Id == id);
|
|
|
|
|
|
|
|
if(userEntity == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(id));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return await Task.FromResult(userEntity.FromEntityToModel());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<User> GetUserByUsername(string username)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var context = new UserDbContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var userEntity = context.Users.FirstOrDefault(u => u.Username == username);
|
|
|
|
|
|
|
|
if (userEntity == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(username));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(userEntity.FromEntityToModel());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<User>> GetUsers(int page, int number)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var context = new UserDbContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return await Task.FromResult(context.Users.Skip((page - 1) * number).Take(number).ToList().Select(u => u.FromEntityToModel()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Task<bool> DeleteUser(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var context = new UserDbContext()) {
|
|
|
|
|
|
|
|
var userEntity = context.Users.FirstOrDefault(u => u.Id == id);
|
|
|
|
|
|
|
|
if (userEntity == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Task.FromResult(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
context.Users.Remove(userEntity);
|
|
|
|
|
|
|
|
context.SaveChangesAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Task.FromResult(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<User> UpdateUser(int id, UserDTO user)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var context = new UserDbContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var updatingUser = context.Users.FirstOrDefault(u => u.Id == id);
|
|
|
|
|
|
|
|
if (updatingUser == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ArgumentException("Impossible de trouver l'utilisateur", nameof(id));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
updatingUser.Username = user.Username;
|
|
|
|
|
|
|
|
updatingUser.Password = user.Password;
|
|
|
|
|
|
|
|
updatingUser.Email = user.Email;
|
|
|
|
|
|
|
|
updatingUser.IsAdmin = user.IsAdmin;
|
|
|
|
|
|
|
|
// Permet d'indiquer en Db que l'entité a été modifiée.
|
|
|
|
|
|
|
|
context.Entry(updatingUser).State = EntityState.Modified;
|
|
|
|
|
|
|
|
context.SaveChangesAsync();
|
|
|
|
|
|
|
|
return await Task.FromResult(updatingUser.FromEntityToModel());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<User> CreateUser(string username, string password, string email, bool isAdmin)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var context = new UserDbContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var newUserEntity = new UserDTO
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Username = username,
|
|
|
|
|
|
|
|
Password = password,
|
|
|
|
|
|
|
|
Email = email,
|
|
|
|
|
|
|
|
IsAdmin = isAdmin
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
context.Users.Add(newUserEntity.FromDTOToModel().FromModelToEntity());
|
|
|
|
|
|
|
|
context.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(newUserEntity.FromDTOToModel());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<InquiryDTO> GetInquiries(int page, int number)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InquiryDTO GetInquiryById(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InquiryDTO GetInquiryByTitle(string title)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public UserDTO CreateInquiry(string title, string description, bool isUser, InquiryTableEntity database, SolutionEntity inquiryTable)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool DeleteInquiry(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InquiryDTO UpdateInquiry(int id, InquiryDTO inquiry)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<InquiryDTO> GetLessons(int page, int number)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InquiryDTO GetLessonById(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InquiryDTO GetLessonByTitle(string title)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool DeleteLesson(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InquiryDTO UpdateLesson(int id, LessonDTO lesson)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UserDTO CreateLesson(string title, string lastPublisher, DateOnly lastEdit)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|