Icons updated with ef
This commit is contained in:
parent
0b68261181
commit
2c886d22ad
@ -1,6 +1,7 @@
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newsbot.Collector.Domain.Entities;
|
||||
using Newsbot.Collector.Domain.Interfaces;
|
||||
using Newsbot.Collector.Domain.Models;
|
||||
using Npgsql;
|
||||
@ -23,37 +24,29 @@ public class IconsTable : IIconsRepository
|
||||
_connectionString = connstr;
|
||||
}
|
||||
|
||||
public void New(IconModel model)
|
||||
public void New(IconEntity model)
|
||||
{
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
model.Id = Guid.NewGuid();
|
||||
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var q = @"Insert Into icons (id, filename, site, sourceid) values (@Id,@FileName, @Site, @SourceId)";
|
||||
conn.Execute(q, model);
|
||||
context.Icons.Add(model);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public IconModel GetById(Guid id)
|
||||
public IconEntity GetById(Guid id)
|
||||
{
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var query = "Select * From icons where ID = @id Limit 1;";
|
||||
var res = conn.Query<IconModel>(query, new
|
||||
{
|
||||
id
|
||||
});
|
||||
if (!res.Any()) return new IconModel();
|
||||
return res.First();
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
var res = context.Icons.FirstOrDefault(f => f.Id.Equals(id));
|
||||
res ??= new IconEntity();
|
||||
return res;
|
||||
}
|
||||
|
||||
public IconModel GetBySourceId(Guid id)
|
||||
public IconEntity GetBySourceId(Guid id)
|
||||
{
|
||||
using var conn = OpenConnection(_connectionString);
|
||||
var query = "Select * From icons where sourceid = @id Limit 1;";
|
||||
var res = conn.Query<IconModel>(query, new
|
||||
{
|
||||
id
|
||||
});
|
||||
if (!res.Any()) return new IconModel();
|
||||
return res.First();
|
||||
using var context = new DatabaseContext(_connectionString);
|
||||
var res = context.Icons.FirstOrDefault(f => f.SourceId.Equals(id));
|
||||
res ??= new IconEntity();
|
||||
return res;
|
||||
}
|
||||
|
||||
private IDbConnection OpenConnection(string connectionString)
|
||||
|
@ -1,11 +1,11 @@
|
||||
using Newsbot.Collector.Domain.Models;
|
||||
using Newsbot.Collector.Domain.Entities;
|
||||
|
||||
namespace Newsbot.Collector.Domain.Interfaces;
|
||||
|
||||
public interface IIconsRepository
|
||||
{
|
||||
public void New(IconModel model);
|
||||
public void New(IconEntity model);
|
||||
|
||||
public IconModel GetById(Guid id);
|
||||
public IconModel GetBySourceId(Guid id);
|
||||
public IconEntity GetById(Guid id);
|
||||
public IconEntity GetBySourceId(Guid id);
|
||||
}
|
Loading…
Reference in New Issue
Block a user