public async Task <IActionResult> Create(CategoryViewModel categoryViewModel) { if (ModelState.IsValid) { var category = new Category() { Id = Guid.NewGuid().ToString(), Name = categoryViewModel.Name, Slug = categoryViewModel.Slug, Content = categoryViewModel.Content, }; try { var result = await _categoryServices.AddAsync(category); if (result > 0) { return(RedirectToAction(nameof(Index))); } } catch (NullReferenceException) { return(NotFound()); } catch (Exception) { return(BadRequest()); } } return(View(categoryViewModel)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Category category) { if (ModelState.IsValid) { await _categoryServices.AddAsync(category); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Add(CategoryViewModel categoryViewModel) { if (ModelState.IsValid) { var categories = await _categoryServices.AddAsync(categoryViewModel); if (categories) { TempData["Success"] = _commonLocalizer.GetLocalizedHtmlString("msg_AddSuccess").ToString(); return(RedirectToAction("Index")); } ViewData["Error"] = _categoryLocalizer.GetLocalizedHtmlString("err_AddCategoryFailure"); return(View(categoryViewModel)); } Log.Error("Add Category Error"); return(View(categoryViewModel)); }
public async Task HandleAsync(CreateCategory command) { await _categoryServices.AddAsync(command.Name, command.DefaultOperationType); }
public async Task AddAsyncShouldInvokeAddAsyncOnRepository() { await _categoryService.AddAsync("Sport", OperationTypeEnum.Expense); Repository.Verify(x => x.AddAsync(It.IsAny <Category>()), Times.Once); }