| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using OzonDomains.Models; |
| | | 3 | | using OzonRepositories.Context; |
| | | 4 | | |
| | | 5 | | namespace OzonRepositories.Data |
| | | 6 | | { |
| | | 7 | | public class ManufacturerRepository : MainRepository, IRepository<Manufacturer> |
| | | 8 | | { |
| | 0 | 9 | | public ManufacturerRepository(ApplicationDbContext orderContext) : base(orderContext) |
| | | 10 | | { |
| | 0 | 11 | | } |
| | | 12 | | |
| | | 13 | | public async Task<int> Add(Manufacturer value) |
| | | 14 | | { |
| | 0 | 15 | | _context.Manufacturers.Add(value); |
| | 0 | 16 | | return await _context.SaveChangesAsync(); |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | public async Task<int> Delete(Manufacturer value) |
| | | 20 | | { |
| | 0 | 21 | | _context.Manufacturers.Remove(value); |
| | 0 | 22 | | return await (_context.SaveChangesAsync()); |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | public async Task<List<Manufacturer>> Get() |
| | | 26 | | { |
| | 0 | 27 | | return await _context.Manufacturers.ToListAsync(); |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | public async Task<Manufacturer?> GetAsync(int id) |
| | | 31 | | { |
| | 0 | 32 | | await Task.CompletedTask; |
| | 0 | 33 | | return _context.Manufacturers.FirstOrDefault(x => x.Id == id); |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | public async Task<Manufacturer?> GetAsync(Manufacturer value) |
| | | 37 | | { |
| | 0 | 38 | | await Task.CompletedTask; |
| | 0 | 39 | | return _context.Manufacturers.FirstOrDefault(x => |
| | 0 | 40 | | x.Code == value.Code && x.EtProduserId == value.EtProduserId); |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | public async Task<int> Update(Manufacturer value) |
| | | 44 | | { |
| | 0 | 45 | | Manufacturer? manufacturer = await _context.Manufacturers.FindAsync(value.Id); |
| | 0 | 46 | | if (manufacturer != null) |
| | | 47 | | { |
| | 0 | 48 | | manufacturer.Name = value.Name; |
| | 0 | 49 | | manufacturer.Code = value.Code; |
| | | 50 | | } |
| | | 51 | | |
| | 0 | 52 | | return await _context.SaveChangesAsync(); |
| | 0 | 53 | | } |
| | | 54 | | } |
| | | 55 | | } |