public IActionResult GetCategories() { try { List <PublicControllerCategory> categories = new List <PublicControllerCategory>(); using (Dal db = new Dal()) { using (DbDataReader reader = db.ExecuteReader( "select Id,name,'https://allegro.pl/'+routeUrl as Url from websiteCategories with (nolock)")) { while (reader.Read()) { PublicControllerCategory tempCat = new PublicControllerCategory() { Id = reader.GetInt32(0), Name = reader.GetString(1), Url = reader.GetString(2) }; categories.Add(tempCat); } } } return(new JsonResult(categories)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult GetCategory(int categoryId) { try { bool parse = int.TryParse(categoryId.ToString(), out _); if (!parse) { return(BadRequest("Category Id is invalid.")); } List <PublicControllerCategory> categories = new List <PublicControllerCategory>(); using (Dal db = new Dal()) { using (DbDataReader reader = db.ExecuteReader( $"select Id,name,'https://allegro.pl/'+routeUrl as Url from websiteCategories with (nolock) where Id = " + categoryId + ";")) { while (reader.Read()) { PublicControllerCategory tempCat = new PublicControllerCategory() { Id = reader.GetInt32(0), Name = reader.GetString(1), Url = reader.GetString(2) }; categories.Add(tempCat); } } } if (categories.Count == 0) { return(NotFound("Not found category with id " + categoryId)); } return(new JsonResult(categories)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }