private SourcingInventory Map(tblSourcingInventory inventory)
 {
     return new SourcingInventory(inventory.id)
                {
                    Balance = inventory.Balance.Value,
                    UnavailableBalance = inventory.UnavailableBalance,
                    Value = 0,
                    Commodity = _commodityRepository.GetById(inventory.CommodityId),
                    Warehouse = _costCentreRepository.GetById(inventory.WareHouseId) as Warehouse,
                    Grade = _commodityRepository.GetGradeByGradeId(inventory.GradeId),
                   
                };
 }
 public void AdjustInventoryBalance(Guid costCentreId,Guid commodityid, Guid gradeId, decimal qty)
 {
     DateTime date = DateTime.Now;
     var inventory =
         _ctx.tblSourcingInventory.FirstOrDefault(s => s.CommodityId == commodityid && s.GradeId == gradeId && s.WareHouseId== costCentreId);
     if (inventory == null)
     {
         inventory = new tblSourcingInventory();
         inventory.id = Guid.NewGuid();
         inventory.GradeId = gradeId;
         inventory.CommodityId = commodityid;
         inventory.WareHouseId = costCentreId;
         inventory.IM_DateCreated = date;
         inventory.IM_Status = 1;
         inventory.Balance = 0;
         inventory.UnavailableBalance = 0;
         _ctx.tblSourcingInventory.AddObject(inventory);
        
     }
     inventory.Balance += qty;
     inventory.IM_DateLastUpdated = date;
     _ctx.SaveChanges();
 }
 /// <summary>
 /// Create a new tblSourcingInventory object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="wareHouseId">Initial value of the WareHouseId property.</param>
 /// <param name="commodityId">Initial value of the CommodityId property.</param>
 /// <param name="gradeId">Initial value of the GradeId property.</param>
 /// <param name="unavailableBalance">Initial value of the UnavailableBalance property.</param>
 /// <param name="iM_DateCreated">Initial value of the IM_DateCreated property.</param>
 /// <param name="iM_DateLastUpdated">Initial value of the IM_DateLastUpdated property.</param>
 /// <param name="iM_Status">Initial value of the IM_Status property.</param>
 public static tblSourcingInventory CreatetblSourcingInventory(global::System.Guid id, global::System.Guid wareHouseId, global::System.Guid commodityId, global::System.Guid gradeId, global::System.Decimal unavailableBalance, global::System.DateTime iM_DateCreated, global::System.DateTime iM_DateLastUpdated, global::System.Int32 iM_Status)
 {
     tblSourcingInventory tblSourcingInventory = new tblSourcingInventory();
     tblSourcingInventory.id = id;
     tblSourcingInventory.WareHouseId = wareHouseId;
     tblSourcingInventory.CommodityId = commodityId;
     tblSourcingInventory.GradeId = gradeId;
     tblSourcingInventory.UnavailableBalance = unavailableBalance;
     tblSourcingInventory.IM_DateCreated = iM_DateCreated;
     tblSourcingInventory.IM_DateLastUpdated = iM_DateLastUpdated;
     tblSourcingInventory.IM_Status = iM_Status;
     return tblSourcingInventory;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the tblSourcingInventory EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotblSourcingInventory(tblSourcingInventory tblSourcingInventory)
 {
     base.AddObject("tblSourcingInventory", tblSourcingInventory);
 }