Note that there are some explanatory texts on larger screens.

plurals
  1. POreduce complexity of service class
    text
    copied!<p>I am developing a web api using WCF Web Api preview 5. At the moment I have a resource class fully functional, how ever I noticed my methods inside this resouce are getting complex.</p> <p>For example:</p> <pre><code>[WebInvoke(UriTemplate = "{EhrID}/PhysicalTest",Method="POST")] public HttpResponseMessage&lt;DTO.PhysicalTest&gt; PostPhysicalTest(int EhrID, DTO.PhysicalTest PhysicalTestDTO) { var EHR = repository.FindById(EhrID); var PhysicalTest = Mapper.Map&lt;DTO.PhysicalTest, PhysicalTest&gt;(PhysicalTestDTO); if (PhysicalTest == null) { var response = CreateResponseForException("No object to store", HttpStatusCode.BadRequest); throw new HttpResponseException(response); } try { if (EHR.PhysicalTests == null) { EHR.PhysicalTests = new List&lt;PhysicalTest&gt;(); } PhysicalTest.CreationDate = DateTime.Now; EHR.PhysicalTests.Add(PhysicalTest); _unitOfWork.Commit(); return new HttpResponseMessage&lt;DTO.PhysicalTest&gt;(PhysicalTestDTO, HttpStatusCode.Created); } catch (Exception ex) { var response = CreateResponseForException("Cannot create Physical Test", HttpStatusCode.InternalServerError); throw new HttpResponseException(response); } } </code></pre> <p>As you may notice this method has the task of posting a new Physical Test, but it's actually validating my model too (I'm missing lots of validations still, property validations), which should not be this class concern. If there any approachable way to reduce the complexity of the methods inside de resource?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload