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); } }
public System.Web.Http.Results.OkNegotiatedContentResult <ReturnCodeModel> SaveRestaurant([FromBody] RestaurantModel restaurant) { try { Int32 recordId = 0; SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["DBConnection"]; SqlCommand sqlCmd = new SqlCommand(); sqlCmd.CommandText = "spSaveRestaurant"; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Connection = myConnection; SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@Restaurant_Id"; parameter.SqlDbType = SqlDbType.Int; parameter.Size = 4; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurant.RestaurantId; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@Restaurant_Name"; parameter.SqlDbType = SqlDbType.VarChar; parameter.Size = 100; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurant.RestaurantName; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@Address"; parameter.SqlDbType = SqlDbType.VarChar; parameter.Size = 50; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurant.Address; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@City"; parameter.SqlDbType = SqlDbType.VarChar; parameter.Size = 50; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurant.City; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@State"; parameter.SqlDbType = SqlDbType.VarChar; parameter.Size = 50; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurant.State; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@Zip_Code"; parameter.SqlDbType = SqlDbType.VarChar; parameter.Size = 20; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurant.ZipCode; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@Email_Address"; parameter.SqlDbType = SqlDbType.VarChar; parameter.Size = 50; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurant.EmailAddress; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@Restaurant_Image_URL"; parameter.SqlDbType = SqlDbType.VarChar; parameter.Size = 1000; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurant.RestaurantImageURL; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@Sales_Tax_Percent"; parameter.SqlDbType = SqlDbType.Decimal; parameter.Size = 10; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurant.SalesTaxPercentage; sqlCmd.Parameters.Add(parameter); parameter = new SqlParameter(); parameter.ParameterName = "@End_Date"; parameter.SqlDbType = SqlDbType.DateTime; parameter.Size = 8; parameter.Direction = ParameterDirection.Input; parameter.Value = restaurant.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); } }