/
Iceneo
/
WellTracker
Обзор
Документация
Войти
/
Iceneo
/
WellTracker
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
API/DAL/Statistics/Weight/WeightRecordsRepository.cs
45 строк
1 KB
Anton Yaskov
Добавил статистику по весу
16 ноя 2025, 20:30
16 ноя 2025, 20:30
9cde306
Код
Авторство
О чём код?
using Domain.Statistics.Weight; using Microsoft.EntityFrameworkCore; namespace DAL.Statistics.Weight; public class WeightRecordsRepository( DataContext dataContext ) : IWeightRecordsRepository { private DbSet<WeightRecordEntity> WeightRecords => dataContext.WeightRecords; public async Task AddOrUpdate(Guid userId, float weight, DateOnly date) { var existed = await WeightRecords.FirstOrDefaultAsync(e => e.UserId == userId && e.Date == date); if (existed != null) { existed.Weight = weight; } else { var toAdd = new WeightRecordEntity() { UserId = userId, Date = date, Weight = weight }; await WeightRecords.AddAsync(toAdd); } await dataContext.SaveChangesAsync(); } public async Task<WeightRecord[]> GetByPeriodIncluded(Guid userId, DateOnly from, DateOnly to) { var records = WeightRecords .AsNoTracking() .Where(e => e.UserId == userId) .Where(e => e.Date >= from && e.Date <= to) .OrderBy(e => e.Date); return records .Select(WeightRecordsMapper.ToDomain) .ToArray(); } }