public HttpResponseMessage<Workout> Post(Workout workout) { var id = _unitOfWork.CurrentSession.Save(workout); _unitOfWork.Commit(); var response = new HttpResponseMessage<Workout> (workout, HttpStatusCode.Created); response.Headers.Location = new Uri(Request.RequestUri, Url.Route(null, new { id })); return response; }
public Workout Put(Workout workout) { var existingWorkout = _unitOfWork.CurrentSession.Query<Workout>().SingleOrDefault(x => x.Id == workout.Id); //check to ensure update can occur if(existingWorkout==null) throw new HttpResponseException(HttpStatusCode.NotFound); //merge detached entity into session _unitOfWork.CurrentSession.Merge(workout); _unitOfWork.Commit(); return workout; }