Пример #1
0
        public async Task <IHttpActionResult> PutEmployee(Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _dbContext.ApplyChanges(employee);

            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_dbContext.Employees.Any(e => e.EmployeeId == employee.EmployeeId))
                {
                    return(Conflict());
                }
                throw;
            }

            await _dbContext.LoadRelatedEntitiesAsync(employee);

            employee.AcceptChanges();
            return(Ok(employee));
        }
Пример #2
0
        public async Task <IHttpActionResult> PostEmployee(Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            employee.TrackingState = TrackingState.Added;
            _dbContext.ApplyChanges(employee);

            await _dbContext.SaveChangesAsync();

            await _dbContext.LoadRelatedEntitiesAsync(employee);

            employee.AcceptChanges();
            return(CreatedAtRoute("DefaultApi", new { id = employee.EmployeeId }, employee));
        }