//end Get all alert [Alert_Manager_2020] //GET ALL MANAGER PRODUCT public List <managerproducts> get_manager_productsDB() { List <managerproducts> manager_products_List = new List <managerproducts>(); SqlConnection con = null; try { con = connect("DBConnectionString"); String query = "SELECT * FROM [manager_products_2020]"; SqlCommand cmd = new SqlCommand(query, con); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); // the connection will close as reading completes while (dr.Read()) { // Read till the end of the data into a row managerproducts mp = new managerproducts(); mp.ProdName = (string)dr["prodName"]; mp.ProdID = Convert.ToInt32(dr["prodID"]); mp.BeerType = (string)dr["beerType"]; mp.Amount = Convert.ToInt32(dr["amount"]); mp.Min_in_stock = Convert.ToInt32(dr["min_In_Stock"]); manager_products_List.Add(mp); } return(manager_products_List); } catch (Exception ex) { throw (ex); } finally { if (con != null) { con.Close(); } } }
[HttpPut] // edit public HttpResponseMessage Put(managerproducts managerproducts_mn) { int numEffected = 0; try { numEffected = managerproducts_mn.Update(); if (numEffected > 0) { return(Request.CreateResponse(HttpStatusCode.OK, numEffected)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Not Found")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
// GET api/<controller> public List <managerproducts> Get() { managerproducts Managerproducts = new managerproducts(); return(Managerproducts.get_managerproducts()); }