public virtual async Task <IActionResult> OnPostAsync() { await _service.CreateAsync( ObjectMapper.Map <CreateEditCategoryViewModel, CreateUpdateCategoryDto>(Category)); return(NoContent()); }
public async Task <ActionResult> Create([FromBody] CreateCategoryRequest request) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorResponse())); } var response = await _service.CreateAsync(request); if (!response.Success) { return(BadRequest(response.Erros)); } return(Ok()); } catch (ArgumentNullException ex) { return(NotFound("Category does not exist")); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> OnPostAsync() { var test = Category; await _bookAppService.CreateAsync(Category); return(NoContent()); }
public async Task CreateCategoryAsync() { //Given var input = new CreateUpdateCategoryDto { Name = "Software2 Development", Description = "Software Development Description" }; var result = await categoryAppService.CreateAsync(input); result.Id.ShouldNotBe(Guid.Empty); result.Name.ShouldBe(input.Name); result.Description.ShouldBe(input.Description); }
public async Task CreateCategory_Test() { var categoryName = "Category_" + DateTime.Now.ToString("yyyyMMddHHssfff"); await _categoryAppService.CreateAsync( new CreateCategoryDto { Name = categoryName }); await UsingDbContextAsync(async context => { var dbCategory = await context.Categories.FirstOrDefaultAsync(c => c.Name == categoryName); dbCategory.ShouldNotBeNull(); }); }
public async Task CreateProduct_Test() { var name = "Name_" + DateTime.Now.ToString("yyyyMMddHHssfff"); var description = "Des" + DateTime.Now.ToString("yyyyMMddHHssfff"); var quantity = 10; var price = 100000; var categoryName = "Category_" + DateTime.Now.ToString("yyyyMMddHHssfff"); var dbCategory = await _categoryAppService.CreateAsync( new CreateCategoryDto { Name = categoryName }); var shopName = "Name_" + DateTime.Now.ToString("yyyyMMddHHssfff"); var shopDes = "Des_" + DateTime.Now.ToString("yyyyMMddHHssfff"); var dbShop = await _shopAppService.CreateAsync( new CreateShopDto { Name = shopName, Description = shopDes }); await _productAppService.CreateAsync( new CreateProductDto { Name = name, Description = description, Quantity = quantity, Price = price, CategoryId = dbCategory.Id, ShopId = dbShop.Id }); await UsingDbContextAsync(async context => { var dbProduct = await context.Products.FirstOrDefaultAsync(p => p.Name == name && p.Description == description); dbProduct.ShouldNotBeNull(); dbProduct.ShopId.ShouldBe(dbShop.Id); dbProduct.CategoryId.ShouldBe(dbCategory.Id); dbProduct.Quantity.ShouldBe(quantity); dbProduct.Price.ShouldBe(price); }); }
public Task <CategoryDto> CreateAsync(CreateUpdateCategoryDto input) { return(_service.CreateAsync(input)); }
public async Task <IActionResult> OnPostAsync() { await _service.CreateAsync(Category); return(NoContent()); }
public Task <CategoryDto> CreateAsync(CategoryDto input) { return(_AppService.CreateAsync(input)); }