| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using OzonDomains; |
| | | 3 | | using OzonDomains.Models; |
| | | 4 | | using OzonRepositories.Context; |
| | | 5 | | |
| | | 6 | | namespace OzonRepositories.Data |
| | | 7 | | { |
| | | 8 | | public class AppStatusRepository : MainRepository, IRepository<AppStatus> |
| | | 9 | | { |
| | 2 | 10 | | public AppStatusRepository(ApplicationDbContext orderContext) : base(orderContext) |
| | | 11 | | { |
| | 2 | 12 | | } |
| | | 13 | | |
| | | 14 | | public Task<int> Add(AppStatus value) |
| | | 15 | | { |
| | 0 | 16 | | _context.AppStatuses.AddAsync(value); |
| | 0 | 17 | | return _context.SaveChangesAsync(); |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | public Task<int> Delete(AppStatus value) |
| | | 21 | | { |
| | 0 | 22 | | _context.Remove(value); |
| | 0 | 23 | | return _context.SaveChangesAsync(); |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | public async Task<List<AppStatus>> Get() |
| | | 27 | | { |
| | 0 | 28 | | return await _context.AppStatuses |
| | 0 | 29 | | .Include(s => s.StatusColor) |
| | 0 | 30 | | .ToListAsync(); |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | public async Task<AppStatus?> GetAsync(int id) |
| | | 34 | | { |
| | 0 | 35 | | return await _context.AppStatuses |
| | 0 | 36 | | .Include(s => s.StatusColor) |
| | 0 | 37 | | .FirstOrDefaultAsync(a => a.Id == id); |
| | 0 | 38 | | } |
| | | 39 | | |
| | | 40 | | public async Task<AppStatus?> GetAsync(AppStatus value) |
| | | 41 | | { |
| | 0 | 42 | | await Task.CompletedTask; |
| | 0 | 43 | | return _context.AppStatuses.Include(s => s.StatusColor).SingleOrDefault(a => a.Name == value.Name); |
| | 0 | 44 | | } |
| | | 45 | | |
| | | 46 | | public async Task<int> Update(AppStatus value) |
| | | 47 | | { |
| | 0 | 48 | | await Task.CompletedTask; |
| | 0 | 49 | | _context.AppStatuses.Update(value); |
| | 0 | 50 | | return _context.SaveChanges(); |
| | 0 | 51 | | } |
| | | 52 | | public async Task UpdateStatusColor(int statusId, string colorCode) |
| | | 53 | | { |
| | 0 | 54 | | var status = await _context.AppStatuses.FindAsync(statusId); |
| | 0 | 55 | | if (status != null) |
| | | 56 | | { |
| | 0 | 57 | | var color = await _context.StatusColors.FirstOrDefaultAsync(c => c.ColorCode == colorCode); |
| | 0 | 58 | | if (color == null) |
| | | 59 | | { |
| | 0 | 60 | | color = new StatusColor { ColorCode = colorCode }; |
| | 0 | 61 | | await _context.StatusColors.AddAsync(color); |
| | 0 | 62 | | await _context.SaveChangesAsync(); |
| | | 63 | | } |
| | | 64 | | |
| | 0 | 65 | | status.StatusColorId = color.Id; |
| | 0 | 66 | | await _context.SaveChangesAsync(); |
| | 0 | 67 | | } |
| | 0 | 68 | | } |
| | | 69 | | |
| | | 70 | | public async Task ResetStatusColor(int statusId) |
| | | 71 | | { |
| | 0 | 72 | | var status = await _context.AppStatuses.FindAsync(statusId); |
| | 0 | 73 | | if (status != null) |
| | | 74 | | { |
| | 0 | 75 | | status.StatusColorId = null; |
| | 0 | 76 | | await _context.SaveChangesAsync(); |
| | | 77 | | } |
| | 0 | 78 | | } |
| | | 79 | | } |
| | | 80 | | } |