public ActionResult <int> AddCategory(GeneralCategoryDTO category) { IdentityUser currentUser = GetCurrentUser(); if (currentUser == null || String.IsNullOrEmpty(category.Name)) { return(BadRequest()); } GeneralCategory categoryToCreate = new GeneralCategory(category.Name, currentUser); _itemRepository.AddCategory(categoryToCreate); _itemRepository.SaveChanges(); return(Ok(categoryToCreate.Id)); }
private async void AddCategory() { AddCategoryDialog dialog = new AddCategoryDialog(); ContentDialogResult result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { if (!String.IsNullOrEmpty(dialog.CategoryName)) { if (!Categories.Any(c => c.Name == dialog.CategoryName)) { Category catToAdd = new Category(dialog.CategoryName); int catId = await _itemRepository.AddCategory(catToAdd); catToAdd.Id = catId; Categories.Add(catToAdd); BuildItemList(); } } } }