From 83c9b7fe6e46fd2c3723ee9bd04f4495094939e4 Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Sat, 7 Sep 2024 12:18:30 +0300 Subject: [PATCH] verified field in car, fixed missing public declarations there as well --- Database/Models/Car.cs | 9 ++++--- Repositories/PolisRepository.cs | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/Database/Models/Car.cs b/Database/Models/Car.cs index ba77df7..66a5cca 100644 --- a/Database/Models/Car.cs +++ b/Database/Models/Car.cs @@ -9,11 +9,12 @@ public class Car [Required] public string Number { get; set; } = null!; [Required] - Polis Polis { get; set; } = null!; + public Polis Polis { get; set; } = null!; [Required] - long PolisId { get; set; } + public long PolisId { get; set; } [Required] - User Resp { get; set; } = null!; + public User Resp { get; set; } = null!; [Required] - long RespId { get; set; } + public long RespId { get; set; } + public bool Verified { get; set; } } \ No newline at end of file diff --git a/Repositories/PolisRepository.cs b/Repositories/PolisRepository.cs index e69de29..00e8a4f 100644 --- a/Repositories/PolisRepository.cs +++ b/Repositories/PolisRepository.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore; +using Renis.Database; +using Renis.Database.Models; + +namespace Renis.Repositories; + +public class PolisRepository(ApplicationContext db) : IPolisRepository +{ + private readonly ApplicationContext _db = db; + + public async Task AddPolis(Polis polis) + { + _db.Polises.Add(polis); + return await Save(); + } + + public async Task DeletePolis(Polis polis) + { + _db.Polises.Remove(polis); + return await Save(); + } + + public async Task GetPolisById(long id) + { + return await _db.Polises.FirstOrDefaultAsync(x => x.Id == id); + } + + public async Task GetPolisByNumber(string number) + { + return await _db.Polises.FirstOrDefaultAsync(x => x.Number == number); + } + + public IQueryable GetPolises() + { + return _db.Polises.AsQueryable(); + } + + public async Task Save() + { + return await _db.SaveChangesAsync() > 0; + } + + public async Task UpdatePolis(Polis polis) + { + _db.Polises.Update(polis); + return await Save(); + } +}