public DataModel.PositionEntity GetPositionById(int id) { var position = dataContext.Positions.FirstOrDefault(p => p.PositionId == id); if (position != null) { PositionEntity result = new PositionEntity(); result.PositionId = position.PositionId; result.Description = position.Description; return result; } return null; }
public IEnumerable<DataModel.PositionEntity> GetAll() { List<PositionEntity> positions = new List<PositionEntity>(); foreach (var item in dataContext.Positions) { PositionEntity position = new PositionEntity(); position.PositionId = item.PositionId; position.Description = item.Description; positions.Add(position); } return positions; }
// POST api/Position public HttpResponseMessage PostPosition(PositionEntity position) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (position == null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } try { dbContext.SavePosition(position); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }