påbörjat hantering olika portföljer
This commit is contained in:
50
StockDAL/StockPersonConnect.cs
Normal file
50
StockDAL/StockPersonConnect.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user