예제 #1
0
        public IActionResult Add(CategoryForAddDto categoryForAddDto)
        {
            var result = categoryService.Add(categoryForAddDto);

            if (result.Success)
            {
                return(CreatedAtAction("GetById", new { id = result.Data }, result.Message));
            }
            return(BadRequest(result.Message));
        }
        public void Add_WhenAddedNewCategory_ShouldAddAndReturnId()
        {
            // Arrange
            var categoryForAddDto = new CategoryForAddDto();
            var mockCategoryDal   = new MockCategoryDal().MockAdd(new Category());
            var sut = new CategoryManager(mockCategoryDal.Object);

            // Act
            var result = sut.Add(categoryForAddDto);

            // Assert
            Assert.Equal(new short(), result.Data);
        }
        private async Task AddCategory()
        {
            CategoryForAddDto categoryForAddDto = new CategoryForAddDto()
            {
                Description = txtDescription.Text,
                Name        = txtName.Text
            };

            await CategoryService.Add(categoryForAddDto);

            MessageBox.Show(Messages.CategoryAdded);
            await LoadCategoryList();
        }
        public async Task <IActionResult> AddCategory(CategoryForAddDto categoryDto)
        {
            var category = new Category()
            {
                CategoryName     = categoryDto.CategoryName,
                VerifyFireLabels = categoryDto.VerifyFireLabels
            };

            await _context.Categories.AddAsync(category);

            await _context.SaveChangesAsync();

            return(Ok(category));
        }
        public IDataResult <short> Add(CategoryForAddDto categoryForAddDto)
        {
            var category = new Category()
            {
                CreatedAt   = DateTime.Now,
                Description = categoryForAddDto.Description,
                IsEnable    = true,
                Name        = categoryForAddDto.Name,
                UpdatedAt   = DateTime.Now
            };

            categoryDal.Add(category);
            return(new SuccessDataResult <short>(category.Id, Messages.CategoryAdded));
        }
예제 #6
0
        public void CategoryForAddValidator_TrueStory()
        {
            // Arrange
            var model = new CategoryForAddDto()
            {
                Description = "Desc Category T",
                Name        = "Category T"
            };
            var sut = new CategoryForAddValidator();

            // Act
            var result = sut.TestValidate(model);

            // Assert
            result.ShouldNotHaveAnyValidationErrors();
        }
예제 #7
0
        public static async Task <Uri> Add(CategoryForAddDto categoryForAddDto)
        {
            using var client = new HttpClient();
            var uri = $"{APIAddresses.CategoryService}";

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", FormAccessToken.Token);
            var response = await client.PostAsJsonAsync(uri, categoryForAddDto);

            if (response.IsSuccessStatusCode)
            {
                return(response.Headers.Location);
            }

            var errorContent = response.Content.ReadFromJsonAsync <ErrorDetail>().Result;

            throw new HttpFailureException(errorContent);
        }
예제 #8
0
        public IActionResult AddCategory([FromBody] CategoryForAddDto categoryForAddDto)
        {
            var category = _mapper.Map <Category>(categoryForAddDto);

            category.Active     = false;
            category.CategoryId = Guid.NewGuid().ToString();

            IResult result = _categoryService.Add(category);

            if (!result.Success)
            {
                return(BadRequest(new ErrorResultDto {
                    Name = ErrorNames.DefaultError,
                    Type = ErrorTypes.Danger,
                    Value = SecurityMessages.SystemError
                }));
            }

            return(Ok(result.Message));
        }