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 PersonRepository : IPersonRepository { public Person GetPersonById(int personId) { using var context = new StockContext(); var entity = (from prs in context.Persons where prs.Id == personId select prs).FirstOrDefault(); return entity; } public IEnumerable GetAllOwners() { using var context = new StockContext(); var output = context.Persons; return output.ToList(); } public Person SavePerson(Person person) { using var context = new StockContext(); var entity = (from prs in context.Persons where prs.Id == person.Id select prs).FirstOrDefault(); if (entity == null) { entity = new Person { AccountNo = person.AccountNo, Born = person.Born, ClearingNo = person.ClearingNo, Comments = person.Comments, FirstName = person.FirstName, HomeAddress = person.HomeAddress, InvoiceAddress = person.InvoiceAddress, LastName = person.LastName, NickName = person.NickName }; context.Persons.Add(entity); } else { entity.AccountNo = person.AccountNo; entity.Born = person.Born; entity.ClearingNo = person.ClearingNo; entity.Comments = person.Comments; entity.FirstName = person.FirstName; entity.HomeAddress = person.HomeAddress; entity.InvoiceAddress = person.InvoiceAddress; entity.LastName = person.LastName; entity.NickName = person.NickName; } context.SaveChanges(); return entity; } } }