public async Task <Response <KnowledgeCategoryDto> > Handle(CreateKnowledgeCategoryCommand request, CancellationToken cancellationToken)
        {
            bool nameExists = _dbContext.KnowledgeCategories.Where(kc => kc.UserId == request.UserId).Any(kc => kc.Name == request.Name);

            if (nameExists)
            {
                return(Response <KnowledgeCategoryDto> .Fail("A Category with this name already exists."));
            }


            var knowledgeCategory = new KnowledgeCategory()
            {
                Name = request.Name, Comment = request.Comment, UserId = request.UserId
            };

            var result = _dbContext.KnowledgeCategories.Add(knowledgeCategory);
            await _dbContext.SaveChangesAsync();

            if (result != null)
            {
                return(Response <KnowledgeCategoryDto> .Ok(_mapper.Map <KnowledgeCategoryDto>(result.Entity)));
            }
            else
            {
                return(Response <KnowledgeCategoryDto> .Fail("An error occurred while creating the Category."));
            }
        }
コード例 #2
0
        public KnowledgeCategory AddCategory(KnowledgeCategory parent)
        {
            var category = new KnowledgeCategory();

            category.ParentCategory_Id = parent.MyId;
            var service = new KnowledgeCategoryService();

            service.Create(category);
            return(category);
        }
コード例 #3
0
        // GET: /Platform/iDepartment/Edit/5
        /// <summary>
        /// </summary>
        /// <param name="id">
        /// </param>
        /// <returns>
        /// </returns>
        public async Task <IActionResult> EditAsync(string id)
        {
            var item = new KnowledgeCategory();

            if (!string.IsNullOrEmpty(id))
            {
                item = JsonConvert.DeserializeObject <KnowledgeCategory>(jsonDataService.FindAsync(id).Result.JsonDataStr);
            }
            return(View(item));
        }
コード例 #4
0
        public async Task <KnowledgeCategory> Post(KnowledgeCategory category)
        {
            if (ModelState.IsValid)
            {
                await knowledgeDatabaseService.Add(category);

                return(category);
            }
            throw new Exception();
        }
コード例 #5
0
        public async Task <IActionResult> EditAsync(string id, KnowledgeCategory collection)
        {
            if (!ModelState.IsValid)
            {
                return(View(collection));
            }

            await jsonDataService.SaveAsync(id, collection);

            await _unitOfWork.CommitAsync();

            return(new EditSuccessResult(id));
        }
コード例 #6
0
        public KnowledgeCategory[] GetByParent(KnowledgeCategory parent)
        {
            var service = new KnowledgeCategoryService();
            IEnumerable <KnowledgeCategory> enumer;

            if (parent == null)
            {
                enumer = service.GetChildCategory(0);
            }
            else
            {
                enumer = service.GetChildCategory(parent.MyId);
            }
            return(enumer.ToArray());
        }
コード例 #7
0
 public KnowledgeCategoryTreeModel(KnowledgeCategory category)
 {
 }
コード例 #8
0
        public Knowledge[] GetKnowledgeByCategory(KnowledgeCategory category)
        {
            var enumer = (new KnowledgeService()).GetKnowledgesByCategoryId(category.MyId);

            return(enumer.ToArray());
        }
コード例 #9
0
 internal void SetQuestionType(KnowledgeCategory knowledgeCat)
 {
     _currentQuestionType = knowledgeCat;
 }
コード例 #10
0
 public async Task Put(KnowledgeCategory category) => await knowledgeDatabaseService.Update(category);