påbörjat hantering olika portföljer

This commit is contained in:
2021-03-13 00:08:11 +01:00
parent b4a9237290
commit b25c6fd538
18 changed files with 454 additions and 71 deletions

View File

@ -0,0 +1,50 @@
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 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;
}
}
}