public IHttpActionResult AddNewLine(int customerId, Line lineToAdd) { if (lineToAdd == null || lineToAdd.LineNumber == null) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NoContent, "Sorry, we could not get the data"))); } if (customerId < 1) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NoContent, "Sorry,Customer id Can not be smaller than 1"))); } Line addedLine; try { addedLine = _lineManager.AddNewLine(lineToAdd, customerId); } catch (AlreadyExistExeption e) //this line already exists to this customer { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Found, e.Message))); } catch (FoundLineExeption e) //this line already exists to another customer { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.Message))); } catch (Exception) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Something went wrong"))); } if (addedLine != null) { return(Ok(addedLine)); } else { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "We could not add this line, please try again"))); } }