示例#1
0
        public async Task <IActionResult> Post(int apiVersion, [CustomizeValidator] CustomerDto dto)
        {
            var item = dto.Map();

            _dbContext.Set <Customer>().Add(item);
            await _dbContext.SaveChangesAsync();

            return(Created($"api/v{apiVersion}/Customers/{item.Id}", dto));
        }
示例#2
0
        public async Task <IActionResult> Put(long id, [FromBody] CustomerDto dto)
        {
            var item = await _dbContext.Set <Customer>().FindAsync(id);

            if (item == null)
            {
                return(NotFound());
            }

            if (!await _validator.IsValid(dto, ModelState))
            {
                return(BadRequest(ModelState));
            }

            dto.Map(item);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }