From a219699271f1230ddf3abd151986cd50e4549262 Mon Sep 17 00:00:00 2001 From: "ismail.taha_janan" Date: Tue, 10 Jan 2023 15:46:00 +0100 Subject: [PATCH] :beers: i was trying to implement AutoMapper but i was to drunk SORRYgit status --- cat_cafe/Controllers/CustomersController.cs | 5 ++-- cat_cafe/Dto/CatDto.cs | 11 ++++++++ cat_cafe/Dto/CustomerDto.cs | 11 ++++++++ cat_cafe/Entities/Cat.cs | 1 - cat_cafe/Mappers/CustomerMapper.cs | 17 +++++++++++ cat_cafe/Services/CustomeService.cs | 31 +++++++++++++++++++++ cat_cafe/cat_cafe.csproj | 14 ++++++++++ 7 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 cat_cafe/Dto/CatDto.cs create mode 100644 cat_cafe/Dto/CustomerDto.cs create mode 100644 cat_cafe/Mappers/CustomerMapper.cs create mode 100644 cat_cafe/Services/CustomeService.cs diff --git a/cat_cafe/Controllers/CustomersController.cs b/cat_cafe/Controllers/CustomersController.cs index 41ae9e4..881bfa2 100644 --- a/cat_cafe/Controllers/CustomersController.cs +++ b/cat_cafe/Controllers/CustomersController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using cat_cafe.Entities; using cat_cafe.Repositories; +using cat_cafe.Dto; namespace cat_cafe.Controllers { @@ -23,7 +24,7 @@ namespace cat_cafe.Controllers // GET: api/Customers [HttpGet] - public async Task>> GetCustomers() + public async Task>> GetCustomers() { if (_context.Customers == null) { @@ -34,7 +35,7 @@ namespace cat_cafe.Controllers // GET: api/Customers/5 [HttpGet("{id}")] - public async Task> GetCustomer(long id) + public async Task> GetCustomer(long id) { if (_context.Customers == null) { diff --git a/cat_cafe/Dto/CatDto.cs b/cat_cafe/Dto/CatDto.cs new file mode 100644 index 0000000..9fd3c53 --- /dev/null +++ b/cat_cafe/Dto/CatDto.cs @@ -0,0 +1,11 @@ +using System; +namespace cat_cafe.Dto +{ + public class CatDto + { + public long Id { get; set; } + public string? Name { get; set; } + public int Age { get; set; } = 0; + } +} + diff --git a/cat_cafe/Dto/CustomerDto.cs b/cat_cafe/Dto/CustomerDto.cs new file mode 100644 index 0000000..6a38d6f --- /dev/null +++ b/cat_cafe/Dto/CustomerDto.cs @@ -0,0 +1,11 @@ +using System; +namespace cat_cafe.Dto +{ + public class CustomerDto + { + public long Id { get; set; } + public string? FullName { get; set; } + public int Age { get; set; } = 0; + } +} + diff --git a/cat_cafe/Entities/Cat.cs b/cat_cafe/Entities/Cat.cs index 0068971..60ff99c 100644 --- a/cat_cafe/Entities/Cat.cs +++ b/cat_cafe/Entities/Cat.cs @@ -6,6 +6,5 @@ public string? Name { get; set; } public int Age { get; set; } = 0; - } } diff --git a/cat_cafe/Mappers/CustomerMapper.cs b/cat_cafe/Mappers/CustomerMapper.cs new file mode 100644 index 0000000..f203515 --- /dev/null +++ b/cat_cafe/Mappers/CustomerMapper.cs @@ -0,0 +1,17 @@ +using System; +using AutoMapper; +using cat_cafe.Entities; +using cat_cafe.Dto; +namespace cat_cafe.Mappers +{ + public class CustomerMapper:Profile + { + + public CustomerMapper() + { + CreateMap(); + CreateMap(); + } + } +} + diff --git a/cat_cafe/Services/CustomeService.cs b/cat_cafe/Services/CustomeService.cs new file mode 100644 index 0000000..ff17ea8 --- /dev/null +++ b/cat_cafe/Services/CustomeService.cs @@ -0,0 +1,31 @@ +using System; +using cat_cafe.Entities; +using cat_cafe.Repositories; +using cat_cafe.Dto; +using cat_cafe.Mappers; + +namespace cat_cafe.Services +{ + public class CustomeService + { + public CustomeService() + { + } + + private readonly CustomerContext _context; + + + public Task>? getAll() + { + if (_context.Customers == null) + { + return null; + } + /** + * here i stoped + */ + return Mappers.CustomerMapper(await _context.Customers.ToListAsync()); + } + } +} + diff --git a/cat_cafe/cat_cafe.csproj b/cat_cafe/cat_cafe.csproj index d01b369..08a7776 100644 --- a/cat_cafe/cat_cafe.csproj +++ b/cat_cafe/cat_cafe.csproj @@ -16,6 +16,20 @@ + + + + + + + + + + + + + +