public BalanceDTO AddBalance(BalanceDTO obj) { obj.CreationDate = DateTime.Now; var LastBalance = unitofwork.Balance.GetAll().Where(x => x.StoreId == obj.StoreId).OrderBy(y => y.CreationDate).Last(); List <ItemBalanceDTO> itemList = new List <ItemBalanceDTO>(); foreach (var i in LastBalance.ItemBalances) { ItemBalanceDTO item = new ItemBalanceDTO(); int balance = this.CalculateItemBalanceForStore(i.ItemId, obj.StoreId, LastBalance.BalanceDate); item.ItemId = i.ItemId; item.Quantity = i.Quantity + balance; itemList.Add(item); } obj.itemList = itemList.ToArray(); var entity = Mapper.Map <BalanceDTO, Balance>(obj); unitofwork.Balance.Add(entity); try { unitofwork.SaveChanges(); return(Mapper.Map <Balance, BalanceDTO>(entity)); } catch { return(Mapper.Map <Balance, BalanceDTO>(entity)); } }
public IEnumerable <ItemBalanceDTO> GetItemsNeedToReorderedForStore(int StoreId) { var lastBalance = balanceService.GetLastBalance(StoreId); List <ItemBalanceDTO> itemList = new List <ItemBalanceDTO>(); foreach (var i in lastBalance.itemList) { ItemBalanceDTO item = new ItemBalanceDTO(); int balance = balanceService.CalculateItemBalanceForStore(i.ItemId, StoreId, lastBalance.BalanceDate); item.ItemId = i.ItemId; item.Item = i.Item; item.Quantity = i.Quantity + balance; if (item.Quantity <= this.GetItem(i.ItemId).ReorderLevel) { itemList.Add(item); } } return(itemList); }