Exemple #1
0
        public IActionResult AddCategory(CategoryViewModel category)
        {
            if (category == null)
            {
                return(Ok(new { code = 1, msg = "FALSE", count = 1, data = string.Empty }));
            }
            Category dbCategory;

            dbCategory = _categoryManager.LoadEntities(x => x.Id == category.Id).FirstOrDefault();
            if (dbCategory == null)
            {
                dbCategory = new Category
                {
                    CategoryName       = category.CategoryName,
                    ParentCategoryName = category.ParentCategoryName,
                };
                var result = _categoryManager.AddEntity(dbCategory);
                if (result != null)
                {
                    return(Ok(new { code = 0, msg = "SUCCEED", count = 1, data = string.Empty }));
                }
            }
            else
            {
                dbCategory.CategoryName       = category.CategoryName;
                dbCategory.ParentCategoryName = category.ParentCategoryName;
                var result = _categoryManager.EditEntity(dbCategory);
                if (result)
                {
                    return(Ok(new { code = 0, msg = "SUCCEED", count = 1, data = string.Empty }));
                }
            }
            return(Ok(new { code = 1, msg = "FALSE", count = 1, data = string.Empty }));
        }