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 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; } } }