コード例 #1
0
        public async Task <IActionResult> Get(long id)
        {
            var categoryArea = await _categoryAreaService.ReadAsync(id);

            var result = CategoryAreaDto.ConvertFrom(categoryArea);

            return(new ObjectResult(result));
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] CategoryAreaDto categoryAreaDto)
        {
            var categoryArea = new CategoryArea
            {
                Name        = categoryAreaDto.Name,
                Description = categoryAreaDto.Description
            };
            await _categoryAreaService.CreateAsync(categoryArea);

            categoryAreaDto.Id = categoryArea.Id;
            return(CreatedAtRoute("GetCategoryArea", new { id = categoryAreaDto.Id }, categoryAreaDto));
        }
コード例 #3
0
        public async Task <IActionResult> Put(long id, [FromBody] CategoryAreaDto categoryAreaDto)
        {
            if (id != categoryAreaDto.Id)
            {
                throw new ApplicationException($"Invalid Category Area Id:{id}");
            }

            var categoryArea = await _categoryAreaService.ReadAsync(id);

            if (categoryArea == null)
            {
                throw new EntityNotFoundException($"Category Area ({id}) not found.");
            }

            categoryArea.Name        = categoryAreaDto.Name;
            categoryArea.Description = categoryAreaDto.Description;
            await _categoryAreaService.UpdateAsync(categoryArea);

            return(new NoContentResult());
        }
コード例 #4
0
        public async Task <IEnumerable <CategoryAreaDto> > Get()
        {
            var categoryAreas = await _categoryAreaService.ReadAllAsync();

            return(categoryAreas.Select(ca => CategoryAreaDto.ConvertFrom(ca)).ToList());
        }