private static void SetInventoryItemReferencedEntities(InventoryItem entityItem, ref InventoryItemDto dtoItem)
        {
            if (entityItem.CategoryRowId.HasValue)
            {
                dtoItem.Category = entityItem.tblInventoryCategory.TranslateToDao();
                
            }

            if (entityItem.LocationRowId.HasValue)
            {
                dtoItem.Location = entityItem.tblInventoryLocation.TranslateToDao();
            }

            if (entityItem.PreferedSupplierRowId.HasValue)
            {
                dtoItem.PreferedSupplier = entityItem.tblInventorySupplier_1.TranslateToDao();
            }
        }
        public bool Save(InventoryItemDto item)
        {
            if (item == null)
            {
                return false;
            }

            var entityItem =
                _entities.tblInventoryItem.Where(i => i.InventoryItemId == item.Id).SingleOrDefault();

            if (entityItem == null)
            {
                entityItem = new InventoryItem { InventoryItemId = item.Id };
                _entities.tblInventoryItem.AddObject(entityItem);
            }

            entityItem.ActualBalance = item.ActualBalance;
            entityItem.EstimatedBalance = item.EstimatedBalance;
            entityItem.ExpiringDate = item.ExpiringDate;
            entityItem.InventoryItemName = item.Name;


            entityItem.AverageOrderPrice = item.AverageOrderPrice.HasValue? (decimal)item.AverageOrderPrice: (decimal?) null ;
            entityItem.InventoryImage = item.Image;
            entityItem.LastOrderAmount = item.LastOrderAmount;

            if(item.Location != null)
            {
                var locationEntity =
                    _entities.tblInventoryLocation.SingleOrDefault(l => l.LocationId == item.Location.Id);

                if (locationEntity != null)
                {
                    entityItem.LocationRowId = locationEntity.RowId;
                }
            }

            if (item.Category != null)
            {
                var categoryEntity =
                    _entities.tblInventoryCategory.SingleOrDefault(l => l.CategoryId == item.Category.Id);

                if (categoryEntity != null)
                {
                    entityItem.CategoryRowId = categoryEntity.RowId;
                }
            }

            if(item.PreferedSupplier != null)
            {
                var supplierEntity =
                    _entities.tblInventorySupplier.SingleOrDefault(l => l.SupplierId == item.PreferedSupplier.Id);

                if (supplierEntity != null)
                {
                    entityItem.PreferedSupplierRowId = supplierEntity.RowId;
                }
            }
            

            _entities.SaveChanges();
            if (!EntityCache.InventoryItems.Entities.Contains(item))
            {
                EntityCache.InventoryItems.Add(item);
            }
            

            return true;

        }