public void Delete(string Id) { using (StockUnitOfWork db = new StockUnitOfWork()) { db.FavoriteStock.Delete(Id); db.SaveChanges(); } }
public void Add(StockInfoItem item) { var stockEntity = new StockEntity { Id = item.Id, Name = item.Name, MarketType = item.MarketType, Category = item.Category }; using (StockUnitOfWork db = new StockUnitOfWork()) { db.Stock.Add(stockEntity); db.SaveChanges(); } }
public void Add(StockInfoItem item) { using (StockUnitOfWork db = new StockUnitOfWork()) { // check if the stock is exist in favorite table if (db.FavoriteStock.GetById(item.Id) != null) { throw new FavoriteStockExistException(item.Id, item.Name); } StockEntity stockEntity = db.Stock.GetById(item.Id); var favoriteStockEntity = new FavoriteStockEntity { Id = item.Id, ParentStock = stockEntity, // TODO : it must rewrite the category source from category table //CustomCategory = item.Category, Order = item.Order }; db.FavoriteStock.Add(favoriteStockEntity); db.SaveChanges(); } }
public void Add(List <StockInfoItem> stockInfoList) { using (StockUnitOfWork db = new StockUnitOfWork()) { var existStockInfoList = db.Stock.GetAll(); List <StockEntity> stockEntityList = new List <StockEntity>(); foreach (var item in stockInfoList) { // 不存在才更新 if (existStockInfoList.FirstOrDefault(x => x.Id == item.Id) == null) { stockEntityList.Add(new StockEntity { Id = item.Id, Name = item.Name, MarketType = item.MarketType, Category = item.Category }); } } db.Stock.Add(stockEntityList); db.SaveChanges(); } }