コード例 #1
0
        public int AddCategory(int parentId, string categoryName, string categoryNumber)
        {
            var existing = DataSession.Query <Ordering.PurchaseOrderCategory>().FirstOrDefault(x => x.ParentID == parentId && x.CatNo == categoryNumber);

            if (existing != null)
            {
                if (existing.Active)
                {
                    throw new Exception($"A category already exists with category number: {categoryNumber}");
                }
                else
                {
                    existing.Active = true;
                    return(existing.CatID);
                }
            }

            var cat = new Ordering.PurchaseOrderCategory()
            {
                ParentID = parentId,
                CatName  = categoryName,
                CatNo    = categoryNumber,
                Active   = true
            };

            DataSession.Insert(cat);

            return(cat.CatID);
        }
コード例 #2
0
 private Category CreateCategory(Ordering.PurchaseOrderCategory category)
 {
     return(new Category()
     {
         CategoryID = category.CatID,
         ParentID = category.ParentID,
         CategoryName = category.CatName,
         CategoryNumber = category.CatNo,
         Active = category.Active
     });
 }