From bbc9fd9a236008eae5090fd164a9b50b29b7a691 Mon Sep 17 00:00:00 2001 From: "victor.gaborit" Date: Fri, 15 Mar 2024 17:17:34 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20d=C3=A9but=20utilisation=20methodes=20d?= =?UTF-8?q?'extension=20pour=20lessons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/LessonDataService.cs | 37 +++++++++++++++++++ API_SQLuedo/Shared/DataService.cs | 2 +- API_SQLuedo/Shared/ILessonService.cs | 2 +- API_SQLuedo/Shared/IdataService.cs | 2 +- API_SQLuedo/Shared/LessonDataService.cs | 20 ++++++++++ API_SQLuedo/TestConsoleAPI/Program.cs | 2 +- 6 files changed, 61 insertions(+), 4 deletions(-) diff --git a/API_SQLuedo/DbDataManager/Service/LessonDataService.cs b/API_SQLuedo/DbDataManager/Service/LessonDataService.cs index 65ed957..5ecad57 100644 --- a/API_SQLuedo/DbDataManager/Service/LessonDataService.cs +++ b/API_SQLuedo/DbDataManager/Service/LessonDataService.cs @@ -3,6 +3,7 @@ using Entities; using Microsoft.EntityFrameworkCore; using Model.OrderCriteria; using Shared; +using Shared.ModelToEntities; namespace DbDataManager.Service; @@ -86,4 +87,40 @@ public class LessonDataService : ILessonService DbContext.SaveChangesAsync(); return newLessonEntity; } + + public async Task AddItem(LessonEntity? item) + { + using (var context = DbContext = new UserDbContext()) + { + var lesson = await context.CreateItemAsync(item); + return item; + } + } + + public async Task DeleteItem(int id) + { + using (var context = DbContext = new UserDbContext()) + { + var succes = await context.DeleteItemAsync(id); + return succes; + } + } + + public async Task UpdateItem(int? id, TDto? newItem) where TDto : class + { + using (var context = DbContext = new UserDbContext()) + { + var lesson = await context.UpdateItemAsync(id, newItem); + return lesson; + } + } + + public async Task> GetItems(int page, int count, object? orderCriteria = null, string? filter = null, object? valueFilter = null) + { + using (var context = DbContext = new UserDbContext()) + { + var lessons = await context.GetItemsWithFilter(page, count, orderCriteria, filter, valueFilter); + return lessons; + } + } } \ No newline at end of file diff --git a/API_SQLuedo/Shared/DataService.cs b/API_SQLuedo/Shared/DataService.cs index 09443e4..67ebbe2 100644 --- a/API_SQLuedo/Shared/DataService.cs +++ b/API_SQLuedo/Shared/DataService.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Shared { - public class DataService : IdataService where TUser : class where TInquiry : class + public class DataService : IdataService where TUser : class where TInquiry : class where Tlesson : class { private UserDbContext _dbContext; public DataService(UserDbContext userDbContext, IUserService userService, ILessonService lessonService, IInquiryService inquiryService, IParagraphService paragrapheService, ISuccessService sucessService) diff --git a/API_SQLuedo/Shared/ILessonService.cs b/API_SQLuedo/Shared/ILessonService.cs index b0a1666..45f8dd9 100644 --- a/API_SQLuedo/Shared/ILessonService.cs +++ b/API_SQLuedo/Shared/ILessonService.cs @@ -2,7 +2,7 @@ namespace Shared; -public interface ILessonService +public interface ILessonService : IGenericDataService where TLesson : class { public IEnumerable GetLessons(int page, int number, LessonOrderCriteria orderCriteria); public TLesson GetLessonById(int id); diff --git a/API_SQLuedo/Shared/IdataService.cs b/API_SQLuedo/Shared/IdataService.cs index b0d90c1..5420b1b 100644 --- a/API_SQLuedo/Shared/IdataService.cs +++ b/API_SQLuedo/Shared/IdataService.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Shared { - public interface IdataService where TUser : class where TInquiry : class + public interface IdataService where TUser : class where TInquiry : class where Tlesson : class { IUserService userService { get; } IInquiryService inquiryService { get; } diff --git a/API_SQLuedo/Shared/LessonDataService.cs b/API_SQLuedo/Shared/LessonDataService.cs index e37b67e..b42edcd 100644 --- a/API_SQLuedo/Shared/LessonDataService.cs +++ b/API_SQLuedo/Shared/LessonDataService.cs @@ -100,4 +100,24 @@ public class LessonDataService : ILessonDataService DbContext.SaveChangesAsync(); return newLessonEntity; } + + public Task AddItem(LessonDTO? item) + { + throw new NotImplementedException(); + } + + public Task DeleteItem(int id) + { + throw new NotImplementedException(); + } + + public Task UpdateItem(int? id, TDto? newItem) where TDto : class + { + throw new NotImplementedException(); + } + + public Task> GetItems(int page, int count, object? orderCriteria = null, string? filter = null, object? valueFilter = null) + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/API_SQLuedo/TestConsoleAPI/Program.cs b/API_SQLuedo/TestConsoleAPI/Program.cs index a1bde9a..e992a21 100644 --- a/API_SQLuedo/TestConsoleAPI/Program.cs +++ b/API_SQLuedo/TestConsoleAPI/Program.cs @@ -28,7 +28,7 @@ using (var context = new UserDbContext(options)) var userController = new UsersController(userLogger, new DataService(context, new Shared.UserDataService(context), new LessonDataService(context), new InquiryDataService(context), new ParagraphDataService(context), new SuccessDataService(context))); var inquiryController = new InquiriesController(new DataService(context, new Shared.UserDataService(context), new LessonDataService(context), new InquiryDataService(context), new ParagraphDataService(context), new SuccessDataService(context)), inquiryLogger); var paragraphController = new ParagraphsController(new ParagraphDataService(context), paragraphLogger); - var lessonController = new LessonsController(new LessonDataService(context), lessonLogger); + var lessonController = new LessonsController(new DataService(context, new Shared.UserDataService(context), new LessonDataService(context), new InquiryDataService(context), new ParagraphDataService(context), new SuccessDataService(context)), lessonLogger); var successController = new SuccessesController(new SuccessDataService(context), successLogger); async void PrintUsers()