コード例 #1
0
        public async Task <IActionResult> PostCustomersTypes([FromBody] CustomersTypes customersTypes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.CustomersTypes.Add(customersTypes);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (CustomersTypesExists(customersTypes.CustomerTypeId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetCustomersTypes", new { id = customersTypes.CustomerTypeId }, customersTypes));
        }
コード例 #2
0
        public async Task <IActionResult> PutCustomersTypes([FromRoute] int id, [FromBody] CustomersTypes customersTypes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customersTypes.CustomerTypeId)
            {
                return(BadRequest());
            }

            _context.Entry(customersTypes).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomersTypesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }