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.")); } }
public KnowledgeCategory AddCategory(KnowledgeCategory parent) { var category = new KnowledgeCategory(); category.ParentCategory_Id = parent.MyId; var service = new KnowledgeCategoryService(); service.Create(category); return(category); }
// 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)); }
public async Task <KnowledgeCategory> Post(KnowledgeCategory category) { if (ModelState.IsValid) { await knowledgeDatabaseService.Add(category); return(category); } throw new Exception(); }
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)); }
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()); }
public KnowledgeCategoryTreeModel(KnowledgeCategory category) { }
public Knowledge[] GetKnowledgeByCategory(KnowledgeCategory category) { var enumer = (new KnowledgeService()).GetKnowledgesByCategoryId(category.MyId); return(enumer.ToArray()); }
internal void SetQuestionType(KnowledgeCategory knowledgeCat) { _currentQuestionType = knowledgeCat; }
public async Task Put(KnowledgeCategory category) => await knowledgeDatabaseService.Update(category);