Add project files.
This commit is contained in:
75
StockDAL/PersonRepository.cs
Normal file
75
StockDAL/PersonRepository.cs
Normal file
@ -0,0 +1,75 @@
|
||||
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<Person> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user