/// <summary>
 /// Deprecated Method for adding a new object to the tblInventoryCategory EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotblInventoryCategory(InventoryCategory inventoryCategory)
 {
     base.AddObject("tblInventoryCategory", inventoryCategory);
 }
 /// <summary>
 /// Create a new InventoryCategory object.
 /// </summary>
 /// <param name="rowId">Initial value of the RowId property.</param>
 /// <param name="categoryId">Initial value of the CategoryId property.</param>
 /// <param name="categoryName">Initial value of the CategoryName property.</param>
 public static InventoryCategory CreateInventoryCategory(global::System.Int32 rowId, global::System.Guid categoryId, global::System.String categoryName)
 {
     InventoryCategory inventoryCategory = new InventoryCategory();
     inventoryCategory.RowId = rowId;
     inventoryCategory.CategoryId = categoryId;
     inventoryCategory.CategoryName = categoryName;
     return inventoryCategory;
 }
Exemplo n.º 3
0
        public bool Save(CategoryDto category)
        {
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            var entityItem =
                _entities.tblInventoryCategory.Where(i => i.CategoryId == category.Id).SingleOrDefault();
            
            if (entityItem == null)
            {
                entityItem = new InventoryCategory { CategoryId = category.Id };
                _entities.tblInventoryCategory.AddObject(entityItem);
            }

            entityItem.CategoryName = category.Name;
            if(category.Parent != null)
            {
                var parent =
                    (_entities.tblInventoryCategory.Where(c => c.CategoryId == category.Parent.Id)).SingleOrDefault();

                entityItem.ParentCategoryId = parent != null ? parent.RowId: (int?) null ;
            }

            _entities.SaveChanges();

            EntityCache.Categories.Add(category);

            return true;
        }