| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using OzonDomains.Models; |
| | | 3 | | using OzonRepositories.Context; |
| | | 4 | | |
| | | 5 | | namespace OzonRepositories.Data |
| | | 6 | | { |
| | | 7 | | public class OzonChatResponseTimeRepository : MainRepository, IRepository<OzonChatResponseTime> |
| | | 8 | | { |
| | 0 | 9 | | public OzonChatResponseTimeRepository(ApplicationDbContext orderContext) : base(orderContext) |
| | | 10 | | { |
| | 0 | 11 | | } |
| | | 12 | | |
| | | 13 | | public async Task<int> Add(OzonChatResponseTime value) |
| | | 14 | | { |
| | 0 | 15 | | await _context.OzonChatResponseTimes.AddAsync(value); |
| | 0 | 16 | | return await _context.SaveChangesAsync(); |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | public async Task<int> Delete(OzonChatResponseTime value) |
| | | 20 | | { |
| | 0 | 21 | | _context.OzonChatResponseTimes.Remove(value); |
| | 0 | 22 | | return await _context.SaveChangesAsync(); |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | public async Task<List<OzonChatResponseTime>> Get() |
| | | 26 | | { |
| | 0 | 27 | | return await _context.OzonChatResponseTimes |
| | 0 | 28 | | .Include(x => x.Client) |
| | 0 | 29 | | .OrderByDescending(x => x.RecordedAt) |
| | 0 | 30 | | .ToListAsync(); |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | public async Task<OzonChatResponseTime?> GetAsync(int id) |
| | | 34 | | { |
| | 0 | 35 | | return await _context.OzonChatResponseTimes |
| | 0 | 36 | | .Include(x => x.Client) |
| | 0 | 37 | | .FirstOrDefaultAsync(x => x.Id == id) ?? new OzonChatResponseTime(); |
| | 0 | 38 | | } |
| | | 39 | | |
| | | 40 | | public async Task<OzonChatResponseTime?> GetAsync(OzonChatResponseTime value) |
| | | 41 | | { |
| | 0 | 42 | | return await _context.OzonChatResponseTimes |
| | 0 | 43 | | .Include(x => x.Client) |
| | 0 | 44 | | .FirstOrDefaultAsync(x => x.Id == value.Id) ?? new OzonChatResponseTime(); |
| | 0 | 45 | | } |
| | | 46 | | |
| | | 47 | | public async Task<int> Update(OzonChatResponseTime value) |
| | | 48 | | { |
| | 0 | 49 | | value.CreatedAt = value.CreatedAt; // nothing special |
| | 0 | 50 | | _context.OzonChatResponseTimes.Update(value); |
| | 0 | 51 | | return await _context.SaveChangesAsync(); |
| | 0 | 52 | | } |
| | | 53 | | |
| | | 54 | | public async Task<List<OzonChatResponseTime>> GetByChatIdAsync(string chatId) |
| | | 55 | | { |
| | 0 | 56 | | return await _context.OzonChatResponseTimes |
| | 0 | 57 | | .Where(x => x.ChatId == chatId) |
| | 0 | 58 | | .OrderByDescending(x => x.RecordedAt) |
| | 0 | 59 | | .ToListAsync(); |
| | 0 | 60 | | } |
| | | 61 | | |
| | | 62 | | public async Task<List<OzonChatResponseTime>> GetByClientIdAsync(int clientId) |
| | | 63 | | { |
| | 0 | 64 | | return await _context.OzonChatResponseTimes |
| | 0 | 65 | | .Where(x => x.ClientId == clientId) |
| | 0 | 66 | | .OrderByDescending(x => x.RecordedAt) |
| | 0 | 67 | | .ToListAsync(); |
| | 0 | 68 | | } |
| | | 69 | | } |
| | | 70 | | } |