public static T GetById <T>(this CarterModule Module, int Id, IBaseFinder <T> Finder) where T : Entity { T entity = Finder.GetById(Id); if (entity == null) { throw new HttpException(HttpStatusCode.BadRequest, $"Element with Id = {Id.ToString()} not found"); } else { return(entity); } }
public static T GetById <T>(this INancyModule Module, string Id, IBaseFinder <T> Finder) where T : Entity { int id; if (!int.TryParse(Id, out id)) { throw new HttpException(HttpStatusCode.BadRequest, $"{Id} it is not an int"); } T entity = Finder.GetById(id); if (entity == null) { throw new HttpException(HttpStatusCode.BadRequest, $"Element with Id = {id.ToString()} not found"); } else { return(entity); } }