public async Task <IActionResult> Get(long id) { var categoryArea = await _categoryAreaService.ReadAsync(id); var result = CategoryAreaDto.ConvertFrom(categoryArea); return(new ObjectResult(result)); }
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)); }
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()); }
public async Task <IEnumerable <CategoryAreaDto> > Get() { var categoryAreas = await _categoryAreaService.ReadAllAsync(); return(categoryAreas.Select(ca => CategoryAreaDto.ConvertFrom(ca)).ToList()); }