public override Task <WorkerEventResponse> AddDepartment(AddDepRequest request, ServerCallContext context) { DBConnection.Open(); String command = "INSERT INTO Department (DepartmentID, DepName) VALUES (@val1, @val2)"; SqlCommand newCommand = new SqlCommand(command, DBConnection); newCommand.Parameters.AddWithValue("@val1", GetNewDepID()); newCommand.Parameters.AddWithValue("@val2", request.DepName); newCommand.ExecuteNonQuery(); DBConnection.Close(); return(System.Threading.Tasks.Task.FromResult(new WorkerEventResponse { State = true, Msg = "New department added!" })); }
public override Task <WorkerEventResponse> AddDepartment(AddDepRequest request, ServerCallContext context) { var DepID = GetNewDepId(); var command = "INSERT INTO Department (DepartmentID, DepName) VALUES (@val1, @val2)"; var newCommand = new SqlCommand(command, _DbConnection); newCommand.Parameters.AddWithValue("@val1", DepID); newCommand.Parameters.AddWithValue("@val2", request.DepName); _DbConnection.Open(); try { newCommand.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); _DbConnection.Close(); } _DbConnection.Close(); return(System.Threading.Tasks.Task.FromResult(new WorkerEventResponse { State = true, Msg = "New department added!" })); }