コード例 #1
0
 public Guid AddInventory(Inventory inventory)
 {
     ValidationResultInfo vri=Validate(inventory);
     if (!vri.IsValid)
     {
         
         throw new DomainValidationException(vri,"Failed to validate Inventory");
     }
     tblInventory tblInv = _ctx.tblInventory.FirstOrDefault(n => n.id == inventory.Id); ;
     DateTime dt = DateTime.Now;
     if (tblInv == null)
     {
         tblInv = new tblInventory();
         tblInv.id = inventory.Id;
         tblInv.IM_DateCreated = dt;
         tblInv.IM_Status = (int)EntityStatus.Active;// true;
         _ctx.tblInventory.AddObject(tblInv);
     }
     var entityStatus = (inventory._Status == EntityStatus.New) ? EntityStatus.Active : inventory._Status;
     if (tblInv.IM_Status != (int)entityStatus)
         tblInv.IM_Status = (int)inventory._Status;
     tblInv.IM_DateLastUpdated = dt;
     tblInv.ProductId = inventory.Product.Id;
     tblInv.WareHouseId = inventory.Warehouse.Id;
     tblInv.Balance = inventory.Balance;
     tblInv.UnavailableBalance = inventory.UnavailableBalance;
     tblInv.Value = inventory.Value;
     _ctx.SaveChanges();
     return tblInv.id;
 }
コード例 #2
0
 private InventoryDTO Map(tblInventory tbl)
 {
     var dto = new InventoryDTO
     {
         MasterId = tbl.id,
         DateCreated = tbl.IM_DateCreated,
         DateLastUpdated = tbl.IM_DateLastUpdated,
         StatusId = tbl.IM_Status,
         Balance = tbl.Balance.HasValue ? tbl.Balance.Value : 0,
         Value = tbl.Value.HasValue ? tbl.Value.Value : 0,
         ProductMasterID = tbl.ProductId,
         UnavailableBalance = tbl.UnavailableBalance,
         WarehouseMasterID = tbl.WareHouseId,
     };
     return dto;
 }
コード例 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the tblInventory EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotblInventory(tblInventory tblInventory)
 {
     base.AddObject("tblInventory", tblInventory);
 }
コード例 #4
0
 /// <summary>
 /// Create a new tblInventory object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="wareHouseId">Initial value of the WareHouseId property.</param>
 /// <param name="productId">Initial value of the ProductId 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="unavailableBalance">Initial value of the UnavailableBalance property.</param>
 /// <param name="iM_Status">Initial value of the IM_Status property.</param>
 public static tblInventory CreatetblInventory(global::System.Guid id, global::System.Guid wareHouseId, global::System.Guid productId, global::System.DateTime iM_DateCreated, global::System.DateTime iM_DateLastUpdated, global::System.Decimal unavailableBalance, global::System.Int32 iM_Status)
 {
     tblInventory tblInventory = new tblInventory();
     tblInventory.id = id;
     tblInventory.WareHouseId = wareHouseId;
     tblInventory.ProductId = productId;
     tblInventory.IM_DateCreated = iM_DateCreated;
     tblInventory.IM_DateLastUpdated = iM_DateLastUpdated;
     tblInventory.UnavailableBalance = unavailableBalance;
     tblInventory.IM_Status = iM_Status;
     return tblInventory;
 }
コード例 #5
0
        private void AdjustInventory()
        {
            string conn = ConfigurationManager.AppSettings["pzcussons_inventory"];
            using (var ctx = new CokeDataContext(conn))
            {
                using (var c = NestedContainer)
                {
                    Using<IAdjustInventoryWindow>(c).ShowAdjustDialog();

                    if(AdjustQuantity>0m)
                    {
                        try
                        {
                            var products = ctx.tblProduct.Select(p => p.id).ToList();
                            if(products.Any())
                            {
                                DateTime date = DateTime.Now;
                                var wareHouse = ctx.tblCostCentre.FirstOrDefault(p => p.Cost_Centre_Code == "PZ Cussons EA");
                                if(wareHouse==null)
                                {
                                    const string error = "Something bad has happened while adjusting inventory..there is no warehouse";
                                    MessageBox.Show(error);
                                    FileUtility.LogError(error);
                                    return;
                                }

                                foreach (var productId in products)
                                {
                                    var inventory = ctx.tblInventory.FirstOrDefault(p => p.ProductId == productId);
                                    if(inventory==null)
                                    {
                                        inventory = new tblInventory()
                                                        {
                                                            id=Guid.NewGuid(),
                                                            IM_DateCreated = date,
                                                            IM_DateLastUpdated = date,
                                                            IM_Status = (int)EntityStatus.Active,
                                                        };
                                        ctx.tblInventory.AddObject(inventory);
                                    }
                                    inventory.Balance += AdjustQuantity;
                                    inventory.ProductId = productId;
                                    inventory.WareHouseId = wareHouse.Id;
                                    inventory.Value = 0;
                                }
                                ctx.SaveChanges();
                            }
                            MessageBox.Show(string.Format("Inventory adjustment success=>{0} product adjusted with{1}",products.Count,AdjustQuantity));

                        }
                        catch (Exception e)
                        {
                            var error = e.Message
                                        +
                                        (e.InnerException == null
                                             ? ""
                                             : "\n" + e.InnerException);
                            MessageBox.Show("Something bad has happened while adjusting inventory..see logs for details");
                            FileUtility.LogError(error);
                        }
                       
                        
                    }
                }
                
            }
        }
コード例 #6
0
 protected Inventory Map(tblInventory tblInv)
 {
     Inventory inv = new Inventory(tblInv.id)
                         {
                             Warehouse = _costCentreRepository.GetById(tblInv.tblCostCentre.Id) as Warehouse,
                             Product = _productRepository.GetById(tblInv.ProductId),
                             Balance = tblInv.Balance.Value,
                             Value = (decimal) tblInv.Value,
                             UnavailableBalance = tblInv.UnavailableBalance,
                         };
     return inv;
 }