Program fixes , registering new stocks, without dbchanges
This commit is contained in:
@ -133,6 +133,8 @@ namespace StockDAL
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IEnumerable<StockGrpPers> GetStocksGroupedPerPerson(int persId)
|
||||
{
|
||||
using var context = new StockContext();
|
||||
@ -140,12 +142,52 @@ namespace StockDAL
|
||||
join stk in context.Stocks on prs.StockId equals stk.Id
|
||||
join grp in context.StockGroups on stk.StockId equals grp.StockName
|
||||
where prs.PersonId == persId
|
||||
orderby grp.GroupName, grp.StockName
|
||||
orderby grp.StockGroup, grp.StockName
|
||||
select new StockGrpPers
|
||||
{
|
||||
PersId = persId,
|
||||
StockId = stk.StockId,
|
||||
StockGroup = grp.GroupName
|
||||
StockGroup = grp.StockGroup
|
||||
}).ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
public StockGroupModel SaveStockGroup(StockGroupModel stockGroup)
|
||||
{
|
||||
using var context = new StockContext();
|
||||
var entity = (from sg in context.StockGroups
|
||||
where sg.Id == stockGroup.Id
|
||||
select sg).FirstOrDefault();
|
||||
if (entity == null)
|
||||
{
|
||||
entity = new StockGroupModel
|
||||
{
|
||||
StockGroup = stockGroup.StockGroup,
|
||||
StockName = stockGroup.StockName
|
||||
};
|
||||
context.StockGroups.Add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.StockGroup = stockGroup.StockGroup;
|
||||
entity.StockName = stockGroup.StockName;
|
||||
}
|
||||
context.SaveChanges();
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<StockGrpPers> GetGroupedStock(string stock)
|
||||
{
|
||||
using var context = new StockContext();
|
||||
var result = (from grp in context.StockGroups
|
||||
where grp.StockName == stock
|
||||
select new StockGrpPers
|
||||
{
|
||||
PersId = 0,
|
||||
StockId = grp.StockName,
|
||||
StockGroup = grp.StockGroup
|
||||
}).ToList();
|
||||
return result;
|
||||
}
|
||||
@ -184,5 +226,17 @@ namespace StockDAL
|
||||
throw new InvalidOperationException(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public List<string> GetStockNames()
|
||||
{
|
||||
using var context = new StockContext();
|
||||
var output = (from stg in context.StockGroups
|
||||
orderby stg.StockName
|
||||
select stg.StockName).ToList();
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user