72 lines
2.3 KiB
C#
72 lines
2.3 KiB
C#
using DataDomain;
|
|
using DatamodelLibrary;
|
|
using StockDAL.Interface;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace StockDAL
|
|
{
|
|
public class StockPersonConnect : IStockPersonConnect
|
|
{
|
|
public IEnumerable<PersonStock> GetAllConnectionsByPersId(int personId)
|
|
{
|
|
using var context = new StockContext();
|
|
var connections = (from spc in context.PersonStocks
|
|
where spc.PersonId == personId
|
|
select spc).ToList();
|
|
return connections;
|
|
}
|
|
|
|
public IEnumerable<PersonStock> GetAllConnectedStocks()
|
|
{
|
|
using var context = new StockContext();
|
|
var entities = (from spc in context.PersonStocks
|
|
where spc.PersonId != 0
|
|
select spc).ToList();
|
|
return entities;
|
|
}
|
|
|
|
public PersonStock SavePersonStockConnection(PersonStock personStock)
|
|
{
|
|
using var context = new StockContext();
|
|
var entity = (from ps in context.PersonStocks
|
|
where ps.Id == personStock.Id
|
|
select ps).FirstOrDefault();
|
|
if (entity == null)
|
|
{
|
|
entity = new PersonStock
|
|
{
|
|
PersonId = personStock.PersonId,
|
|
StockId = personStock.StockId,
|
|
Comment = personStock.Comment
|
|
};
|
|
context.PersonStocks.Add(entity);
|
|
}
|
|
else
|
|
{
|
|
entity.PersonId = personStock.PersonId;
|
|
entity.StockId = personStock.StockId;
|
|
entity.Comment = personStock.Comment;
|
|
}
|
|
context.SaveChanges();
|
|
|
|
return entity;
|
|
}
|
|
|
|
public void RemoveConnectedShare(PersonStock personStock)
|
|
{
|
|
using var context = new StockContext();
|
|
var entity = (from ps in context.PersonStocks
|
|
where ps.StockId == personStock.StockId
|
|
select ps).FirstOrDefault();
|
|
if (entity != null)
|
|
{
|
|
context.PersonStocks.Remove(entity);
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
} |