56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
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 AddressRepository : IAddressRepository
|
|
{
|
|
public Address GetAddressById(int AddressId)
|
|
{
|
|
using var context = new StockContext();
|
|
var entity = (from adr in context.Addresses
|
|
where adr.Id == AddressId
|
|
select adr).FirstOrDefault();
|
|
return entity;
|
|
}
|
|
|
|
public Address SaveAddress(Address address)
|
|
{
|
|
using var context = new StockContext();
|
|
var entity = (from adr in context.Addresses
|
|
where adr.Id == address.Id
|
|
select adr).FirstOrDefault();
|
|
|
|
if (entity == null)
|
|
{
|
|
entity = new Address
|
|
{
|
|
Street = address.Street,
|
|
Street2 = address.Street2,
|
|
Zipcode = address.Zipcode,
|
|
Destination = address.Destination,
|
|
Nation = address.Nation
|
|
};
|
|
context.Addresses.Add(entity);
|
|
}
|
|
else
|
|
{
|
|
entity.Street = address.Street;
|
|
entity.Street2 = address.Street2;
|
|
entity.Zipcode = address.Zipcode;
|
|
entity.Destination = address.Destination;
|
|
entity.Nation = address.Nation;
|
|
}
|
|
|
|
context.SaveChanges();
|
|
return entity;
|
|
}
|
|
}
|
|
}
|