예제 #1
0
        public async Task <IHttpActionResult> PutJobHistory(JobHistory entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _dbContext.ApplyChanges(entity);

            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_dbContext.JobHistory.Any(e => e.JobHistoryId == entity.JobHistoryId))
                {
                    return(Conflict());
                }
                throw;
            }

            await _dbContext.LoadRelatedEntitiesAsync(entity);

            entity.AcceptChanges();
            return(Ok(entity));
        }
예제 #2
0
        public async Task <IHttpActionResult> PostJobHistory(JobHistory entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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


            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (_dbContext.JobHistory.Any(e => e.JobHistoryId == entity.JobHistoryId))
                {
                    return(Conflict());
                }
                throw;
            }

            await _dbContext.LoadRelatedEntitiesAsync(entity);

            entity.AcceptChanges();
            return(CreatedAtRoute("DefaultApi", new { id = entity.JobHistoryId }, entity));
        }