Beispiel #1
0
        public async Task <IActionResult> PostCarrierEmployee([FromBody] CarrierEmployee carrierEmployee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.CarrierEmployee.Add(carrierEmployee);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (CarrierEmployeeExists(carrierEmployee.UserId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetCarrierEmployee", new { id = carrierEmployee.UserId }, carrierEmployee));
        }
Beispiel #2
0
        public async Task <IActionResult> PutCarrierEmployee([FromRoute] long id, [FromBody] CarrierEmployee carrierEmployee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != carrierEmployee.UserId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }