51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using AyCode.Core.Server.Loggers;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using TIAM.Database.DbContexts.Auctions;
|
|
using TIAM.Entities.Auctions;
|
|
|
|
namespace TIAM.Database.DataLayers.Auctions
|
|
{
|
|
public class AuctionDal : DalBase<AuctionDbContext>
|
|
{
|
|
|
|
public AuctionDal() : base()
|
|
{
|
|
}
|
|
|
|
public Task<List<AuctionBid>> GetBids()
|
|
{
|
|
return Context.AuctionBids.ToListAsync();
|
|
}
|
|
|
|
public Task<List<AuctionBid>> GetBidsByEmail(string email)
|
|
{
|
|
GlobalLogger.Info($"Getting bid from db {email}");
|
|
var emailLower = email.ToLower();
|
|
return Context.AuctionBids.Where(x => x.Email.ToLower() == emailLower).ToListAsync();
|
|
}
|
|
|
|
public AuctionBid? GetBidById(Guid id)
|
|
{
|
|
GlobalLogger.Info($"Getting bid from db {id}");
|
|
|
|
return Context.AuctionBids.FirstOrDefault(x => x.Id == id);
|
|
}
|
|
|
|
public Task<bool> CreateBidAsync(AuctionBid auctionBid)
|
|
{
|
|
auctionBid.Created = DateTime.UtcNow;
|
|
auctionBid.Modified = DateTime.UtcNow;
|
|
Context.AuctionBids.Add(auctionBid);
|
|
GlobalLogger.Info($"Saving user to db {auctionBid.Id}, {auctionBid.Email}, {auctionBid.PhoneNumber}");
|
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
|
}
|
|
|
|
public Task<bool> UpdateBidAsync(AuctionBid auctionBid)
|
|
{
|
|
auctionBid.Modified = DateTime.UtcNow;
|
|
Context.AuctionBids.Update(auctionBid);
|
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
|
}
|
|
}
|
|
}
|