Add project files.

This commit is contained in:
2021-05-09 22:10:25 +02:00
parent f20ba23e7b
commit f8c472a4cd
70 changed files with 6207 additions and 0 deletions

View File

@ -0,0 +1,72 @@
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();
}
}
}
}