61 lines
1.7 KiB
C#
61 lines
1.7 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 StockRepository : IStockRepository
|
|
{
|
|
public void SaveStockMember(StockMember stockMember)
|
|
{
|
|
using (var context = new StockContext())
|
|
{
|
|
var sm = context.Stocks.Add(stockMember);
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public void UpdateActualPrice(int id, decimal price)
|
|
{
|
|
using var context = new StockContext();
|
|
var entity = (from stk in context.Stocks
|
|
where stk.Id == id
|
|
select stk).FirstOrDefault();
|
|
|
|
entity.ActValue = price;
|
|
entity.ActDate = DateTime.Today;
|
|
|
|
context.SaveChanges();
|
|
}
|
|
|
|
public IEnumerable<StockMember> GetAllStocks()
|
|
{
|
|
using var context = new StockContext();
|
|
var output = context.Stocks;
|
|
return output.ToList();
|
|
}
|
|
|
|
public IEnumerable<StockMember> GetAllRemainingStocks()
|
|
{
|
|
using var context = new StockContext();
|
|
var output = (from stk in context.Stocks
|
|
where stk.SoldDate == null || stk.ActValue > 0
|
|
select stk).ToList();
|
|
return output;
|
|
}
|
|
|
|
public void InsertMany(List<StockMember> stockMembers)
|
|
{
|
|
using var context = new StockContext();
|
|
context.Stocks.AddRange(stockMembers);
|
|
context.SaveChanges();
|
|
}
|
|
|
|
}
|
|
}
|