public System.Web.Http.Results.OkNegotiatedContentResult <List <RestaurantMenuCategoryModel> > GetRestaurantsMenuCategories(Int32 restaurantId) { SqlDataReader reader = null; SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["DBConnection"]; SqlCommand sqlCmd = new SqlCommand(); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "spGetRestaurantMenuCategory"; sqlCmd.Connection = myConnection; SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@Restaurant_Id"; parameter.SqlDbType = SqlDbType.Int; parameter.Size = 3; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurantId; sqlCmd.Parameters.Add(parameter); myConnection.Open(); reader = sqlCmd.ExecuteReader(); int restaurantMenuCategoryIdOrdinal = reader.GetOrdinal("Restaurant_Menu_Category_Id"); int restaurantIdOrdinal = reader.GetOrdinal("Restaurant_Id"); int restaurantMenuCategoryOrdinal = reader.GetOrdinal("Restaurant_Menu_Category"); int sortIndexOrdinal = reader.GetOrdinal("Sort_Index"); int endDateOrdinal = reader.GetOrdinal("End_Date"); List <RestaurantMenuCategoryModel> restaurantList = new List <RestaurantMenuCategoryModel>(); RestaurantMenuCategoryModel restaurant = null; while (reader.Read()) { restaurant = new RestaurantMenuCategoryModel(); restaurant.RestaurantMenuCategoryId = reader.GetInt32(restaurantMenuCategoryIdOrdinal); restaurant.RestaurantId = reader.GetInt32(restaurantIdOrdinal); restaurant.RestaurantMenuCategory = reader.GetString(restaurantMenuCategoryOrdinal); restaurant.SortIndex = reader.GetInt32(sortIndexOrdinal); restaurant.EndDate = reader.IsDBNull(endDateOrdinal) ? (DateTime?)null : (DateTime?)reader.GetDateTime(endDateOrdinal); restaurantList.Add(restaurant); } myConnection.Close(); return(Ok(content: restaurantList)); }
public System.Web.Http.Results.OkNegotiatedContentResult <ReturnCodeModel> SaveRestaurantMenuCategory([FromBody] RestaurantMenuCategoryModel restaurantMenuCategory) { try { Int32 recordId = 0; SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["DBConnection"]; SqlCommand sqlCmd = new SqlCommand(); sqlCmd.CommandText = "spSaveRestaurantMenuCategory"; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Connection = myConnection; SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@Restaurant_Menu_Category_Id"; parameter.SqlDbType = SqlDbType.Int; parameter.Size = 4; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurantMenuCategory.RestaurantMenuCategoryId; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@Restaurant_Id"; parameter.SqlDbType = SqlDbType.Int; parameter.Size = 4; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurantMenuCategory.RestaurantId; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@Restaurant_Menu_Category"; parameter.SqlDbType = SqlDbType.VarChar; parameter.Size = 150; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurantMenuCategory.RestaurantMenuCategory; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@Sort_Index"; parameter.SqlDbType = SqlDbType.Int; parameter.Size = 4; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurantMenuCategory.SortIndex; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@End_Date"; parameter.SqlDbType = SqlDbType.DateTime; parameter.Size = 8; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurantMenuCategory.EndDate; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@Return_Id"; parameter.SqlDbType = SqlDbType.Int; parameter.Size = 4; parameter.Direction = ParameterDirection.Output; sqlCmd.Parameters.Add(parameter); myConnection.Open(); sqlCmd.ExecuteNonQuery(); recordId = (Int32)parameter.Value; myConnection.Close(); ReturnCodeModel returnCodeModel = new ReturnCodeModel(); returnCodeModel.RecordId = recordId; returnCodeModel.ReturnCode = "success"; returnCodeModel.Message = "The record has been saved successfully"; return(Ok(content: returnCodeModel)); } catch (Exception ex) { ExceptionModel.SaveException(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodInfo.GetCurrentMethod().Name); return(null); } }