// PUT clients/{id} //public HttpResponseMessage Put(int id, Treatment model) //{ // if (ModelState.IsValid && id == model.Id) // { // //tu jeszcze bym dodała try-catch na submit changes // //ew. osobna metoda, która by to robiła // //ew.2 łapanie po różnych wyjątkach tak jak niżej jest // try // { // repository.UpdateTreatmentById(id, model); // } // catch (Exception ex) // { // //Console.WriteLine(ex.ToString()); // return Request.CreateResponse(HttpStatusCode.NotFound); // } // return Request.CreateResponse(HttpStatusCode.OK); // } // else // { // return Request.CreateResponse(HttpStatusCode.BadRequest); // } //} /* * // PUT clients/{id} * public HttpResponseMessage Put(Guid id, bool active) * { * if (ModelState.IsValid) * { * var existingTreatment = _repository.Get(id); * * if (existingTreatment == null) * throw new HttpResponseException(HttpStatusCode.NotFound); * * var treatment = _repository.ChangeStatus(id, active); * * return Request.CreateResponse(HttpStatusCode.OK, treatment); * } * else * { * return Request.CreateResponse(HttpStatusCode.BadRequest); * } * } */ #endregion /// <summary> /// Checks if treat exists. /// </summary> /// <returns>The if treat exists.</returns> /// <param name="id">Identifier.</param> public static TreatmentViewModel CheckIfTreatExists(Guid id) { TreatmentViewModel treat = null; try { treat = _repository.Get(id); } catch { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound, Content = new StringContent("Treatment not found.") }); } return(treat); }