/
renix
/
TravelGuide
Обзор
Документация
Войти
/
renix
/
TravelGuide
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
back/Repositories/FeedbackRepository.cs
53 строки
1 KB
artem777764
Feedback Clean Architecture
02 апр 2025, 21:25
02 апр 2025, 21:25
fbf9ecd
Код
Авторство
О чём код?
using back.Interfaces; using back.Models; using back.Models.Entities; using Microsoft.EntityFrameworkCore; namespace back.Repositories; public class FeedbackRepository : IRepository<FeedbackEntity> { private readonly Context _dbContext; public FeedbackRepository(Context context) { _dbContext = context; } public async Task<int> AddAsync(FeedbackEntity entity) { await _dbContext.Feedbacks.AddAsync(entity); await _dbContext.SaveChangesAsync(); return entity.Id; } public async Task<bool> DeleteAsync(int id) { FeedbackEntity? feedback = await _dbContext.Feedbacks.FindAsync(id); if (feedback == null) return false; _dbContext.Feedbacks.Remove(feedback); await _dbContext.SaveChangesAsync(); return true; } public async Task<List<FeedbackEntity>> GetAllAsync() { return await _dbContext.Feedbacks.AsNoTracking().ToListAsync(); } public async Task<FeedbackEntity?> GetByIdAsync(int id) { return await _dbContext.Feedbacks.FindAsync(id); } public async Task<bool> UpdateAsync(FeedbackEntity entity) { FeedbackEntity? currentFeedback = await _dbContext.Feedbacks.FindAsync(entity.Id); if (currentFeedback == null) return false; _dbContext.Entry(currentFeedback).CurrentValues.SetValues(entity); await _dbContext.SaveChangesAsync(); return true; } }